Skip to content

Build file annotated

Vyacheslav Rusakov edited this page Jan 5, 2016 · 1 revision

Here is sample build file with annotations

plugins {
    id 'groovy'          // enable groovy support (for tests); implicitly enables java plugin
    id 'jacoco'          // jacoco test coverage (required for coveralls)
    id 'project-report'  // required for html dependencies tree task at the end of build file
    id 'ru.vyarus.java-lib' version '1.0.1'             // artifacts definition
    id 'ru.vyarus.github-info' version '1.0.0'          // configure pom and bintray with github links
    id 'ru.vyarus.animalsniffer' version '1.0.0'        // older jdk compatibility check with animalsniffer
    id 'ru.vyarus.quality' version '1.2.0'              // enables quality plugins and provides default configs
    id 'com.github.kt3k.coveralls' version '2.4.0x'     // sends coverage to coveralls (see .travis.yml)
    id 'com.jfrog.bintray' version '1.5'                // bintray upload plugin (used for release)
    id 'net.researchgate.release' version '2.3.4'       // maven-like release process
    id 'com.github.ben-manes.versions' version '0.11.3' // dependencyUpdates task to check for new versions
}

New gradle plugins dsl. It may be used together with legacy plugins definition through buildscipt and plugin apply.

sourceCompatibility = 1.6

Java compatibility. Note that targetCompatibility option is not required because its the same as source by defaut.

wrapper {
    gradleVersion = 2.10
}

Gradle wrapper version. When need to update project wrapper simply update version here and call wrapper task (it will update scripts and jar in gradle dir)

repositories { jcenter(); mavenCentral(); mavenLocal() }
dependencies {
    signature 'org.codehaus.mojo.signature:java16-sun:+@signature'

    provided 'com.google.code.findbugs:jsr305:3.0.1'
    provided 'com.google.code.findbugs:annotations:3.0.1'

    compile 'org.slf4j:slf4j-api:1.7.13'

    testCompile 'ch.qos.logback:logback-classic:1.1.3'
    testCompile 'org.slf4j:jul-to-slf4j:1.7.13'
    testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
}

Provided and optional are defined by ru.vyarus.pom plugin. Signature defined by ru.vyarus.animalsniffer plugin

group = 'com.johnd'
description = 'Test library'

Maven group id and project short description. Description is used in pom and for bintray package description.

github {
    user = 'johnd'
    license = 'MIT'
}

Github info configuration used by ru.vyarus.github-info plugin to configre github links in pom and for bintray package.

pom {
    developers {
        developer {
            id "johnd"
            name "John Doe"
            email "[email protected]"
        }
    }
}

Free pom customization provided by ru.vyarus.pom plugin. Most pom sections will be pre-filled by other plugins. Use generatePomFileForMavenPublication task to verify pom (generated pom licated in build/publications/maven/pom-default.xml)

bintray {
    user = project.hasProperty('bintrayUser') ? bintrayUser : 'USER'
    key = project.hasProperty('bintrayKey') ? bintrayKey : 'KEY'
    publications = ['maven']
    dryRun = false
    publish = true
    pkg {
        repo = 'mvn'
        name = project.name
        desc = project.description
        labels = ['java', 'sample', 'lib']
        publicDownloadNumbers = true
        version {
            gpg {
                sign = true
                passphrase = project.hasProperty('gpgPassphrase') ? gpgPassphrase : ''
            }
            mavenCentralSync {
                sync = false
                user = project.hasProperty('sonatypeUser') ? sonatypeUser : 'USER'
                password = project.hasProperty('sonatypePassword') ? sonatypePassword : 'PASSWORD'
            }
        }
    }
}

com.jfrog.bintry plugin configuration.

afterReleaseBuild {
    dependsOn = [bintrayUpload]
    doLast {
        logger.warn "RELEASED $project.group:$project.name:$project.version"
    }
}

Release process configuration: bintrayUpload must be called during release.

test {
    testLogging {
        events "skipped", "failed", "standard_error"
        exceptionFormat "full"
    }
    maxHeapSize = "512m"
}

Tests configuration is important for travis. Test logging configured to log errors with exception to simplify debug. maxHeapSize is important to workaround travis 137 error: tests are executed in forked vm and inside docker container (sudo:false in .travis.yml) java see overall memory instead of allowed for current container and set incorrect default for max memory (as a result vm gets killed by travis monitoring agent and we see error 137 in log)

dependencyUpdates.revision = 'release'

Configure dependencies plugin to show only released newer versions.

jacocoTestReport.reports.xml.enabled = true

By default xml report is disabled, but its required for coveralls plugin

task showDependenciesTree(dependsOn: 'htmlDependencyReport', group: 'help', description:
        'Generates dependencies tree report and opens it in browser') << {
    java.awt.Desktop.getDesktop().open(file('/build/reports/project/dependencies/root.html'))
}

Custom task to generate and immediately open in browser dependencies html report.

Clone this wiki locally