Following the principle of convention over configuration this Gradle plugin provides default configurations for various plugins of a Gradle JVM project so that you do not need to copy boilerplate code throughout your projects.
plugins {
id "io.github.gregoranders.project-configuration" version "0.0.9"
}
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "io.github.gregoranders:project-configuration:0.0.9"
}
}
apply plugin: "io.github.gregoranders.project-configuration"
required configuration properties
- sourceCompatibility
idea {
project {
vcs = 'Git'
jdkName = "jdk-${project.sourceCompatibility}"
languageLevel = project.targetCompatibility
}
module {
downloadJavadoc = true
downloadSources = true
}
}
required configuration properties
- checkstyleVersion
checkstyle {
toolVersion = project.rootProject.property('checkstyleVersion')
ignoreFailures = false
}
project.tasks.checkstyleTest.enabled = false
required configuration properties
- pmdVersion
optional configuration properties
- cpdMinimumTokenCount used for the Copy/Paste detection - default is 10
pmd {
consoleOutput = true
incrementalAnalysis = true
toolVersion = project.rootProject.property('pmdVersion')
ignoreFailures = false
ruleSets = []
ruleSetConfig = project.rootProject.resources.text.fromFile('config/pmd/pmd-rules.xml')
}
project.tasks.register('cpdMain', CPDTask)
project.tasks.pmdTest.enabled = false
project.check {
dependsOn project.tasks.cpdMain
}
required configuration properties
- jacocoVersion
jacoco {
toolVersion = project.rootProject.property('jacocoVersion')
}
jacocoTestReport {
dependsOn project.tasks.test
reports {
xml.required = true
csv.required = true
html.required = true
}
}
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
counter = 'INSTRUCTION'
minimum = 1.0
}
limit {
counter = 'BRANCH'
minimum = 1.0
}
limit {
counter = 'LINE'
minimum = 1.0
}
limit {
counter = 'METHOD'
minimum = 1.0
}
limit {
counter = 'CLASS'
minimum = 1.0
}
}
}
}
project.tasks.test {
finalizedBy project.tasks.jacocoTestReport
}
project.tasks.check {
dependsOn project.tasks.jacocoTestCoverageVerification
}
required configuration properties
- spotbugsVersion
spotbugs {
toolVersion = project.rootProject.property('spotbugsVersion')
ignoreFailures = false
effort = 'max'
reportLevel = 'low'
excludeFilter = project.rootProject.file('config/spotbugs/excludeFilter.xml')
}
spotbugsMain {
reports {
html {
outputLocation = project.layout.buildDirectory.file('reports/spotbugs/main/spotbugs.html').get().asFile
stylesheet = 'fancy-hist.xsl'
}
xml {
outputLocation = project.layout.buildDirectory.file('reports/spotbugs/main/spotbugs.xml').get().asFile
}
}
}
project.tasks.spotbugsTest.enabled = false
dependencyCheck {
autoUpdate = true
failBuildOnCVSS = 1
cveValidForHours = 1
format = 'ALL'
outputDirectory = project.layout.buildDirectory.dir('reports/dependency-check').get().asFile
suppressionFile = project.rootProject.file('config/dependency-check/suppressions.xml')
analyzers {
experimentalEnabled = true
archiveEnabled = true
jarEnabled = true
centralEnabled = true
nexusEnabled = false
nexusUsesProxy = false
nuspecEnabled = false
assemblyEnabled = false
msbuildEnabled = false
golangDepEnabled = false
golangModEnabled = false
cocoapodsEnabled = false
swiftEnabled = false
swiftPackageResolvedEnabled = false
bundleAuditEnabled = false
pyDistributionEnabled = false
pyPackageEnabled = false
rubygemsEnabled = false
opensslEnabled = false
cmakeEnabled = false
autoconfEnabled = false
composerEnabled = false
cpanEnabled = false
nodeEnabled = false
}
}
if (System.getenv('CI') == 'true') {
check {
dependsOn project.tasks.dependencyCheckAnalyze
}
}
required configuration properties
- url
- license
- licenseUrl
- authorId
- author
- scmUrl
publishing {
publications {
mavenJava(MavenPublication) {
from project.components.java
pom {
name = project.name
description = project.description
url = property('url')
licenses {
license {
name = property('license')
url = property('licenseUrl')
}
}
developers {
developer {
id = property('authorId')
name = property('author')
email = property('email')
}
}
scm {
connection = "scm:git:git://${property('scmUrl')}"
developerConnection = "scm:git:ssh://${property('scmUrl')}"
url = property('url')
}
}
}
}
repositories {
maven {
name = 'Build'
url = project.layout.buildDirectory.dir('repos')
}
}
}
required environment variables
- GPG_KEY_ID
- GPG_KEY
- GPG_PASSPHRASE
if (System.getenv('GPG_KEY_ID') && System.getenv('GPG_KEY') && System.getenv('GPG_PASSPHRASE')) {
project.signing {
useInMemoryPgpKeys(System.getenv('GPG_KEY_ID'), System.getenv('GPG_KEY'), System.getenv('GPG_PASSPHRASE'))
if (project.plugins.hasPlugin('maven-publish')) {
sign project.publishing.publications
}
}
}