// import com.github.spotbugs.snom.SpotBugsTask import org.apache.tools.ant.taskdefs.condition.Os plugins { id 'java' id 'jacoco' id 'maven-publish' id 'pmd' id 'signing' id 'com.github.ben-manes.versions' version '0.47.0' id 'net.thauvin.erik.gradle.semver' version '1.0.4' // id 'com.github.spotbugs' version '5.0.14' id 'org.sonarqube' version '4.2.1.3168' } defaultTasks 'check' group = 'net.thauvin.erik' final def mavenName = 'SemVer' final def mavenDescription = 'Semantic Version Annotation Processor' final def mavenUrl = 'https://github.com/ethauvin/semver' final def mavenLicense = 'The BSD 3-Clause License' final def mavenLicenseUrl = 'http://opensource.org/licenses/BSD-3-Clause' final def mavenScmCon = 'https://github.com/ethauvin/semver.git' final def mavenScmDevCon = 'git@github.com:ethauvin/semver.git' def isNonStable = { String version -> def stableKeyword = ['RELEASE', 'FINAL', 'GA'].any { it -> version.toUpperCase().contains(it) } def regex = /^[0-9,.v-]+(-r)?$/ return !stableKeyword && !(version ==~ regex) } ext.versions = [ pmd: '6.54.0', // spotbugs: '4.7.3' ] repositories { mavenLocal() mavenCentral() maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } } dependencies { implementation 'com.github.spullara.mustache.java:compiler:0.9.10' // spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.12.0' // spotbugsPlugins 'com.mebigfatguy.sb-contrib:sb-contrib:7.6.0' // compileOnly "com.github.spotbugs:spotbugs-annotations:$versions.spotbugs" // testCompileOnly "com.github.spotbugs:spotbugs-annotations:$versions.spotbugs" testImplementation 'org.testng:testng:7.8.0' } tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } java { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 withSourcesJar() withJavadocJar() } tasks.named("dependencyUpdates").configure { rejectVersionIf { isNonStable(it.candidate.version) } } pmd { toolVersion = versions.pmd ignoreFailures = true ruleSets = [] ruleSetFiles = files("${projectDir}/config/pmd.xml") consoleOutput = true } publishing { publications { mavenJava(MavenPublication) { from components.java groupId = project.group artifactId = rootProject.name pom { name = mavenName description = mavenDescription url = mavenUrl licenses { license { name = mavenLicense url = mavenLicenseUrl } } developers { developer { id = 'ethauvin' name = 'Erik C. Thauvin' email = 'erik@thauvin.net' url = 'https://erik.thauvin.net/' } } scm { connection = 'scm:git:' + mavenScmCon developerConnection = 'scm:git:' + mavenScmDevCon url = mavenUrl } } } } repositories { maven { name = 'ossrh' project.afterEvaluate { url = project.version.contains('SNAPSHOT') ? 'https://oss.sonatype.org/content/repositories/snapshots/' : 'https://oss.sonatype.org/service/local/staging/deploy/maven2/' } credentials(PasswordCredentials) } } } signing { useGpgCmd() sign publishing.publications.mavenJava } javadoc { doFirst { title = "$mavenDescription $project.version API" } options.with { source = '17' tags = ['created'] author = true //addBooleanOption('html4', true) links('https://docs.oracle.com/en/java/javase/17/docs/api/') //addStringOption('Xdoclint:none', '-quiet') } } test { testLogging { exceptionFormat = 'full' events('passed', 'skipped', 'failed') } useTestNG() finalizedBy jacocoTestReport } // spotbugs { // toolVersion.set("${versions.spotbugs}") // excludeFilter.set(file("$projectDir/config/spotbugs/excludeFilter.xml")) // } // tasks.withType(SpotBugsTask).configureEach { // reports { // xml.required = false // html.required = true // } // } tasks.register('release') { group = 'Publishing' description = 'Releases new version to local maven repository.' dependsOn(wrapper, clean, publishToMavenLocal) doFirst { println "Version: $version" } } tasks.register('pandoc', Exec) { group = 'Documentation' def pandoc_args = ['--from', 'gfm', '--to', 'html5', '--metadata', "pagetitle=$mavenDescription", '-s', '-c', 'github-pandoc.css', '-o', 'docs/README.html', 'README.md'] if (Os.isFamily(Os.FAMILY_WINDOWS)) { commandLine(['cmd', '/c', 'pandoc'] + pandoc_args) } else { executable = 'pandoc' args(pandoc_args) } standardOutput = new ByteArrayOutputStream() ext.output = { return standardOutput.toString() } } jacocoTestReport { dependsOn test reports { xml.required = true html.required = true } } sonarqube { properties { property('sonar.organization', 'ethauvin-github') property('sonar.projectKey', 'ethauvin_semver') property('sonar.host.url', 'https://sonarcloud.io') property('sonar.sourceEncoding', 'UTF-8') } } tasks.sonar { dependsOn 'jacocoTestReport' }