From 5f5601fc8d29828ab9826755fdb7c58357189f72 Mon Sep 17 00:00:00 2001 From: higan Date: Tue, 24 Oct 2023 16:09:20 +0800 Subject: [PATCH] :arrow_up: Upgrade to Kotlin 1.9.10 --- gradle/libs.versions.toml | 22 +++--- gradle/wrapper/gradle-wrapper.properties | 2 +- .../project/gradle/SisyphusExtension.kt | 6 +- .../bybutter/sisyphus/project/gradle/Utils.kt | 67 ++++++++++++------- .../java/JavaDependenciesReplacePlugin.kt | 3 +- .../gradle/publishing/ProjectLicensePlugin.kt | 34 +++++----- .../threepart/SisyphusAntlrKotlinPlugin.kt | 9 +-- .../gradle/threepart/SisyphusDockerPlugin.kt | 51 +++++++++----- .../gradle/threepart/SisyphusKtlintPlugin.kt | 24 +++---- .../kotlin/dsl/SisyphusDevelopmentLayer.kt | 14 +++- 10 files changed, 135 insertions(+), 97 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 33b7ea4..4ec5a95 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,24 +1,24 @@ [versions] -kotlin = "1.9.0" -spring-boot = "3.1.2" +gradle-docker = "9.3.4" +kotlin = "1.9.10" +ktlint = "4.0.0" nebula-contacts = "7.0.1" nebula-info = "12.1.6" nebula-publishing = "20.3.0" -gradle-docker = "9.3.2" -plugin-publishing = "1.2.0" -ktlint = "11.5.0" +plugin-publishing = "1.2.1" +spring-boot = "3.1.2" [libraries] -nebula-info = { module = "com.netflix.nebula:gradle-info-plugin", version.ref = "nebula-info" } -nebula-publishing = { module = "com.netflix.nebula:nebula-publishing-plugin", version.ref = "nebula-publishing" } -nebula-contacts = { module = "com.netflix.nebula:gradle-contacts-plugin", version.ref = "nebula-contacts" } gradle-docker = { module = "com.bmuschko:gradle-docker-plugin", version.ref = "gradle-docker" } gradle-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } +gradle-ktlint = { module = "org.jmailen.gradle:kotlinter-gradle", version.ref = "ktlint" } gradle-spring = { module = "org.springframework.boot:spring-boot-gradle-plugin", version.ref = "spring-boot" } -gradle-ktlint = { module = "org.jlleitschuh.gradle:ktlint-gradle", version.ref = "ktlint" } kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" } +nebula-contacts = { module = "com.netflix.nebula:gradle-contacts-plugin", version.ref = "nebula-contacts" } +nebula-info = { module = "com.netflix.nebula:gradle-info-plugin", version.ref = "nebula-info" } +nebula-publishing = { module = "com.netflix.nebula:nebula-publishing-plugin", version.ref = "nebula-publishing" } [plugins] -plugin-publishing = { id = "com.gradle.plugin-publish", version.ref = "plugin-publishing" } kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } -ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" } \ No newline at end of file +ktlint = { id = "org.jmailen.kotlinter", version.ref = "ktlint" } +plugin-publishing = { id = "com.gradle.plugin-publish", version.ref = "plugin-publishing" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a1f2792..fce403e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/kotlin/com/bybutter/sisyphus/project/gradle/SisyphusExtension.kt b/src/main/kotlin/com/bybutter/sisyphus/project/gradle/SisyphusExtension.kt index 3c807ed..bb1857b 100644 --- a/src/main/kotlin/com/bybutter/sisyphus/project/gradle/SisyphusExtension.kt +++ b/src/main/kotlin/com/bybutter/sisyphus/project/gradle/SisyphusExtension.kt @@ -79,9 +79,9 @@ open class SisyphusExtension(val project: Project) { branchName != null -> "$branchName-SNAPSHOT" githubRef != null && pullRequestRefRegex.matches(githubRef) -> "PR-${ - pullRequestRefRegex.matchEntire( - githubRef - )?.groupValues?.get(1) + pullRequestRefRegex.matchEntire( + githubRef, + )?.groupValues?.get(1) }-SNAPSHOT" else -> null diff --git a/src/main/kotlin/com/bybutter/sisyphus/project/gradle/Utils.kt b/src/main/kotlin/com/bybutter/sisyphus/project/gradle/Utils.kt index 821b915..2556dde 100644 --- a/src/main/kotlin/com/bybutter/sisyphus/project/gradle/Utils.kt +++ b/src/main/kotlin/com/bybutter/sisyphus/project/gradle/Utils.kt @@ -12,7 +12,10 @@ internal fun Project.isRelease(): Boolean { return !isSnapshot() } -internal fun Project.ensurePlugin(vararg ids: String, block: (Project) -> Unit): Boolean { +internal fun Project.ensurePlugin( + vararg ids: String, + block: (Project) -> Unit, +): Boolean { for (id in ids) { if (!pluginManager.hasPlugin(id)) { pluginManager.withPlugin(id) { @@ -25,7 +28,11 @@ internal fun Project.ensurePlugin(vararg ids: String, block: (Project) -> Unit): return true } -internal inline fun Project.ensurePlugin(id: String, noinline block: (Project) -> Unit, returnBlock: () -> Unit) { +internal inline fun Project.ensurePlugin( + id: String, + noinline block: (Project) -> Unit, + returnBlock: () -> Unit, +) { if (!pluginManager.hasPlugin(id)) { pluginManager.withPlugin(id) { block(this) @@ -34,7 +41,10 @@ internal inline fun Project.ensurePlugin(id: String, noinline block: (Project) - } } -internal fun Project.tryApplyPluginClass(className: String, action: () -> Unit = {}): Boolean { +internal fun Project.tryApplyPluginClass( + className: String, + action: () -> Unit = {}, +): Boolean { return try { val plugin = Class.forName(className) action() @@ -47,33 +57,38 @@ internal fun Project.tryApplyPluginClass(className: String, action: () -> Unit = internal fun RepositoryHandler.applyFromRepositoryKeys( repositories: Map, - repositoryKeys: Collection + repositoryKeys: Collection, ) { for (repositoryKey in repositoryKeys) { - val repository = when (repositoryKey) { - "local" -> repositories[repositoryKey] ?: run { - this.mavenLocal() - null - } - - "central" -> repositories[repositoryKey] ?: run { - this.mavenCentral() - null - } - - "portal" -> repositories[repositoryKey] ?: run { - this.gradlePluginPortal() - null + val repository = + when (repositoryKey) { + "local" -> + repositories[repositoryKey] ?: run { + this.mavenLocal() + null + } + + "central" -> + repositories[repositoryKey] ?: run { + this.mavenCentral() + null + } + + "portal" -> + repositories[repositoryKey] ?: run { + this.gradlePluginPortal() + null + } + + "google" -> + repositories[repositoryKey] ?: run { + this.google() + null + } + + else -> repositories[repositoryKey] } - "google" -> repositories[repositoryKey] ?: run { - this.google() - null - } - - else -> repositories[repositoryKey] - } - repository ?: continue this.maven { diff --git a/src/main/kotlin/com/bybutter/sisyphus/project/gradle/java/JavaDependenciesReplacePlugin.kt b/src/main/kotlin/com/bybutter/sisyphus/project/gradle/java/JavaDependenciesReplacePlugin.kt index 8b74c81..e63b8fd 100644 --- a/src/main/kotlin/com/bybutter/sisyphus/project/gradle/java/JavaDependenciesReplacePlugin.kt +++ b/src/main/kotlin/com/bybutter/sisyphus/project/gradle/java/JavaDependenciesReplacePlugin.kt @@ -10,7 +10,8 @@ class JavaDependenciesReplacePlugin : Plugin { target.configurations.all { it.resolutionStrategy.eachDependency { detail -> - extension.managedDependencies.getting("${detail.requested.group}:${detail.requested.name}").orNull?.let { moduleStringNotation -> + extension.managedDependencies.getting("${detail.requested.group}:${detail.requested.name}").orNull?.let { + moduleStringNotation -> detail.useVersion(moduleStringNotation.version) detail.because("The version of current dependency managed by Sisyphus Property") } diff --git a/src/main/kotlin/com/bybutter/sisyphus/project/gradle/publishing/ProjectLicensePlugin.kt b/src/main/kotlin/com/bybutter/sisyphus/project/gradle/publishing/ProjectLicensePlugin.kt index ceb3dce..b1c9eee 100644 --- a/src/main/kotlin/com/bybutter/sisyphus/project/gradle/publishing/ProjectLicensePlugin.kt +++ b/src/main/kotlin/com/bybutter/sisyphus/project/gradle/publishing/ProjectLicensePlugin.kt @@ -68,21 +68,23 @@ class ProjectLicensePlugin : Plugin { } companion object { - private val licenseRegex = mapOf( - "MIT License" to "MIT License".toRegex(), - "Apache License 2.0" to """Apache License\s+Version 2\.0""".toRegex(), - "Mozilla Public License 2.0" to """Mozilla Public License Version 2\.0""".toRegex(), - "GNU AGPLv3" to """GNU AFFERO GENERAL PUBLIC LICENSE\s+Version 3""".toRegex(), - "GNU GPLv3" to """GNU GENERAL PUBLIC LICENSE\s+Version 3""".toRegex(), - "GNU LGPLv3" to """GNU LESSER GENERAL PUBLIC LICENSE\s+Version 3""".toRegex(), - "Boost Software License 1.0" to """Boost Software License - Version 1\.0""".toRegex(), - "The Unlicense" to """This is free and unencumbered software released into the public domain\.""".toRegex(), - "WTFPL" to "DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE".toRegex() - ) - private val githubPatterns = listOf( - """git@github.com:([a-zA-Z0-9-_.]+?):([a-zA-Z0-9-_.]+?).git""".toRegex(), - """https?://github.com/([a-zA-Z0-9-_.]+?)/([a-zA-Z0-9-_.]+?)\.git""".toRegex(), - """https?://github.com/([a-zA-Z0-9-_.]+?)/([a-zA-Z0-9-_.]+)""".toRegex() - ) + private val licenseRegex = + mapOf( + "MIT License" to "MIT License".toRegex(), + "Apache License 2.0" to """Apache License\s+Version 2\.0""".toRegex(), + "Mozilla Public License 2.0" to """Mozilla Public License Version 2\.0""".toRegex(), + "GNU AGPLv3" to """GNU AFFERO GENERAL PUBLIC LICENSE\s+Version 3""".toRegex(), + "GNU GPLv3" to """GNU GENERAL PUBLIC LICENSE\s+Version 3""".toRegex(), + "GNU LGPLv3" to """GNU LESSER GENERAL PUBLIC LICENSE\s+Version 3""".toRegex(), + "Boost Software License 1.0" to """Boost Software License - Version 1\.0""".toRegex(), + "The Unlicense" to """This is free and unencumbered software released into the public domain\.""".toRegex(), + "WTFPL" to "DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE".toRegex(), + ) + private val githubPatterns = + listOf( + """git@github.com:([a-zA-Z0-9-_.]+?):([a-zA-Z0-9-_.]+?).git""".toRegex(), + """https?://github.com/([a-zA-Z0-9-_.]+?)/([a-zA-Z0-9-_.]+?)\.git""".toRegex(), + """https?://github.com/([a-zA-Z0-9-_.]+?)/([a-zA-Z0-9-_.]+)""".toRegex(), + ) } } diff --git a/src/main/kotlin/com/bybutter/sisyphus/project/gradle/threepart/SisyphusAntlrKotlinPlugin.kt b/src/main/kotlin/com/bybutter/sisyphus/project/gradle/threepart/SisyphusAntlrKotlinPlugin.kt index f8fe6a4..e0bff41 100644 --- a/src/main/kotlin/com/bybutter/sisyphus/project/gradle/threepart/SisyphusAntlrKotlinPlugin.kt +++ b/src/main/kotlin/com/bybutter/sisyphus/project/gradle/threepart/SisyphusAntlrKotlinPlugin.kt @@ -20,10 +20,11 @@ class SisyphusAntlrKotlinPlugin : Plugin { val sourceSets = target.extensions.getByType(SourceSetContainer::class.java) sourceSets.forEach { - val generateTaskName = when (it.name) { - "main" -> "generateGrammarSource" - else -> "generate${GUtil.toCamelCase(it.name)}GrammarSource" - } + val generateTaskName = + when (it.name) { + "main" -> "generateGrammarSource" + else -> "generate${GUtil.toCamelCase(it.name)}GrammarSource" + } target.tasks.named(generateTaskName, AntlrTask::class.java).configure { task -> it.java.setSrcDirs(it.java.srcDirs.filter { task.outputDirectory.absolutePath != it.absolutePath }) it.java.srcDir(task) diff --git a/src/main/kotlin/com/bybutter/sisyphus/project/gradle/threepart/SisyphusDockerPlugin.kt b/src/main/kotlin/com/bybutter/sisyphus/project/gradle/threepart/SisyphusDockerPlugin.kt index 93671df..bd9f8ed 100644 --- a/src/main/kotlin/com/bybutter/sisyphus/project/gradle/threepart/SisyphusDockerPlugin.kt +++ b/src/main/kotlin/com/bybutter/sisyphus/project/gradle/threepart/SisyphusDockerPlugin.kt @@ -43,7 +43,10 @@ class SisyphusDockerPlugin : Plugin { } } - private fun registerExtractLayerTask(target: Project, bootJar: BootJar) { + private fun registerExtractLayerTask( + target: Project, + bootJar: BootJar, + ) { target.tasks.register("extractBootJarLayer", ExtractBootJarLayer::class.java) { it.dependsOn(bootJar) it.bootJars = bootJar.outputs.files @@ -51,7 +54,11 @@ class SisyphusDockerPlugin : Plugin { } } - private fun registerDockerfileTask(target: Project, sisyphusDocker: SisyphusDockerExtension, bootJar: BootJar) { + private fun registerDockerfileTask( + target: Project, + sisyphusDocker: SisyphusDockerExtension, + bootJar: BootJar, + ) { target.tasks.register("dockerfile", Dockerfile::class.java) { it.arg("PROJECT_NAME") it.arg("PROJECT_VERSION") @@ -80,7 +87,7 @@ class SisyphusDockerPlugin : Plugin { it.entryPoint( "java", *sisyphusDocker.jvmArgs.get().toTypedArray(), - "org.springframework.boot.loader.JarLauncher" + "org.springframework.boot.loader.JarLauncher", ) } } @@ -105,7 +112,10 @@ class SisyphusDockerPlugin : Plugin { } } - private fun registerDockerBuild(target: Project, sisyphusDocker: SisyphusDockerExtension) { + private fun registerDockerBuild( + target: Project, + sisyphusDocker: SisyphusDockerExtension, + ) { target.tasks.register("dockerBuild", DockerBuildImage::class.java) { it.dependsOn(target.tasks.named("dockerSync")) it.group = "docker" @@ -121,19 +131,21 @@ class SisyphusDockerPlugin : Plugin { private fun registerDockerPush( target: Project, sisyphusDocker: SisyphusDockerExtension, - sisyphus: SisyphusExtension + sisyphus: SisyphusExtension, ) { - val registries = sisyphus.dockerPublishRegistries.get().associate { - it to sisyphus.repositories.getting(it).orNull - } + val registries = + sisyphus.dockerPublishRegistries.get().associate { + it to sisyphus.repositories.getting(it).orNull + } val baseName = "${target.name}:${target.version}" sisyphusDocker.images.get().forEach { image -> - val repository = registries.entries.firstOrNull { - val url = it.value?.url ?: return@firstOrNull false - image == "$url/$baseName" - } ?: return@forEach + val repository = + registries.entries.firstOrNull { + val url = it.value?.url ?: return@firstOrNull false + image == "$url/$baseName" + } ?: return@forEach target.tasks.register("dockerPush" + GUtil.toCamelCase(repository.key), DockerPushImage::class.java) { it.dependsOn(target.tasks.named("dockerBuild")) @@ -186,7 +198,8 @@ open class SisyphusDockerExtension(factory: ObjectFactory, sisyphus: SisyphusExt in 1..7, in 9..10, in 12..16, - null -> { + null, + -> { } else -> { @@ -203,7 +216,7 @@ open class SisyphusDockerExtension(factory: ObjectFactory, sisyphus: SisyphusExt }.map { "${it.url}/$baseName" } - } + }, ) } @@ -215,11 +228,17 @@ open class SisyphusDockerExtension(factory: ObjectFactory, sisyphus: SisyphusExt configure(instructions) } - fun ListProperty.copyFile(source: String, destination: String) { + fun ListProperty.copyFile( + source: String, + destination: String, + ) { add(Dockerfile.CopyFileInstruction(Dockerfile.CopyFile(source, destination))) } - fun ListProperty.addFile(source: String, destination: String) { + fun ListProperty.addFile( + source: String, + destination: String, + ) { add(Dockerfile.AddFileInstruction(Dockerfile.File(source, destination))) } diff --git a/src/main/kotlin/com/bybutter/sisyphus/project/gradle/threepart/SisyphusKtlintPlugin.kt b/src/main/kotlin/com/bybutter/sisyphus/project/gradle/threepart/SisyphusKtlintPlugin.kt index 15439b7..4124e85 100644 --- a/src/main/kotlin/com/bybutter/sisyphus/project/gradle/threepart/SisyphusKtlintPlugin.kt +++ b/src/main/kotlin/com/bybutter/sisyphus/project/gradle/threepart/SisyphusKtlintPlugin.kt @@ -3,31 +3,23 @@ package com.bybutter.sisyphus.project.gradle.threepart import com.bybutter.sisyphus.project.gradle.ensurePlugin import org.gradle.api.Plugin import org.gradle.api.Project -import org.jlleitschuh.gradle.ktlint.KtlintExtension -import org.jlleitschuh.gradle.ktlint.reporter.ReporterType -import java.io.File +import org.jmailen.gradle.kotlinter.tasks.FormatTask +import org.jmailen.gradle.kotlinter.tasks.LintTask class SisyphusKtlintPlugin : Plugin { override fun apply(target: Project) { - target.ensurePlugin("org.jlleitschuh.gradle.ktlint") { + target.ensurePlugin("org.jmailen.kotlinter") { apply(it) }.also { if (!it) return } - val extension = target.extensions.getByType(KtlintExtension::class.java) - extension.filter { - val pattern1 = "${File.separatorChar}generated${File.separatorChar}" - val pattern2 = "${File.separatorChar}generated-src${File.separatorChar}" - it.exclude { - it.file.path.contains(pattern1) - } - it.exclude { - it.file.path.contains(pattern2) - } + target.tasks.withType(LintTask::class.java).whenTaskAdded { + it.exclude("**/generated/**") } - extension.reporters { - it.reporter(ReporterType.CHECKSTYLE) + + target.tasks.withType(FormatTask::class.java).whenTaskAdded { + it.exclude("**/generated/**") } } } diff --git a/src/main/kotlin/org/gradle/kotlin/dsl/SisyphusDevelopmentLayer.kt b/src/main/kotlin/org/gradle/kotlin/dsl/SisyphusDevelopmentLayer.kt index 4b346ff..88c43b1 100644 --- a/src/main/kotlin/org/gradle/kotlin/dsl/SisyphusDevelopmentLayer.kt +++ b/src/main/kotlin/org/gradle/kotlin/dsl/SisyphusDevelopmentLayer.kt @@ -27,7 +27,9 @@ enum class SisyphusDevelopmentLayer { /** * Layer 3, Framework development, include [API], [PLATFORM] */ - FRAMEWORK; + FRAMEWORK, + + ; companion object { val attribute = Attribute.of(SisyphusDevelopmentLayer::class.java) @@ -46,7 +48,10 @@ fun Project.frameworkLayer(dependency: T): Dependency { return layer(dependency, SisyphusDevelopmentLayer.FRAMEWORK) } -fun Project.layer(dependency: T, layer: SisyphusDevelopmentLayer): Dependency { +fun Project.layer( + dependency: T, + layer: SisyphusDevelopmentLayer, +): Dependency { val sisyphus = extensions.findByType(SisyphusExtension::class.java) ?: return dependency if (!sisyphus.developer.isPresent) return dependency if (sisyphus.layer.get().ordinal < layer.ordinal) return dependency @@ -79,7 +84,10 @@ fun Project.frameworkLayer(dependency: Provider): Provider Project.layer(dependency: Provider, layer: SisyphusDevelopmentLayer): Provider { +fun Project.layer( + dependency: Provider, + layer: SisyphusDevelopmentLayer, +): Provider { return dependency.map { layer(it, layer) }