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..5e906f8767 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,121 @@ +plugins { + alias(libs.plugins.kotlin.jvm) apply false + alias(libs.plugins.checksum) + alias(libs.plugins.shadow) + alias(libs.plugins.githubRelease) +} + +val isKotlinDev: Boolean = 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", + "**.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", + // 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 +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.githubRelease { + dependsOn(provider { shadowJarExecutable }) +} + +githubRelease { + token(githubToken) + owner("pinterest") + repo("ktlint") + tagName(project.property("VERSION_NAME").toString()) + releaseName(project.property("VERSION_NAME").toString()) + targetCommitish("master") + 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 + shadowJarExecutable.get().outputs.files.files.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 announceRelease by tasks.registering(Exec::class) { + 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 githubToken) +} + +val homebrewBumpFormula by tasks.registering(Exec::class) { + group = "Help" + description = "Runs brew bump-forumula-pr" + commandLine("./.homebrew") + environment("VERSION" to "${project.property("VERSION_NAME")}") + dependsOn(tasks.named("githubRelease")) +} + +tasks.register("publishNewRelease") { + group = "Help" + description = "Triggers uploading new archives and publish announcements" + dependsOn(announceRelease, homebrewBumpFormula, tasks.named("githubRelease")) +} + +tasks.wrapper { + gradleVersion = libs.versions.gradle.get() + distributionSha256Sum = libs.versions.gradleSha256.get() +} 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-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-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/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") { 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