Skip to content

Commit

Permalink
Simple property assignments in KTS (pinterest#2123)
Browse files Browse the repository at this point in the history
* Simple property assignments in KTS

https://blog.gradle.org/simpler-kotlin-dsl-property-assignment

* Fix conflicts
  • Loading branch information
Goooler authored Oct 5, 2023
1 parent 025fff3 commit ea8df7e
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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<JavaCompile>().configureEach {
options.release.set(buildLogicTargetJavaVersion.majorVersion.toInt())
options.release = buildLogicTargetJavaVersion.majorVersion.toInt()
}
tasks.withType<KotlinCompile>().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 {
Expand Down
4 changes: 2 additions & 2 deletions build-logic/src/main/kotlin/ktlint-dokka.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Jar>("javadocJar") {
dependsOn(tasks.dokkaJavadoc)
archiveClassifier.set("javadoc")
archiveClassifier = "javadoc"
from(tasks.dokkaJavadoc)
}
4 changes: 2 additions & 2 deletions build-logic/src/main/kotlin/ktlint-kotlin-common.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ kotlin {
}

tasks.withType<JavaCompile>().configureEach {
options.release.set(javaTargetVersion.asInt())
options.release = javaTargetVersion.asInt()
}
tasks.withType<KotlinCompile>().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()
Expand Down
22 changes: 11 additions & 11 deletions build-logic/src/main/kotlin/ktlint-publication.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,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")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ tasks.register<JavaExec>("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",
Expand All @@ -50,7 +50,7 @@ tasks.register<JavaExec>("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",
Expand Down
10 changes: 5 additions & 5 deletions ktlint-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ tasks.register<Checksum>("shadowJarExecutableChecksum") {
.parentFile
},
)
checksumAlgorithm.set(Checksum.Algorithm.MD5)
checksumAlgorithm = Checksum.Algorithm.MD5
}

tasks.withType<Test>().configureEach {
Expand Down Expand Up @@ -167,8 +167,8 @@ tasks.withType<Test>().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"
}
12 changes: 6 additions & 6 deletions ktlint-ruleset-template/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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!! })
}

Expand All @@ -38,7 +38,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")
Expand All @@ -54,9 +54,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"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pluginManagement {
}

dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS
repositories {
mavenCentral()
}
Expand Down

0 comments on commit ea8df7e

Please sign in to comment.