Moved to Gradle Kotlin DSL

This commit is contained in:
Jim Martens 2023-07-29 13:56:23 +02:00
parent ef8f7262d3
commit 956380b50a
29 changed files with 383 additions and 331 deletions

View File

@ -1,13 +0,0 @@
plugins {
id 'twomartens.versions'
id 'twomartens.nebula-release'
}
versionCatalogUpdate {
sortByKey = false
keep {
keepUnusedVersions = true
keepUnusedLibraries = true
keepUnusedPlugins = true
}
}

17
build.gradle.kts Normal file
View File

@ -0,0 +1,17 @@
plugins {
id("twomartens.versions")
id("twomartens.nebula-release")
}
nebulaRelease {
addReleaseBranchPattern("/main/")
}
versionCatalogUpdate {
sortByKey.set(false)
keep {
keepUnusedVersions.set(true)
keepUnusedLibraries.set(true)
keepUnusedPlugins.set(true)
}
}

View File

@ -1,15 +0,0 @@
plugins {
id 'groovy-gradle-plugin'
}
repositories {
gradlePluginPortal()
}
dependencies {
implementation libs.plugin.springboot
implementation libs.plugin.lombok
implementation libs.plugin.nebula.release
implementation libs.plugin.gradle.versions
implementation libs.plugin.version.catalog
}

18
buildSrc/build.gradle.kts Normal file
View File

@ -0,0 +1,18 @@
plugins {
`kotlin-dsl`
}
repositories {
gradlePluginPortal()
mavenCentral()
}
dependencies {
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
implementation(libs.plugin.kotlin.gradle)
implementation(libs.plugin.springboot)
implementation(libs.plugin.lombok)
implementation(libs.plugin.nebula.release)
implementation(libs.plugin.gradle.versions)
implementation(libs.plugin.version.catalog)
}

View File

@ -1,4 +1,4 @@
rootProject.name = 'twomartens.config'
rootProject.name = "twomartens.config"
dependencyResolutionManagement {
versionCatalogs {

View File

@ -1,6 +0,0 @@
plugins {
id 'idea'
id 'eclipse'
}
group = projectgroup

View File

@ -1,23 +0,0 @@
plugins {
id 'checkstyle'
id 'twomartens.java-base'
}
checkstyle {
toolVersion '10.0'
ignoreFailures = false
maxWarnings = 0
configFile rootProject.file('config/checkstyle/checkstyle.xml')
configProperties = ['org.checkstyle.google.suppressionfilter.config': "${project.rootDir}/config/checkstyle/checkstyle-suppressions.xml"]
tasks.withType(Checkstyle).tap {
configureEach {
reports {
xml.required = true
html.required = true
}
}
}
}

View File

@ -1,22 +0,0 @@
plugins {
id 'java'
id 'java-library'
id 'twomartens.base'
}
sourceCompatibility = projectSourceCompatibility
targetCompatibility = projectSourceCompatibility
repositories {
mavenCentral()
}
tasks.register('buildAll') {
group 'build'
dependsOn(build)
dependsOn(test)
}
clean {
delete 'out'
}

View File

@ -1,15 +0,0 @@
plugins {
id 'twomartens.java-base'
}
tasks.withType(JavaCompile).configureEach {
options.compilerArgs += "--enable-preview"
}
tasks.withType(Test).configureEach {
jvmArgs += "--enable-preview"
}
tasks.withType(JavaExec).configureEach {
jvmArgs += '--enable-preview'
}

View File

@ -1,71 +0,0 @@
import java.text.SimpleDateFormat
plugins {
id 'jacoco'
id 'io.freefair.lombok'
id 'twomartens.java-base'
id 'twomartens.checkstyle'
}
dependencies {
constraints.implementation libs.bundles.logging
implementation libs.slf4j.api
runtimeOnly libs.bundles.logging
testImplementation libs.bundles.test
}
configurations {
configureEach {
exclude group: 'junit', module: 'junit'
// we are using log4j-slf4j2-impl, so we need to suppress spring include of log4j-slf4j-impl
exclude group: 'org.apache.logging.log4j', module: 'log4j-slf4j-impl'
}
}
test {
systemProperty 'junit.jupiter.execution.parallel.enabled', true
systemProperty 'junit.jupiter.execution.parallel.mode.default', "concurrent"
useJUnitPlatform()
maxHeapSize = "4g"
workingDir = rootProject.projectDir
finalizedBy jacocoTestReport
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
jacocoTestReport {
dependsOn(test)
reports {
xml.required = true
}
}
jar {
doFirst {
manifest {
attributes 'Implementation-Title': rootProject.name,
'Implementation-Version': archiveVersion.get(),
'Implementation-Vendor': "Jim Martens",
'Build-Timestamp': new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date()),
'Created-By': "Gradle ${gradle.gradleVersion}",
'Build-Jdk': "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})",
'Build-OS': "${System.properties['os.name']} ${System.properties['os.arch']} ${System.properties['os.version']}"
}
}
}
normalization.runtimeClasspath.metaInf {
ignoreAttribute("Build-Timestamp")
}
tasks.register('cleanLibs') {
delete("${buildDir}/libs")
}
tasks.build.dependsOn("cleanLibs")

View File

@ -1,16 +0,0 @@
plugins {
id 'com.netflix.nebula.release'
id 'twomartens.base'
}
nebulaRelease {
addReleaseBranchPattern(/main/)
}
task writeVersionProperties() {
group 'version'
buildDir.mkdirs()
file("$buildDir/version.properties").text = "VERSION=${project.version.toString()}\n"
mustRunAfter("release")
outputs.file("$buildDir/version.properties")
}

View File

@ -1,40 +0,0 @@
plugins {
id 'twomartens.spring-boot'
}
dependencies {
implementation platform(libs.spring.cloud)
implementation libs.bundles.spring.boot.server
implementation libs.spring.openapi
implementation libs.httpclient
implementation libs.prometheus
}
sourceSets {
"server-test" {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/server-test/java')
}
resources.srcDir file('src/server-test/resources')
}
}
configurations {
serverTestImplementation.extendsFrom testImplementation
}
tasks.register('serverTest', Test) {
outputs.upToDateWhen { false }
systemProperty 'junit.jupiter.execution.parallel.enabled', true
systemProperty 'junit.jupiter.execution.parallel.mode.default', "concurrent"
systemProperty 'junit.jupiter.execution.parallel.mode.classes.default', "concurrent"
useJUnitPlatform()
maxHeapSize = "4g"
group = 'verification'
workingDir = rootProject.projectDir
testClassesDirs = sourceSets."server-test".output.classesDirs
classpath = sourceSets."server-test".runtimeClasspath
}

View File

@ -1,60 +0,0 @@
plugins {
id 'org.springframework.boot'
id 'twomartens.java'
}
dependencies {
implementation platform(libs.spring.boot)
implementation libs.bundles.spring.boot
testImplementation libs.spring.boot.test
annotationProcessor libs.spring.boot.config
}
sourceSets {
"integration-test" {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/integration-test/java')
}
resources.srcDir file('src/integration-test/resources')
}
}
configurations {
configureEach {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
integrationTestImplementation.extendsFrom testImplementation
}
tasks.register('integrationTest', Test) {
systemProperty 'junit.jupiter.execution.parallel.enabled', true
systemProperty 'junit.jupiter.execution.parallel.mode.default', "concurrent"
systemProperty 'junit.jupiter.execution.parallel.mode.classes.default', "concurrent"
useJUnitPlatform()
maxHeapSize = "4g"
group = 'verification'
workingDir = rootProject.projectDir
testClassesDirs = sourceSets."integration-test".output.classesDirs
classpath = sourceSets."integration-test".runtimeClasspath
}
tasks.named("buildAll").configure() {
dependsOn(integrationTest)
}
springBoot {
buildInfo()
}
bootJar {
enabled = false
}
jar {
enabled = true
archiveClassifier.set("")
}

View File

@ -1,29 +0,0 @@
plugins {
id "com.github.ben-manes.versions"
id "nl.littlerobots.version-catalog-update"
}
dependencyUpdates {
revision = "release"
gradleReleaseChannel = "current"
}
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)
}
tasks.named("dependencyUpdates").configure {
rejectVersionIf {
isNonStable(it.candidate.version)
}
}
tasks.named("versionCatalogUpdate").configure {
group 'version'
}
tasks.named("dependencyUpdates").configure {
group 'version'
}

View File

@ -0,0 +1,6 @@
plugins {
idea
}
val projectgroup: String = providers.gradleProperty("projectgroup").get()
group = projectgroup

View File

@ -0,0 +1,23 @@
plugins {
checkstyle
id("twomartens.java-base")
}
checkstyle {
toolVersion = "10.0"
setIgnoreFailures(false)
maxWarnings = 0
configFile = rootProject.file("config/checkstyle/checkstyle.xml")
configProperties = mapOf<String, String>(
"org.checkstyle.google.suppressionfilter.config" to
"${project.rootDir}/config/checkstyle/checkstyle-suppressions.xml")
}
tasks.withType<Checkstyle>().configureEach {
reports {
xml.required.set(true)
html.required.set(true)
}
}

View File

@ -0,0 +1,30 @@
plugins {
java
`java-library`
id("twomartens.base")
application
}
val projectSourceCompatibility: String = rootProject.properties["projectSourceCompatibility"].toString()
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(projectSourceCompatibility))
}
}
repositories {
mavenCentral()
}
tasks.register("buildAll") {
group = "build"
dependsOn("build")
dependsOn("test")
}
tasks.clean {
doFirst {
delete("out")
}
}

View File

@ -0,0 +1,15 @@
plugins {
id("twomartens.java-base")
}
tasks.withType<JavaCompile>().configureEach {
options.compilerArgs.plusAssign("--enable-preview")
}
tasks.withType<Test>().configureEach {
jvmArgs.plusAssign("--enable-preview")
}
tasks.withType<JavaExec>().configureEach {
jvmArgs.plusAssign("--enable-preview")
}

View File

@ -0,0 +1,80 @@
import org.gradle.accessors.dm.LibrariesForLibs
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
plugins {
jacoco
id("io.freefair.lombok")
id("twomartens.java-base")
id("twomartens.checkstyle")
}
val libs = the<LibrariesForLibs>()
dependencies {
constraints.implementation(libs.bundles.logging)
implementation(libs.slf4j.api)
runtimeOnly(libs.bundles.logging)
testImplementation(libs.bundles.test)
testImplementation(kotlin("test-junit5"))
}
configurations {
configureEach {
exclude(group="junit", module="junit")
// we are using log4j-slf4j2-impl, so we need to suppress spring include of log4j-slf4j-impl
exclude(group="org.apache.logging.log4j", module="log4j-slf4j-impl")
}
}
tasks.withType<Test>().configureEach {
systemProperty("junit.jupiter.execution.parallel.enabled", true)
systemProperty("junit.jupiter.execution.parallel.mode.default", "concurrent")
useJUnitPlatform()
maxHeapSize = "4g"
workingDir = rootProject.projectDir
finalizedBy(tasks.jacocoTestReport)
}
configurations {
compileOnly {
extendsFrom(configurations.annotationProcessor.get())
}
}
tasks.jacocoTestReport {
dependsOn(tasks.test)
reports {
xml.required.set(true)
}
}
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
tasks.jar {
doFirst {
manifest {
attributes["Implementation-Title"] = rootProject.name
attributes["Implementation-Version"] = archiveVersion.get()
attributes["Implementation-Vendor"] = "Jim Martens"
attributes["Build-Timestamp"] = LocalDateTime.now().format(formatter)
attributes["Created-By"] = "Gradle ${gradle.gradleVersion}"
attributes["Build-Jdk"] = "${providers.systemProperty("java.version").get()} (${providers.systemProperty("java.vendor").get()} ${providers.systemProperty("java.vm.version").get()})"
attributes["Build-OS"] = "${providers.systemProperty("os.name").get()} ${providers.systemProperty("os.arch").get()} ${providers.systemProperty("os.version").get()}"
}
}
}
normalization.runtimeClasspath.metaInf {
ignoreAttribute("Build-Timestamp")
}
tasks.register("cleanLibs") {
delete("${buildDir}/libs")
}
tasks.build {
dependsOn("cleanLibs")
}

View File

@ -0,0 +1,18 @@
import java.nio.file.Files
plugins {
id("twomartens.base")
}
apply(plugin="com.netflix.nebula.release")
tasks.register("writeVersionProperties") {
group = "version"
mustRunAfter("release")
outputs.file("$buildDir/version.properties")
val directory = buildDir
doLast {
Files.createDirectories(directory.toPath())
File("$buildDir/version.properties").writeText("VERSION=${project.version.toString()}\n")
}
}

View File

@ -0,0 +1,49 @@
import org.gradle.accessors.dm.LibrariesForLibs
plugins {
id("twomartens.spring-boot")
}
val libs = the<LibrariesForLibs>()
dependencies {
implementation(platform(libs.spring.cloud))
implementation(libs.bundles.spring.boot.server)
implementation(libs.spring.openapi)
implementation(libs.httpclient)
implementation(libs.prometheus)
}
sourceSets {
create("server-test") {
java {
compileClasspath += sourceSets.main.get().output + sourceSets.test.get().output
runtimeClasspath += sourceSets.main.get().output + sourceSets.test.get().output
setSrcDirs(listOf("src/server-test"))
}
}
}
idea {
module {
testSources.from(sourceSets["server-test"].java.srcDirs)
}
}
val serverTestImplementation: Configuration by configurations.getting {
extendsFrom(configurations["testImplementation"])
}
tasks.register<Test>("serverTest") {
outputs.upToDateWhen { false }
systemProperty("junit.jupiter.execution.parallel.enabled", true)
systemProperty("junit.jupiter.execution.parallel.mode.default", "concurrent")
systemProperty("junit.jupiter.execution.parallel.mode.classes.default", "concurrent")
useJUnitPlatform()
maxHeapSize = "4g"
group = "verification"
workingDir = rootProject.projectDir
testClassesDirs = sourceSets["server-test"].output.classesDirs
classpath = sourceSets["server-test"].runtimeClasspath
}

View File

@ -0,0 +1,72 @@
import org.gradle.accessors.dm.LibrariesForLibs
plugins {
id("org.springframework.boot")
id("twomartens.java")
}
val libs = the<LibrariesForLibs>()
dependencies {
implementation(platform(libs.spring.boot))
implementation(libs.bundles.spring.boot)
testImplementation(libs.spring.boot.test)
annotationProcessor(libs.spring.boot.config)
}
sourceSets {
create("integration-test") {
java {
compileClasspath += sourceSets.main.get().output + sourceSets.test.get().output
runtimeClasspath += sourceSets.main.get().output + sourceSets.test.get().output
setSrcDirs(listOf("src/integration-test"))
}
}
}
idea {
module {
testSources.from(sourceSets["integration-test"].java.srcDirs)
}
}
val integrationTestImplementation by configurations.getting {
extendsFrom(configurations.testImplementation.get())
}
configurations {
configureEach {
exclude(group = "org.springframework.boot", module = "spring-boot-starter-logging")
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
}
}
tasks.register<Test>("integrationTest") {
systemProperty("junit.jupiter.execution.parallel.enabled", true)
systemProperty("junit.jupiter.execution.parallel.mode.default", "concurrent")
systemProperty("junit.jupiter.execution.parallel.mode.classes.default", "concurrent")
useJUnitPlatform()
maxHeapSize = "4g"
group = "verification"
workingDir = rootProject.projectDir
testClassesDirs = sourceSets["integration-test"].output.classesDirs
classpath = sourceSets["integration-test"].runtimeClasspath
}
tasks.named("buildAll") {
dependsOn("integrationTest")
}
springBoot {
buildInfo()
}
tasks.bootJar {
enabled = false
}
tasks.jar {
enabled = true
archiveClassifier.set("")
}

View File

@ -0,0 +1,32 @@
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
plugins {
id("com.github.ben-manes.versions")
id("nl.littlerobots.version-catalog-update")
}
tasks.withType<DependencyUpdatesTask>().configureEach {
revision = "release"
gradleReleaseChannel = "current"
}
fun String.isNonStable(): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { uppercase().contains(it) }
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
val isStable = stableKeyword || regex.matches(this)
return isStable.not()
}
tasks.withType<DependencyUpdatesTask> {
rejectVersionIf {
candidate.version.isNonStable()
}
}
tasks.named("versionCatalogUpdate").configure {
group = "version"
}
tasks.named("dependencyUpdates").configure {
group = "version"
}

View File

@ -14,10 +14,11 @@ junit = "5.9.2"
assertj = "3.24.2"
mockito = "5.3.0"
keycloak = "22.0.0"
plugin-nebula-release = "17.1.0"
plugin-nebula-release = "17.2.2"
plugin-lombok = "8.0.1"
plugin-gradle-versions = "0.46.0"
plugin-version-catalog = "0.8.0"
plugin-kotlin-gradle = "1.9.0"
[libraries]
spring-boot = { module = "org.springframework.boot:spring-boot-dependencies", version.ref = "spring-boot" }
@ -72,6 +73,7 @@ plugin-springboot = { module = "org.springframework.boot:spring-boot-gradle-plug
plugin-lombok = { module = "io.freefair.gradle:lombok-plugin", version.ref = "plugin-lombok" }
plugin-gradle-versions = { module = "com.github.ben-manes:gradle-versions-plugin", version.ref = "plugin-gradle-versions" }
plugin-version-catalog = { module = "nl.littlerobots.vcu:plugin", version.ref = "plugin-version-catalog" }
plugin-kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "plugin-kotlin-gradle" }
[bundles]
logging = [

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -1,10 +0,0 @@
plugins {
id 'twomartens.spring-boot-cloud'
}
dependencies {
implementation libs.mapstruct.base
implementation libs.bundles.spring.boot.security
annotationProcessor libs.mapstruct.processor
}

View File

@ -0,0 +1,9 @@
plugins {
id("twomartens.spring-boot-cloud")
}
dependencies {
implementation(libs.mapstruct.base)
implementation(libs.bundles.spring.boot.security)
annotationProcessor(libs.mapstruct.processor)
}

View File

@ -1,8 +0,0 @@
rootProject.name = projectname
include 'server'
rootProject.children.each { subproject ->
subproject.projectDir = file("module-" + subproject.name)
subproject.buildFileName = "${subproject.name}.gradle"
}

9
settings.gradle.kts Normal file
View File

@ -0,0 +1,9 @@
val projectname: String = providers.gradleProperty("projectname").get()
rootProject.name = projectname
include("server")
for (subproject in rootProject.children) {
subproject.projectDir = file("module-" + subproject.name)
subproject.buildFileName = "${subproject.name}.gradle.kts"
}