Skip to content

Gradle plugins with typical configuration for Java based project

License

Notifications You must be signed in to change notification settings

coditory/gradle-build-plugin

Repository files navigation

Build Gradle Plugin

Build Coverage Status Gradle Plugin Portal

This plugin applies a typical configuration for Coditory JVM projects:

Enabling the plugin

Add to your build.gradle:

plugins {
  id 'com.coditory.build' version '0.1.20'
}

Add reasonable defaults

Adds maven central as the default repository:

// add a default repository
repositories {
    mavenCentral()
}

// enable junit and produce logs for tests
tasks.withType(Test) {
    useJUnitPlatform()
    testLogging {
        exceptionFormat = "full"
        events = ["passed", "skipped", "failed"]
    }
}

tasks.withType(JavaCompile) {
    // make all test/main builds use UTF-8
    options.encoding = "UTF-8"
    // produce error on lint problems
    options.compilerArgs << "-Werror"
    options.compilerArgs << "-Xlint"
    options.compilerArgs << "-Xlint:-serial"
}

tasks.withType(GroovyCompile) {
    // make all test/main builds use UTF-8
    groovyOptions.encoding = "UTF-8"
}

tasks.withType(KotlinCompile) {
    // produce errors on warnings
    kotlinOptions.allWarningsAsErrors = true
}

// the most recent ktlint version (that does not cause problems)
// https://github.com/JLLeitschuh/ktlint-gradle/issues/589
ktlint {
    version.set("0.45.2")
}

// make Jacoco report combine all types of tests
jacocoTestReport {
    executionData(fileTree(project.buildDir).include("jacoco/*.exec"))
    reports {
        xml.required = true
        html.required = true
    }
}

// make javadoc less strict to limit noisy logs
javadoc {
    source = sourceSets.main.allJava
    classpath = configurations.compileClasspath
    failOnError = false
    options {
        this as StandardJavadocDocletOptions
        addBooleanOption("Xdoclint:none", true)
        addStringOption("Xmaxwarns", "1")
        memberLevel = JavadocMemberLevel.PUBLIC
        outputLevel = JavadocOutputLevel.QUIET
        encoding = "UTF-8"
    }
}

You're responsible to setup jvm toolchains:

// build.gradle for java:
java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(11)
    }
}

// build.gradle.kts for kotlin >=1.8:
kotlin {
    jvmToolchain {
        languageVersion.set(JavaLanguageVersion.of(11))
    }
}

// build.gradle.kts of for kotlin <1.8
kotlin {
    jvmToolchain {
        (this as JavaToolchainSpec).languageVersion.set(JavaLanguageVersion.of(11))
    }
}

About

Gradle plugins with typical configuration for Java based project

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages