Skip to content

Commit

Permalink
Merge pull request #551 from raynigon/feature/upgrade-gradle-build
Browse files Browse the repository at this point in the history
Upgrade Gradle to the latest version 8.9
  • Loading branch information
raynigon authored Aug 13, 2024
2 parents 11fa0c1 + b166395 commit 0eacb11
Show file tree
Hide file tree
Showing 22 changed files with 329 additions and 327 deletions.
134 changes: 22 additions & 112 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,136 +1,46 @@
import static org.owasp.dependencycheck.reporting.ReportGenerator.Format.HTML
import static org.owasp.dependencycheck.reporting.ReportGenerator.Format.JSON

buildscript {
repositories {
mavenCentral()
}
}

plugins {
id 'java-library'
id 'signing'
id 'maven-publish'
id 'org.springframework.boot' version '3.2.5'
id 'io.spring.dependency-management' version '1.1.4'

// Auto Update Versions
id 'se.patrikerdes.use-latest-versions' version '0.2.18'
id 'com.github.ben-manes.versions' version '0.51.0'

// Auto Release
id('net.researchgate.release') version '3.0.2'

// Linting
id 'checkstyle'
id 'pmd'
id 'com.github.spotbugs' version '6.0.12'
id 'org.owasp.dependencycheck' version '9.1.0'
id 'maven-publish'
id "net.researchgate.release" version "3.0.2"
}

evaluationDependsOnChildren()

allprojects {
group = 'com.raynigon.unit-api'
// version = project.version
sourceCompatibility = JavaLanguageVersion.of(17)
repositories {
mavenCentral()
}
}

subprojects {
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'java-library'
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'maven-publish'
apply plugin: 'jacoco'
apply plugin: 'signing'
apply plugin: 'net.researchgate.release'
apply plugin: 'checkstyle'
apply plugin: 'pmd'
apply plugin: 'com.github.spotbugs'

sourceCompatibility = JavaLanguageVersion.of(17)
targetCompatibility = JavaLanguageVersion.of(17)
compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'


apply from: "$rootDir/gradle/scripts/versionClass.gradle"
apply from: "$rootDir/gradle/scripts/javadoc.gradle"
apply from: "$rootDir/gradle/scripts/test.gradle"
apply from: "$rootDir/gradle/scripts/publishing.gradle"

bootJar {
enabled = false
}

jar {
enabled = true
archiveClassifier.set("")
}
release {
preTagCommitMessage = "[Release] Version:"
tagCommitMessage = "[Release] Version:"
newVersionCommitMessage = "[Release] Update Version:"
tagTemplate = 'v${version}'
buildTasks = ['publish']

sourceSets {
main {
java.srcDirs += "build/generated/sources/version/java"
}
git {
requireBranch.set("release")
}
}

dependencies {
compileOnly 'org.projectlombok:lombok:1.18.32'
implementation 'javax.measure:unit-api:2.2'
implementation 'org.apache.commons:commons-lang3:3.14.0'
implementation 'org.slf4j:slf4j-api:2.0.13'
implementation 'org.jetbrains:annotations:24.1.0'
annotationProcessor 'org.projectlombok:lombok:1.18.32'

testCompileOnly 'org.projectlombok:lombok:1.18.32'
testImplementation 'org.apache.groovy:groovy:4.0.21'
testImplementation 'org.spockframework:spock-core:2.4-M4-groovy-4.0'
testRuntimeOnly "net.bytebuddy:byte-buddy:1.14.13"
testAnnotationProcessor 'org.projectlombok:lombok:1.18.32'

}


tasks.withType(Checkstyle) {
configFile = new File(rootProject.projectDir, "gradle/config/checkstyle.xml")
reports {
xml.required = true
html.required = true
}
}


pmd {
consoleOutput = true
ignoreFailures = true
toolVersion = "6.41.0"
rulesMinimumPriority = 3
}

spotbugs {
ignoreFailures = true
}

dependencyCheck {
autoUpdate = false
skipTestGroups = true
suppressionFile = "${parent.projectDir}/gradle/config/dependency-check-suppression.xml"
formats = [JSON, HTML]

analyzers.nodeEnabled = false
analyzers.nuspecEnabled = false
analyzers.nugetconfEnabled = false
analyzers.assemblyEnabled = false
analyzers.retirejs.enabled = false
def updateMkdocsConfig = tasks.register("updateMkdocsConfig") {
doFirst {
def cfg = project.file(project.file('mkdocs.yml'))
cfg.text = cfg.text.replaceAll(/(?m)latest_version:.*/, "latest_version: ${project.version}")
}
}

bootJar {
enabled = false
tasks.named("afterReleaseBuild").configure {
dependsOn(
subprojects.collect { it.tasks.named("publish") },
updateMkdocsConfig
)
}

apply from: "$rootDir/gradle/scripts/updateMkdocsConfig.gradle"
apply from: "$rootDir/gradle/scripts/release.gradle"
18 changes: 18 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
plugins {
`kotlin-dsl`
}

repositories {
mavenCentral()
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}

dependencies {
implementation("io.spring.gradle:dependency-management-plugin:1.1.6")
implementation("com.github.spotbugs.snom:spotbugs-gradle-plugin:6.0.1")
implementation("org.owasp:dependency-check-gradle:10.0.3")

implementation("org.springframework.boot:spring-boot-gradle-plugin:3.2.5")
}
69 changes: 69 additions & 0 deletions buildSrc/src/main/kotlin/unit-api.java-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import org.gradle.kotlin.dsl.withType
import org.owasp.dependencycheck.reporting.ReportGenerator.Format

plugins {
java
`java-library`
id("io.spring.dependency-management")

checkstyle
pmd
id("com.github.spotbugs")
id("org.owasp.dependencycheck")

id("unit-api.version-class")
id("unit-api.javadoc")
id("unit-api.test")
id("unit-api.publishing")
}

repositories {
mavenCentral()
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}

tasks.withType<Checkstyle>().configureEach {
configFile = File(rootProject.projectDir, "gradle/config/checkstyle.xml")
reports {
xml.required = true
html.required = true
}
}

pmd {
isConsoleOutput = true
isIgnoreFailures = true
toolVersion = "6.41.0"
rulesMinimumPriority = 3
}

spotbugs {
ignoreFailures = true
}

dependencyCheck {
autoUpdate = false
skipTestGroups = true
suppressionFile = "${parent!!.projectDir}/gradle/config/dependency-check-suppression.xml"
formats = listOf(Format.JSON.toString(), Format.HTML.toString())

analyzers.nodeEnabled = false
analyzers.nuspecEnabled = false
analyzers.nugetconfEnabled = false
analyzers.assemblyEnabled = false
analyzers.retirejs.enabled = false
}

dependencies {
compileOnly("org.projectlombok:lombok:1.18.32")
api("javax.measure:unit-api:2.2")
api("org.apache.commons:commons-lang3:3.14.0")
api("org.slf4j:slf4j-api:2.0.13")
api("org.jetbrains:annotations:24.1.0")
annotationProcessor("org.projectlombok:lombok:1.18.32")
}
15 changes: 15 additions & 0 deletions buildSrc/src/main/kotlin/unit-api.javadoc.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins {
java
}

tasks.javadoc {
// options.addBooleanOption('html5', true)
}

tasks.register<Copy>("globalJavadoc") {
dependsOn(tasks.javadoc)
group = "documentation"
val branchName = (System.getenv("GITHUB_REF") ?: "refs/heads/master").split("/")[2]
from(layout.buildDirectory.dir("docs/javadoc"))
into(parent!!.layout.buildDirectory.dir("javadoc/$branchName/${project.name}"))
}
72 changes: 72 additions & 0 deletions buildSrc/src/main/kotlin/unit-api.publishing.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import groovy.util.Node
import groovy.util.NodeList

plugins {
`java-library`
`maven-publish`
signing
}

java {
withJavadocJar()
withSourcesJar()
}

signing {
val signingKey = findProperty("signingKey").toString()
val signingPassword = findProperty("signingPassword").toString()
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications)
}

publishing {
repositories {
maven {
name = "OSSRH" // OSS Repository Hosting
url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = System.getenv("OSSRH_USERNAME") ?: null
password = System.getenv("OSSRH_PASSWORD") ?: null
}

}
}
publications {
create<MavenPublication>("maven") {
artifactId = project.name
from(components["java"])

pom {
name = project.name
description = "The ${project.name} is a part of the unit-api"
url = "https://unit-api.raynigon.com/"
issueManagement {
system = "GitHub"
url = "https://github.com/raynigon/unit-api/issues"
}
licenses {
license {
name = "Apache-2.0"
url = "https://opensource.org/licenses/Apache-2.0"
}
}
scm {
url = "https://github.com/raynigon/unit-api/"
connection = "scm:git:git://github.com/raynigon/unit-api.git"
developerConnection = "scm:git:ssh://[email protected]/raynigon/unit-api.git"
}
developers {
developer {
id = "raynigon"
name = "Simon Schneider"
email = "[email protected]"
}
}
}
pom.withXml {
val rootNode = asNode()
rootNode.remove((rootNode.get("dependencyManagement") as NodeList)[0] as Node)
}
}
}
}
26 changes: 26 additions & 0 deletions buildSrc/src/main/kotlin/unit-api.spring-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import org.springframework.boot.gradle.tasks.bundling.BootJar

plugins {
id("unit-api.java-conventions")

id("org.springframework.boot")
}

tasks.named<BootJar>("bootJar") {
enabled = false
}

dependencies {
compileOnly("org.springframework.boot:spring-boot-starter")
compileOnly("org.springframework:spring-context-support")
compileOnly("org.springframework.boot:spring-boot-autoconfigure")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")

testImplementation("org.springframework.boot:spring-boot-starter")
testImplementation("org.springframework:spring-context-support")
testImplementation("org.springframework.boot:spring-boot-autoconfigure")
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
}
testImplementation("org.spockframework:spock-spring:2.4-M4-groovy-4.0")
}
27 changes: 27 additions & 0 deletions buildSrc/src/main/kotlin/unit-api.test.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
plugins {
java
groovy
jacoco
}

tasks.test {
useJUnitPlatform()
finalizedBy(tasks.jacocoTestReport) // report is always generated after tests run
}

tasks.jacocoTestReport {
dependsOn(tasks.test) // tests are required to run before generating the report
reports {
xml.required = true
html.required = true
csv.required = false
}
}

dependencies {
testCompileOnly("org.projectlombok:lombok:1.18.32")
testImplementation("org.apache.groovy:groovy:4.0.21")
testImplementation("org.spockframework:spock-core:2.4-M4-groovy-4.0")
testRuntimeOnly("net.bytebuddy:byte-buddy:1.14.13")
testAnnotationProcessor("org.projectlombok:lombok:1.18.32")
}
Loading

0 comments on commit 0eacb11

Please sign in to comment.