From ce7264db11141851a44c45594ba4904372373d9f Mon Sep 17 00:00:00 2001 From: Goooler Date: Thu, 29 Sep 2022 16:10:15 +0800 Subject: [PATCH 1/9] Convert root build.gradle to kts --- build.gradle | 120 --------------------------------------------- build.gradle.kts | 125 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 120 deletions(-) delete mode 100644 build.gradle create mode 100644 build.gradle.kts diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 16507218c4..0000000000 --- a/build.gradle +++ /dev/null @@ -1,120 +0,0 @@ -plugins { - alias(libs.plugins.kotlin.jvm) apply false - alias(libs.plugins.checksum) - alias(libs.plugins.shadow) - alias(libs.plugins.githubRelease) -} - -def isKotlinDev = project.hasProperty('isKotlinDev') - -allprojects { p -> - if (isKotlinDev) { - String definedVersion = p.ext."VERSION_NAME".minus("-SNAPSHOT") - p.ext."VERSION_NAME" = "$definedVersion-kotlin-dev-SNAPSHOT".toString() - } - - tasks.withType(Test).configureEach { - it.useJUnitPlatform() - } -} - -configurations { - ktlint -} - -dependencies { - ktlint projects.ktlint -} - -task ktlint(type: JavaExec, group: LifecycleBasePlugin.VERIFICATION_GROUP) { - description = "Check Kotlin code style including experimental rules." - classpath = configurations.ktlint - mainClass.set("com.pinterest.ktlint.Main") - args '**/src/**/*.kt', - // Exclude sources which contain lint violations for the purpose of testing. - '!ktlint/src/test/resources/**', - '--baseline=ktlint/src/test/resources/test-baseline.xml', - // Experimental rules run by default run on the ktlint code base itself. Experimental rules should not be released if - // we are not pleased ourselves with the results on the ktlint code base. - '--experimental' - // Do not run with option "--verbose" or "-v" as the lint violations are difficult to spot between the amount of - // debug output lines. -} - -// Deployment tasks -String getGithubToken() { - if (project.hasProperty("servers.github.privKey")) { - return project.'servers.github.privKey' - } else { - logger.warn("No github token specified") - return "" - } -} - -// Explicitly adding dependency on "shadowJarExecutable" as Gradle does not it set via "releaseAssets" property -tasks.named("githubRelease") { - dependsOn { projects.ktlint.dependencyProject.tasks.named("shadowJarExecutable") } -} - -githubRelease { - token getGithubToken() - owner "pinterest" - repo "ktlint" - tagName project.properties['VERSION_NAME'] - releaseName project.properties['VERSION_NAME'] - targetCommitish "master" - releaseAssets project.files({ - // "shadowJarExecutableChecksum" task does not declare checksum files - // as output, only the whole output directory. As it uses the same directory - // as "shadowJarExecutable" - just pass all the files from that directory - projects.ktlint.dependencyProject.tasks.named("shadowJarExecutable").get() - .outputs - .files - .getFiles() - .first() - .parentFile - .listFiles() - }) - overwrite true - dryRun false - body { - String changelog = project.file("CHANGELOG.md").text - changelog = changelog.substring(changelog.indexOf("## ")) - // 1 in indexOf here to skip first "## [" occurence - changelog.substring(0, changelog.indexOf("## [", 1)) - } -} - -// Put "servers.github.privKey" in "$HOME/.gradle/gradle.properties". -def announceTask = tasks.register("announceRelease", Exec.class) { announceTask -> - group = "Help" - description = "Runs .announce script" - subprojects - .findAll { !it.name.contains("ktlint-ruleset-template") } - .each { subproject -> - announceTask.dependsOn subproject.tasks.named("publishMavenPublicationToMavenCentralRepository") - } - - commandLine './.announce', '-y' - environment VERSION: "${project.'VERSION_NAME'}" - environment GITHUB_TOKEN: "${getGithubToken()}" -} - -def homebrewTask = tasks.register("homebrewBumpFormula", Exec.class) { homebrewTask -> - group "Help" - description "Runs brew bump-forumula-pr" - commandLine './.homebrew' - environment VERSION: "${project.'VERSION_NAME'}" - dependsOn(tasks.named("githubRelease")) -} - -tasks.register("publishNewRelease", DefaultTask.class) { - group = "Help" - description = "Triggers uploading new archives and publish announcements" - dependsOn(announceTask, homebrewTask, tasks.named("githubRelease")) -} - -tasks.wrapper { - gradleVersion = libs.versions.gradle.get() - distributionSha256Sum = libs.versions.gradleSha256.get() -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000000..68e8178eed --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,125 @@ +plugins { + alias(libs.plugins.kotlin.jvm) apply false + alias(libs.plugins.checksum) + alias(libs.plugins.shadow) + alias(libs.plugins.githubRelease) +} + +val isKotlinDev = project.hasProperty("isKotlinDev") + +allprojects { + if (isKotlinDev) { + val definedVersion = ext["VERSION_NAME"].toString().removeSuffix("-SNAPSHOT") + ext["VERSION_NAME"] = "$definedVersion-kotlin-dev-SNAPSHOT" + } + + tasks.withType().configureEach { + useJUnitPlatform() + } +} + +val ktlint: Configuration = configurations.create("ktlint") + +dependencies { + ktlint(projects.ktlint) +} + +tasks.register("ktlint") { + group = LifecycleBasePlugin.VERIFICATION_GROUP + description = "Check Kotlin code style including experimental rules." + classpath = ktlint + mainClass.set("com.pinterest.ktlint.Main") + args( + "**/src/**/*.kt", + // Exclude sources which contain lint violations for the purpose of testing. + "!ktlint/src/test/resources/**", + "--baseline=ktlint/src/test/resources/test-baseline.xml", + // Experimental rules run by default run on the ktlint code base itself. Experimental rules should not be released if + // we are not pleased ourselves with the results on the ktlint code base. + "--experimental", + // Do not run with option "--verbose" or "-v" as the lint violations are difficult to spot between the amount of + // debug output lines. + ) +} + +// Deployment tasks +fun getGithubToken(): String { + return if (project.hasProperty("servers.github.privKey")) { + project.property("servers.github.privKey").toString() + } else { + logger.warn("No github token specified") + "" + } +} + +// Explicitly adding dependency on "shadowJarExecutable" as Gradle does not it set via "releaseAssets" property +tasks.named("githubRelease").configure { + dependsOn(provider { projects.ktlint.dependencyProject.tasks.named("shadowJarExecutable") }) +} + +githubRelease { + token(getGithubToken()) + owner("pinterest") + repo("ktlint") + tagName(project.properties["VERSION_NAME"].toString()) + releaseName(project.properties["VERSION_NAME"].toString()) + targetCommitish("master") + releaseAssets( + project.files( + { + // "shadowJarExecutableChecksum" task does not declare checksum files + // as output, only the whole output directory. As it uses the same directory + // as "shadowJarExecutable" - just pass all the files from that directory + projects.ktlint.dependencyProject.tasks.named("shadowJarExecutable").get() + .outputs + .files + .getFiles() + .first() + .parentFile + .listFiles() + }, + ), + ) + overwrite(true) + dryRun(false) + body { + var changelog = project.file("CHANGELOG.md").readText() + changelog = changelog.substring(changelog.indexOf("## ")) + // 1 in indexOf here to skip first "## [" occurence + changelog.substring(0, changelog.indexOf("## [", 1)) + } +} + +// Put "servers.github.privKey" in "$HOME/.gradle/gradle.properties". +val announceTask = tasks.register("announceRelease", Exec::class.java) { + group = "Help" + description = "Runs .announce script" + subprojects.filter { + !it.name.contains("ktlint-ruleset-template") + }.forEach { subproject -> + dependsOn(subproject.tasks.named("publishMavenPublicationToMavenCentralRepository")) + } + + commandLine("./.announce", "-y") + environment("VERSION" to "${project.property("VERSION_NAME")}") + environment("GITHUB_TOKEN" to "${getGithubToken()}") +} + +val homebrewTask = tasks.register("homebrewBumpFormula", Exec::class.java) { + group = "Help" + description = "Runs brew bump-forumula-pr" + commandLine("./.homebrew") + environment("VERSION" to "${project.property("VERSION_NAME")}") + dependsOn(tasks.named("githubRelease")) +} + +tasks.register("publishNewRelease", DefaultTask::class) { + group = "Help" + description = "Triggers uploading new archives and publish announcements" + dependsOn(announceTask, homebrewTask, tasks.named("githubRelease")) +} + +tasks.wrapper { + gradleVersion = libs.versions.gradle.get() + distributionSha256Sum = libs.versions.gradleSha256.get() +} From 11c230a30c71e9bad4f13b8a1300ce417ab1a1ea Mon Sep 17 00:00:00 2001 From: Goooler Date: Thu, 29 Sep 2022 16:32:26 +0800 Subject: [PATCH 2/9] Cleanup --- build.gradle.kts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 68e8178eed..8fd2547bcc 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -53,7 +53,7 @@ fun getGithubToken(): String { } // Explicitly adding dependency on "shadowJarExecutable" as Gradle does not it set via "releaseAssets" property -tasks.named("githubRelease").configure { +tasks.named("githubRelease") { dependsOn(provider { projects.ktlint.dependencyProject.tasks.named("shadowJarExecutable") }) } @@ -91,7 +91,7 @@ githubRelease { } // Put "servers.github.privKey" in "$HOME/.gradle/gradle.properties". -val announceTask = tasks.register("announceRelease", Exec::class.java) { +val announceRelease by tasks.registering(Exec::class) { group = "Help" description = "Runs .announce script" subprojects.filter { @@ -102,10 +102,10 @@ val announceTask = tasks.register("announceRelease", Exec::class.java) { commandLine("./.announce", "-y") environment("VERSION" to "${project.property("VERSION_NAME")}") - environment("GITHUB_TOKEN" to "${getGithubToken()}") + environment("GITHUB_TOKEN" to getGithubToken()) } -val homebrewTask = tasks.register("homebrewBumpFormula", Exec::class.java) { +val homebrewBumpFormula by tasks.registering(Exec::class) { group = "Help" description = "Runs brew bump-forumula-pr" commandLine("./.homebrew") @@ -116,7 +116,7 @@ val homebrewTask = tasks.register("homebrewBumpFormula", Exec::class.java) { tasks.register("publishNewRelease", DefaultTask::class) { group = "Help" description = "Triggers uploading new archives and publish announcements" - dependsOn(announceTask, homebrewTask, tasks.named("githubRelease")) + dependsOn(announceRelease, homebrewBumpFormula, tasks.named("githubRelease")) } tasks.wrapper { From 91de455da40a3c3b16f9b41eb387d9050558ec0d Mon Sep 17 00:00:00 2001 From: Goooler Date: Thu, 29 Sep 2022 16:37:46 +0800 Subject: [PATCH 3/9] Merge redundant properties --- gradle.properties | 2 ++ ktlint-core/gradle.properties | 2 -- ktlint-reporter-baseline/gradle.properties | 2 -- ktlint-reporter-checkstyle/gradle.properties | 2 -- ktlint-reporter-format/gradle.properties | 2 -- ktlint-reporter-html/gradle.properties | 2 -- ktlint-reporter-json/gradle.properties | 2 -- ktlint-reporter-plain/gradle.properties | 2 -- ktlint-reporter-sarif/gradle.properties | 2 -- ktlint-ruleset-experimental/gradle.properties | 2 -- ktlint-ruleset-standard/gradle.properties | 2 -- ktlint-ruleset-test/gradle.properties | 2 -- ktlint-test-logging/gradle.properties | 2 -- ktlint-test/gradle.properties | 2 -- ktlint/gradle.properties | 1 - 15 files changed, 2 insertions(+), 27 deletions(-) diff --git a/gradle.properties b/gradle.properties index eaa9cd3a0e..857309fcbc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,5 @@ VERSION_NAME=0.48.0-SNAPSHOT +GROUP=com.pinterest.ktlint POM_DESCRIPTION=An anti-bikeshedding Kotlin linter with built-in formatter. @@ -6,6 +7,7 @@ POM_URL=https://github.com/pinterest/ktlint POM_SCM_URL=https://github.com/pinterest/ktlint POM_SCM_CONNECTION=scm:git:git://github.com/pinterest/ktlint.git POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/pinterest/ktlint.git +POM_PACKAGING=jar POM_LICENSE_NAME=MIT POM_LICENSE_URL=https://opensource.org/licenses/MIT diff --git a/ktlint-core/gradle.properties b/ktlint-core/gradle.properties index 15863af7d4..f8b158c437 100644 --- a/ktlint-core/gradle.properties +++ b/ktlint-core/gradle.properties @@ -1,4 +1,2 @@ -GROUP=com.pinterest.ktlint POM_NAME=ktlint-core POM_ARTIFACT_ID=ktlint-core -POM_PACKAGING=jar diff --git a/ktlint-reporter-baseline/gradle.properties b/ktlint-reporter-baseline/gradle.properties index 3f601372ea..53b60b42da 100644 --- a/ktlint-reporter-baseline/gradle.properties +++ b/ktlint-reporter-baseline/gradle.properties @@ -1,4 +1,2 @@ -GROUP=com.pinterest.ktlint POM_NAME=ktlint-reporter-baseline POM_ARTIFACT_ID=ktlint-reporter-baseline -POM_PACKAGING=jar diff --git a/ktlint-reporter-checkstyle/gradle.properties b/ktlint-reporter-checkstyle/gradle.properties index e4517ed178..1e02c3f929 100644 --- a/ktlint-reporter-checkstyle/gradle.properties +++ b/ktlint-reporter-checkstyle/gradle.properties @@ -1,4 +1,2 @@ -GROUP=com.pinterest.ktlint POM_NAME=ktlint-reporter-checkstyle POM_ARTIFACT_ID=ktlint-reporter-checkstyle -POM_PACKAGING=jar diff --git a/ktlint-reporter-format/gradle.properties b/ktlint-reporter-format/gradle.properties index 7858a8bf91..81cb4b82a7 100644 --- a/ktlint-reporter-format/gradle.properties +++ b/ktlint-reporter-format/gradle.properties @@ -1,4 +1,2 @@ -GROUP=com.pinterest.ktlint POM_NAME=ktlint-reporter-format POM_ARTIFACT_ID=ktlint-reporter-format -POM_PACKAGING=jar diff --git a/ktlint-reporter-html/gradle.properties b/ktlint-reporter-html/gradle.properties index a5d9001bfa..0adcb01c89 100644 --- a/ktlint-reporter-html/gradle.properties +++ b/ktlint-reporter-html/gradle.properties @@ -1,4 +1,2 @@ -GROUP=com.pinterest.ktlint POM_NAME=ktlint-reporter-html POM_ARTIFACT_ID=ktlint-reporter-html -POM_PACKAGING=jar diff --git a/ktlint-reporter-json/gradle.properties b/ktlint-reporter-json/gradle.properties index 87231d378c..5b22447815 100644 --- a/ktlint-reporter-json/gradle.properties +++ b/ktlint-reporter-json/gradle.properties @@ -1,4 +1,2 @@ -GROUP=com.pinterest.ktlint POM_NAME=ktlint-reporter-json POM_ARTIFACT_ID=ktlint-reporter-json -POM_PACKAGING=jar diff --git a/ktlint-reporter-plain/gradle.properties b/ktlint-reporter-plain/gradle.properties index eefd1ecfb7..6430b9fd76 100644 --- a/ktlint-reporter-plain/gradle.properties +++ b/ktlint-reporter-plain/gradle.properties @@ -1,4 +1,2 @@ -GROUP=com.pinterest.ktlint POM_NAME=ktlint-reporter-plain POM_ARTIFACT_ID=ktlint-reporter-plain -POM_PACKAGING=jar diff --git a/ktlint-reporter-sarif/gradle.properties b/ktlint-reporter-sarif/gradle.properties index 0c028bb1f5..eb1261a903 100644 --- a/ktlint-reporter-sarif/gradle.properties +++ b/ktlint-reporter-sarif/gradle.properties @@ -1,4 +1,2 @@ -GROUP=com.pinterest.ktlint POM_NAME=ktlint-reporter-sarif POM_ARTIFACT_ID=ktlint-reporter-sarif -POM_PACKAGING=jar diff --git a/ktlint-ruleset-experimental/gradle.properties b/ktlint-ruleset-experimental/gradle.properties index 0a983b71b3..47018a88a6 100644 --- a/ktlint-ruleset-experimental/gradle.properties +++ b/ktlint-ruleset-experimental/gradle.properties @@ -1,4 +1,2 @@ -GROUP=com.pinterest.ktlint POM_NAME=ktlint-ruleset-experimental POM_ARTIFACT_ID=ktlint-ruleset-experimental -POM_PACKAGING=jar diff --git a/ktlint-ruleset-standard/gradle.properties b/ktlint-ruleset-standard/gradle.properties index a56d010d27..a47f3dbe46 100644 --- a/ktlint-ruleset-standard/gradle.properties +++ b/ktlint-ruleset-standard/gradle.properties @@ -1,4 +1,2 @@ -GROUP=com.pinterest.ktlint POM_NAME=ktlint-ruleset-standard POM_ARTIFACT_ID=ktlint-ruleset-standard -POM_PACKAGING=jar diff --git a/ktlint-ruleset-test/gradle.properties b/ktlint-ruleset-test/gradle.properties index 4e6bdad779..a6fbe6df6e 100644 --- a/ktlint-ruleset-test/gradle.properties +++ b/ktlint-ruleset-test/gradle.properties @@ -1,4 +1,2 @@ -GROUP=com.pinterest.ktlint POM_NAME=ktlint-ruleset-test POM_ARTIFACT_ID=ktlint-ruleset-test -POM_PACKAGING=jar diff --git a/ktlint-test-logging/gradle.properties b/ktlint-test-logging/gradle.properties index 659751d642..92c9a070fd 100644 --- a/ktlint-test-logging/gradle.properties +++ b/ktlint-test-logging/gradle.properties @@ -1,4 +1,2 @@ -GROUP=com.pinterest.ktlint POM_NAME=ktlint-test-logging POM_ARTIFACT_ID=ktlint-test-logging -POM_PACKAGING=jar diff --git a/ktlint-test/gradle.properties b/ktlint-test/gradle.properties index 395cd12deb..e3ce5b3dfb 100644 --- a/ktlint-test/gradle.properties +++ b/ktlint-test/gradle.properties @@ -1,4 +1,2 @@ -GROUP=com.pinterest.ktlint POM_NAME=ktlint-test POM_ARTIFACT_ID=ktlint-test -POM_PACKAGING=jar diff --git a/ktlint/gradle.properties b/ktlint/gradle.properties index 15ad7186a6..5aafec738f 100644 --- a/ktlint/gradle.properties +++ b/ktlint/gradle.properties @@ -1,4 +1,3 @@ GROUP=com.pinterest POM_NAME=ktlint POM_ARTIFACT_ID=ktlint -POM_PACKAGING=jar From 48402d760d6d5e14623f7798d8e79686adcdeee5 Mon Sep 17 00:00:00 2001 From: Goooler Date: Thu, 29 Sep 2022 16:53:05 +0800 Subject: [PATCH 4/9] Lint kts files --- build.gradle.kts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index 8fd2547bcc..cd62a18ea2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -31,6 +31,8 @@ tasks.register("ktlint") { mainClass.set("com.pinterest.ktlint.Main") args( "**/src/**/*.kt", + "**.kts", + "!**/build/**", // Exclude sources which contain lint violations for the purpose of testing. "!ktlint/src/test/resources/**", "--baseline=ktlint/src/test/resources/test-baseline.xml", From bbd13ede5d858c23a1974c90459bee32ffa0730f Mon Sep 17 00:00:00 2001 From: Goooler Date: Thu, 29 Sep 2022 17:22:44 +0800 Subject: [PATCH 5/9] Cleanup --- build.gradle.kts | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index cd62a18ea2..422ca39f74 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -66,21 +66,14 @@ githubRelease { tagName(project.properties["VERSION_NAME"].toString()) releaseName(project.properties["VERSION_NAME"].toString()) targetCommitish("master") - releaseAssets( - project.files( - { - // "shadowJarExecutableChecksum" task does not declare checksum files - // as output, only the whole output directory. As it uses the same directory - // as "shadowJarExecutable" - just pass all the files from that directory - projects.ktlint.dependencyProject.tasks.named("shadowJarExecutable").get() - .outputs - .files - .getFiles() - .first() - .parentFile - .listFiles() - }, - ), + releaseAssets.from( + provider { + // "shadowJarExecutableChecksum" task does not declare checksum files + // as output, only the whole output directory. As it uses the same directory + // as "shadowJarExecutable" - just pass all the files from that directory + projects.ktlint.dependencyProject.tasks.named("shadowJarExecutable").get() + .outputs.files.files.first().parentFile.listFiles() + }, ) overwrite(true) dryRun(false) From 6a67aa74771936a21a971f780e902deb6f441e21 Mon Sep 17 00:00:00 2001 From: Goooler Date: Fri, 30 Sep 2022 14:48:08 +0800 Subject: [PATCH 6/9] Cleanup --- build.gradle.kts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 422ca39f74..83b6a3d9c0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -66,14 +66,16 @@ githubRelease { tagName(project.properties["VERSION_NAME"].toString()) releaseName(project.properties["VERSION_NAME"].toString()) targetCommitish("master") - releaseAssets.from( - provider { - // "shadowJarExecutableChecksum" task does not declare checksum files - // as output, only the whole output directory. As it uses the same directory - // as "shadowJarExecutable" - just pass all the files from that directory - projects.ktlint.dependencyProject.tasks.named("shadowJarExecutable").get() - .outputs.files.files.first().parentFile.listFiles() - }, + releaseAssets( + project.files( + provider { + // "shadowJarExecutableChecksum" task does not declare checksum files + // as output, only the whole output directory. As it uses the same directory + // as "shadowJarExecutable" - just pass all the files from that directory + projects.ktlint.dependencyProject.tasks.named("shadowJarExecutable").get() + .outputs.files.files.first().parentFile.listFiles() + }, + ), ) overwrite(true) dryRun(false) From 02a515fdf0ead8aaf63892365a200d99bc1e4c68 Mon Sep 17 00:00:00 2001 From: Goooler Date: Fri, 30 Sep 2022 15:14:50 +0800 Subject: [PATCH 7/9] Tweak --- build.gradle.kts | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 83b6a3d9c0..781f41df45 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { alias(libs.plugins.githubRelease) } -val isKotlinDev = project.hasProperty("isKotlinDev") +val isKotlinDev: Boolean = project.hasProperty("isKotlinDev") allprojects { if (isKotlinDev) { @@ -45,26 +45,28 @@ tasks.register("ktlint") { } // Deployment tasks -fun getGithubToken(): String { - return if (project.hasProperty("servers.github.privKey")) { - project.property("servers.github.privKey").toString() - } else { - logger.warn("No github token specified") - "" - } +val githubToken: String = if (project.hasProperty("servers.github.privKey")) { + project.property("servers.github.privKey").toString() +} else { + logger.warn("No github token specified") + "" +} + +val shadowJarExecutable: TaskProvider by lazy { + projects.ktlint.dependencyProject.tasks.named("shadowJarExecutable") } // Explicitly adding dependency on "shadowJarExecutable" as Gradle does not it set via "releaseAssets" property tasks.named("githubRelease") { - dependsOn(provider { projects.ktlint.dependencyProject.tasks.named("shadowJarExecutable") }) + dependsOn(provider { shadowJarExecutable }) } githubRelease { - token(getGithubToken()) + token(githubToken) owner("pinterest") repo("ktlint") - tagName(project.properties["VERSION_NAME"].toString()) - releaseName(project.properties["VERSION_NAME"].toString()) + tagName(project.property("VERSION_NAME").toString()) + releaseName(project.property("VERSION_NAME").toString()) targetCommitish("master") releaseAssets( project.files( @@ -72,8 +74,7 @@ githubRelease { // "shadowJarExecutableChecksum" task does not declare checksum files // as output, only the whole output directory. As it uses the same directory // as "shadowJarExecutable" - just pass all the files from that directory - projects.ktlint.dependencyProject.tasks.named("shadowJarExecutable").get() - .outputs.files.files.first().parentFile.listFiles() + shadowJarExecutable.get().outputs.files.files.first().parentFile.listFiles() }, ), ) @@ -91,15 +92,13 @@ githubRelease { val announceRelease by tasks.registering(Exec::class) { group = "Help" description = "Runs .announce script" - subprojects.filter { - !it.name.contains("ktlint-ruleset-template") - }.forEach { subproject -> + subprojects.filter { !it.name.contains("ktlint-ruleset-template") }.forEach { subproject -> dependsOn(subproject.tasks.named("publishMavenPublicationToMavenCentralRepository")) } commandLine("./.announce", "-y") environment("VERSION" to "${project.property("VERSION_NAME")}") - environment("GITHUB_TOKEN" to getGithubToken()) + environment("GITHUB_TOKEN" to githubToken) } val homebrewBumpFormula by tasks.registering(Exec::class) { @@ -110,7 +109,7 @@ val homebrewBumpFormula by tasks.registering(Exec::class) { dependsOn(tasks.named("githubRelease")) } -tasks.register("publishNewRelease", DefaultTask::class) { +tasks.register("publishNewRelease") { group = "Help" description = "Triggers uploading new archives and publish announcements" dependsOn(announceRelease, homebrewBumpFormula, tasks.named("githubRelease")) From fde549950d1185c3c4cc109ef8413d2b55d5e1cd Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 4 Oct 2022 22:10:34 +0800 Subject: [PATCH 8/9] Defer more configurations --- ktlint-ruleset-template/build.gradle.kts | 10 ++++++---- ktlint/build.gradle.kts | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ktlint-ruleset-template/build.gradle.kts b/ktlint-ruleset-template/build.gradle.kts index db3967b9cf..732a31a71a 100644 --- a/ktlint-ruleset-template/build.gradle.kts +++ b/ktlint-ruleset-template/build.gradle.kts @@ -9,13 +9,13 @@ group = "com.github.username" val sourcesJar by tasks.registering(Jar::class) { dependsOn(tasks.classes) archiveClassifier.set("sources") - from(sourceSets.main.get().allSource) + from(sourceSets.main.map { it.allSource }) } val javadocJar by tasks.registering(Jar::class) { dependsOn(tasks.javadoc) archiveClassifier.set("javadoc") - from(tasks.javadoc.get().destinationDir) + from(tasks.javadoc.map { it.destinationDir!! }) } artifacts { @@ -46,10 +46,12 @@ tasks.register("ktlint") { mainClass.set("com.pinterest.ktlint.Main") // adding compiled classes to the classpath so that ktlint would validate project"s sources // using its own ruleset (in other words to dogfood) - classpath = ktlint + sourceSets.main.get().output + classpath(ktlint, sourceSets.main.map { it.output }) args("--debug", "src/**/*.kt") }.let { - tasks.check.get().dependsOn(it) + tasks.check.configure { + dependsOn(it) + } } afterEvaluate { diff --git a/ktlint/build.gradle.kts b/ktlint/build.gradle.kts index 6f536b694a..6d526f9c1e 100644 --- a/ktlint/build.gradle.kts +++ b/ktlint/build.gradle.kts @@ -69,7 +69,7 @@ val shadowJarExecutable by tasks.registering(DefaultTask::class) { signing.sign(execFile) } } - finalizedBy(tasks["shadowJarExecutableChecksum"]) + finalizedBy(tasks.named("shadowJarExecutableChecksum")) } tasks.register("shadowJarExecutableChecksum") { From 083fecf00b532828089866e7cf01c82ff0fc7758 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 4 Oct 2022 22:20:57 +0800 Subject: [PATCH 9/9] Cleanup --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 781f41df45..5e906f8767 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -57,7 +57,7 @@ val shadowJarExecutable: TaskProvider by lazy { } // Explicitly adding dependency on "shadowJarExecutable" as Gradle does not it set via "releaseAssets" property -tasks.named("githubRelease") { +tasks.githubRelease { dependsOn(provider { shadowJarExecutable }) }