Build Tools - studiofu/brain GitHub Wiki

Gradle

settings.gradle

  • it's just like build.gradle and it is a Groovy Script
  • only one settings.gradle will be executed in each build
  • it will be executed before any build.gradle
  • gradle read this file to figure out which project take part in a build
  • refer to https://guides.gradle.org/creating-multi-project-builds/

gradle.properties

  • it is just a simple java properties

tasks

  • if task action is not defined, the tasks will be executed in the configuration phase
  • action is like doLast {}, doFirst {}

Sample

settings.gradle (in root level) - https://guides.gradle.org/creating-multi-project-builds/

rootProject.name = 'creating-multi-project-builds' // project name
include 'greeting-library'
include 'greeter'

build.gradle (in root level)

allprojects {
   repositories {
      jcenter()
   }
}

if it is required to include local library, please use flatDir(dirs: file(“$localLibsPath”)) in the repositories section

ext {
    localLibsPath = "${rootProject.projectDir}/libraries/esmart-libs"
}

build.gradle (in sub project level) - spock setup, when, then unit test section - http://spockframework.org/spock/docs/1.0/spock_primer.html


plugins {
    id 'groovy'
    id 'java'
    id 'application'
}

mainClassName = 'greeter.Greeter'

dependencies {
    compile project(':greeting-library') # meed to include the dependent library

    testCompile 'org.spockframework:spock-core:1.0-groovy-2.4', { # to use the spock unit test library
        exclude module: 'groovy-all'
    }
}

Build document into the zipped and tar files

distZip {
    from project(':docs').asciidoctor, {
        into "${project.name}-${version}"
    }
}
distTar {
    from project(':docs').asciidoctor, {
        into "${project.name}-${version}"
    }
}

use configure to loop through the project - https://stackoverflow.com/questions/13868177/apply-configuration-to-specific-projects-in-gradle-build-script

def greeterProjects = [
    project(':greeter'),
    project(':greeting-library'),
    project(':docs'),
]

configure(greeterProjects) { project ->
    println(project)
}

standard spring boot gradle build file

buildscript {
    ext {
        springBootVersion = '2.1.1.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'com.xxx'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()

    maven {
        url 'http://xxxx:8081/artifactory/xxx-repo/'
    }

}

dependencies {
    implementation('org.springframework.boot:spring-boot-starter-web')
    runtimeOnly('org.springframework.boot:spring-boot-devtools')
    compileOnly('org.projectlombok:lombok')
    testImplementation('org.springframework.boot:spring-boot-starter-test')
}

Gradle asciidoctor

plugins {
    id 'org.asciidoctor.convert' version '1.5.6' apply false
}

Resources

Mastering Gradle - Book