Fork me on GitHub

Plugin providing opinionated defaults for Gradle builds, making it easier to use some useful plugins, and coordinating between plugins.

Requires Gradle 2.14+

Language Support

Java

If the java plugin is applied:

  • Add tasks and artifacts for -sources.jar and -javadoc.jar.

  • Sets the compiler target and source compatibility versions based on the defaults.compatibilityVersion (defaults to the version of Java used to compile)

  • Configures the JAR MANIFEST.MF to include

    • Implementation-Title = {project.description ?: project.name}

    • Implementation-Version = {project.version}

    • Built-By = {userEmail as known to git’s "user.email" configuration}

    • Built-Date = {now}

    • Built-JDK = {System.getProperty('java.version')}

    • Built-Gradle = {Gradle version being used}

Lombok

Adds support for Lombok for Java projects. If a project has Java code it is assumed to need Lombok, unless it is explicitly disabled with lombok.enabled = false.

You can change the version of Lombok to use by setting lombok.version. The current default is "1.16.8".

Both compiling from Gradle and IntelliJ IDEA projects are supported.

Checker Framework

Adds support for Checker Framework for Java projects. If a project has Java code it is assumed to need Checker Framework, unless it is explicitly disabled with checkerFramework.enabled = false.

You can change the version of Lombok to use by setting checkerFramework.version. The current default is "2.0.1".

Both compiling from Gradle and IntelliJ IDEA projects are supported.

Groovy

If the groovy plugin is applied:

  • Adds tasks and artifacts for -groovydoc.jar.

  • Sets the compiler target and source compatibility versions based on the defaults.compatibilityVersion (defaults to the version of Java used to compile)

Scala

If the scala plugin is applied:

  • Adds tasks and artifacts for -scaladoc.jar.

  • Sets the compiler target and source compatibility versions based on the defaults.compatibilityVersion (defaults to the version of Java used to compile)

Kotlin

If the kotlin plugin (org.jetbrains.kotlin:kotlin-gradle-plugin) is applied:

  • Adds tasks and artifacts for -dokka.jar if the Dokka plugin has also been applied

  • Sets the compiler target and source compatibility versions based on the defaults.compatibilityVersion (defaults to the version of Java used to compile)

Publishing & Releasing

GitHub Pages

Applies org.ajoberstar.github-pages plugin.

Will publish content from src/gh-pages. In addition, will generate and publish API documentation for Java, Scala, Groovy and Kotlin.

Licensing

If the openSource property is set to true (either against the project or the defaults extension), the license plugin (com.github.hierynomus.license) is applied.

It uses the license header from gradle/HEADER, injecting defaults.copyrightYears for ${year} in the header.

Strict checking (fail a check if all needed files do not have license information) is enabled.

Sets .java, .groovy, .scala and .kt files to use slashstar style (/* */) instead of default javadoc (/** */) style for the license header.

Properties files are excluded from checks.

Release Plugin

The org.ajoberstar.release-opinion plugin is applied.

The release task depends on clean, build and publishGhPages, as well as bintrayUpload if BinTray is being used.

Maven Publishing

The maven-publish plugin is applied and the main publication includes any of the following that exist:

  • .jar

  • -sources.jar

  • -javadoc.jar

  • -groovydoc.jar

  • -scaladoc.jar

  • -dokka.jar

The POM is configured with information from the project and the "defaults" extension, see its Javadoc.

MavenLocal is added as a publishing location.

BinTray

If com.jfrog.bintray is applied and bintrayUser and bintrayKey properties are set on the project, then the following configuration is set in addition to any that the build file explicitly configures:

If defaults.bintrayLabels includes gradle, the gradle-plugin attribute is set to support the Gradle plugin portal for any plugin IDs in src/main/resources.

The main publication from "Maven Publishing" is published to the BinTray repository.

The BinTray project is configured with information from the project and the "defaults" extension, see its Javadoc.

Development

IntelliJ IDEA

Applies the idea plugin.

  • Initializes Git as the VCS

  • Sets the language level to defaults.compatibilityVersion

  • Code formatting set to reasonable/consistent standards

Misc

  • Applies organize-imports plugin.

  • Adds the jcenter() repository.

  • Configures ordering rules for tasks:

    • All tasks should run after clean.

    • All tasks in the publishing group should run after build.

Example Usage

Here’s the relevant section of this project’s build.gradle file:

buildscript {
    repositories {
        jcenter()
        maven { name = 'Defaults Plugin Repo'; url = 'http://dl.bintray.com/jmoore/java-lib' }
        maven { name = 'Gradle Plugin Portal'; url = 'https://plugins.gradle.org/m2/' }
        mavenLocal()
    }

    ext.kotlin_version = '1.0.3'
    ext.dokka_version = '0.9.9'

    dependencies {
        classpath 'com.mooregreatsoftware:gradle-defaults:3.0.0'

        // Kotlin support
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"

        // AsciiDoctor documentation
        classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.3'
    }
}

plugins {
    id 'groovy'
    id 'com.jfrog.bintray' version '1.7.1'
}

apply plugin: 'com.mooregreatsoftware.defaults'

group = 'com.mooregreatsoftware'
description = 'Plugin providing opinionated defaults for Gradle projects.'

defaults {
    // make sure configuration is done for enforcing licenses, BinTray, etc.
    openSource = true

    compatibilityVersion = 1.8

    orgId = 'jdigger'

    bintrayRepo = 'java-lib'
    bintrayLabels = ['gradle', 'plugin']

    developers = [
        [id: 'jmoore', name: 'Jim Moore', email: 'moore.jim@gmail.com']
    ]

    copyrightYears = '2014-2016'

    vcsWriteUrl = "git@github.com:jdigger/gradle-defaults.git"
}

Notes

For all of the configurable properties of the "defaults" extension, see its Javadoc.

For now, the three non-MavenLocal repositories are needed in buildscript — at least until this gets into the Gradle Plugin Repository.

Multi-Module Support

You only need to apply the plugin to the root project and it will take care of applying sensible defaults to all of its children. (In fact, applying it to any project that’s not the root does nothing and a warning is logged.)

Each sub-module receives its own "defaults" extension that can be used to override the settings of its parent.

API