From 800d7a85da14dbe6b59cc21c1c05b8755e699791 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 11 Jul 2023 15:33:42 +0800 Subject: [PATCH 1/2] Simple property assignments in KTS https://blog.gradle.org/simpler-kotlin-dsl-property-assignment --- .../src/main/kotlin/ktlint-dokka.gradle.kts | 4 ++-- .../kotlin/ktlint-kotlin-common.gradle.kts | 2 +- .../main/kotlin/ktlint-publication.gradle.kts | 22 +++++++++---------- build.gradle.kts | 4 ++-- ktlint-cli/build.gradle.kts | 10 ++++----- ktlint-ruleset-template/build.gradle.kts | 12 +++++----- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/build-logic/src/main/kotlin/ktlint-dokka.gradle.kts b/build-logic/src/main/kotlin/ktlint-dokka.gradle.kts index f1edc97255..cd95014d5d 100644 --- a/build-logic/src/main/kotlin/ktlint-dokka.gradle.kts +++ b/build-logic/src/main/kotlin/ktlint-dokka.gradle.kts @@ -10,11 +10,11 @@ java { tasks.dokkaJavadoc { notCompatibleWithConfigurationCache("https://github.com/Kotlin/dokka/issues/1217") - outputDirectory.set(buildDir.resolve("javadoc")) + outputDirectory = buildDir.resolve("javadoc") } tasks.named("javadocJar") { dependsOn(tasks.dokkaJavadoc) - archiveClassifier.set("javadoc") + archiveClassifier = "javadoc" from(tasks.dokkaJavadoc) } diff --git a/build-logic/src/main/kotlin/ktlint-kotlin-common.gradle.kts b/build-logic/src/main/kotlin/ktlint-kotlin-common.gradle.kts index c612c0a9dd..2605768fc0 100644 --- a/build-logic/src/main/kotlin/ktlint-kotlin-common.gradle.kts +++ b/build-logic/src/main/kotlin/ktlint-kotlin-common.gradle.kts @@ -12,7 +12,7 @@ kotlin { tasks.withType().configureEach { compilerOptions { - jvmTarget.set(JvmTarget.JVM_1_8) + jvmTarget = JvmTarget.JVM_1_8 } } diff --git a/build-logic/src/main/kotlin/ktlint-publication.gradle.kts b/build-logic/src/main/kotlin/ktlint-publication.gradle.kts index be2dd30536..324cc7e88c 100644 --- a/build-logic/src/main/kotlin/ktlint-publication.gradle.kts +++ b/build-logic/src/main/kotlin/ktlint-publication.gradle.kts @@ -26,26 +26,26 @@ publishing { artifactId = localGradleProperty("POM_ARTIFACT_ID").get() pom { - name.set(localGradleProperty("POM_NAME").get()) - description.set(providers.gradleProperty("POM_DESCRIPTION")) - url.set(providers.gradleProperty("POM_URL")) + name = localGradleProperty("POM_NAME") + description = providers.gradleProperty("POM_DESCRIPTION") + url = providers.gradleProperty("POM_URL") licenses { license { - name.set(providers.gradleProperty("POM_LICENSE_NAME")) - url.set(providers.gradleProperty("POM_LICENSE_URL")) - distribution.set("repo") + name = providers.gradleProperty("POM_LICENSE_NAME") + url = providers.gradleProperty("POM_LICENSE_URL") + distribution = "repo" } } developers { developer { - id.set(providers.gradleProperty("POM_DEVELOPER_ID")) - name.set(providers.gradleProperty("POM_DEVELOPER_NAME")) + id = providers.gradleProperty("POM_DEVELOPER_ID") + name = providers.gradleProperty("POM_DEVELOPER_NAME") } } scm { - url.set(providers.gradleProperty("POM_SCM_URL")) - connection.set(providers.gradleProperty("POM_SCM_CONNECTION")) - developerConnection.set(providers.gradleProperty("POM_SCM_DEV_CONNECTION")) + url = providers.gradleProperty("POM_SCM_URL") + connection = providers.gradleProperty("POM_SCM_CONNECTION") + developerConnection = providers.gradleProperty("POM_SCM_DEV_CONNECTION") } } } diff --git a/build.gradle.kts b/build.gradle.kts index ed20fdeb1d..2883314716 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,7 +16,7 @@ tasks.register("ktlintCheck") { group = LifecycleBasePlugin.VERIFICATION_GROUP description = "Check Kotlin code style" classpath = ktlint - mainClass.set("com.pinterest.ktlint.Main") + mainClass = "com.pinterest.ktlint.Main" args( "**/src/**/*.kt", "**.kts", @@ -30,7 +30,7 @@ tasks.register("ktlintFormat") { group = LifecycleBasePlugin.VERIFICATION_GROUP description = "Check Kotlin code style and format" classpath = ktlint - mainClass.set("com.pinterest.ktlint.Main") + mainClass = "com.pinterest.ktlint.Main" jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED") args( "-F", diff --git a/ktlint-cli/build.gradle.kts b/ktlint-cli/build.gradle.kts index 5940f247af..67081e829a 100644 --- a/ktlint-cli/build.gradle.kts +++ b/ktlint-cli/build.gradle.kts @@ -138,7 +138,7 @@ tasks.register("shadowJarExecutableChecksum") { .parentFile }, ) - checksumAlgorithm.set(Checksum.Algorithm.MD5) + checksumAlgorithm = Checksum.Algorithm.MD5 } tasks.withType().configureEach { @@ -159,8 +159,8 @@ tasks.withType().configureEach { sdkman { val sdkmanVersion = providers.environmentVariable("SDKMAN_VERSION").orElse(project.version.toString()) - candidate.set("ktlint") - version.set(sdkmanVersion) - url.set("https://github.com/pinterest/ktlint/releases/download/$sdkmanVersion/ktlint-$sdkmanVersion.zip") - hashtag.set("ktlint") + candidate = "ktlint" + version = sdkmanVersion + url = "https://github.com/pinterest/ktlint/releases/download/$sdkmanVersion/ktlint-$sdkmanVersion.zip" + hashtag = "ktlint" } diff --git a/ktlint-ruleset-template/build.gradle.kts b/ktlint-ruleset-template/build.gradle.kts index d3bd93cf71..a176324b6e 100644 --- a/ktlint-ruleset-template/build.gradle.kts +++ b/ktlint-ruleset-template/build.gradle.kts @@ -8,13 +8,13 @@ group = "com.github.username" val sourcesJar by tasks.registering(Jar::class) { dependsOn(tasks.classes) - archiveClassifier.set("sources") + archiveClassifier = "sources" from(sourceSets.main.map { it.allSource }) } val javadocJar by tasks.registering(Jar::class) { dependsOn(tasks.javadoc) - archiveClassifier.set("javadoc") + archiveClassifier = "javadoc" from(tasks.javadoc.map { it.destinationDir!! }) } @@ -37,7 +37,7 @@ dependencies { val ktlintCheck by tasks.registering(JavaExec::class) { dependsOn(tasks.classes) group = LifecycleBasePlugin.VERIFICATION_GROUP - mainClass.set("com.pinterest.ktlint.Main") + mainClass = "com.pinterest.ktlint.Main" // Adding compiled classes of this ruleset to the classpath so that ktlint validates the ruleset using its own ruleset classpath(ktlint, sourceSets.main.map { it.output }) args("--log-level=debug", "src/**/*.kt") @@ -53,9 +53,9 @@ publishing { pom { licenses { license { - name.set("The Apache Software License, Version 2.0") - url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") - distribution.set("repo") + name = "The Apache Software License, Version 2.0" + url = "https://www.apache.org/licenses/LICENSE-2.0.txt" + distribution = "repo" } } } From f9d0c65a24e9dfa675e4362092b267256a3e3056 Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 6 Sep 2023 12:38:21 +0800 Subject: [PATCH 2/2] Fix conflicts --- build-logic/build.gradle.kts | 4 ++-- build-logic/src/main/kotlin/ktlint-kotlin-common.gradle.kts | 4 ++-- settings.gradle.kts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index 40848334f7..5871911a1f 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -25,11 +25,11 @@ kotlin { // @see https://github.com/pinterest/ktlint/pull/2120#discussion_r1260229055 for more details val buildLogicTargetJavaVersion = JavaVersion.VERSION_17 tasks.withType().configureEach { - options.release.set(buildLogicTargetJavaVersion.majorVersion.toInt()) + options.release = buildLogicTargetJavaVersion.majorVersion.toInt() } tasks.withType().configureEach { // Convert Java version (e.g. "1.8" or "11") to Kotlin JvmTarget ("8" resp. "11") - compilerOptions.jvmTarget.set(JvmTarget.fromTarget(buildLogicTargetJavaVersion.toString())) + compilerOptions.jvmTarget = JvmTarget.fromTarget(buildLogicTargetJavaVersion.toString()) } dependencies { diff --git a/build-logic/src/main/kotlin/ktlint-kotlin-common.gradle.kts b/build-logic/src/main/kotlin/ktlint-kotlin-common.gradle.kts index 00143f52bc..8711cbcd8f 100644 --- a/build-logic/src/main/kotlin/ktlint-kotlin-common.gradle.kts +++ b/build-logic/src/main/kotlin/ktlint-kotlin-common.gradle.kts @@ -17,11 +17,11 @@ kotlin { } tasks.withType().configureEach { - options.release.set(javaTargetVersion.asInt()) + options.release = javaTargetVersion.asInt() } tasks.withType().configureEach { // Convert Java version (e.g. "1.8" or "11") to Kotlin JvmTarget ("8" resp. "11") - compilerOptions.jvmTarget.set(JvmTarget.fromTarget(JavaVersion.toVersion(javaTargetVersion).toString())) + compilerOptions.jvmTarget = JvmTarget.fromTarget(JavaVersion.toVersion(javaTargetVersion).toString()) } val requestedJdkVersion = project.findProperty("testJdkVersion")?.toString()?.toInt() diff --git a/settings.gradle.kts b/settings.gradle.kts index f0db0c3b25..a147144890 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -8,7 +8,7 @@ pluginManagement { } dependencyResolutionManagement { - repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS repositories { mavenCentral() }