Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert root build.gradle to kts #1663

Merged
merged 10 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 0 additions & 120 deletions build.gradle

This file was deleted.

121 changes: 121 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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<Test>().configureEach {
useJUnitPlatform()
}
}

val ktlint: Configuration = configurations.create("ktlint")

dependencies {
ktlint(projects.ktlint)
}

tasks.register<JavaExec>("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<Task> 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 })
}
Comment on lines +60 to +62
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


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<DefaultTask>("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()
}
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
VERSION_NAME=0.48.0-SNAPSHOT
GROUP=com.pinterest.ktlint

POM_DESCRIPTION=An anti-bikeshedding Kotlin linter with built-in formatter.

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
Expand Down
2 changes: 0 additions & 2 deletions ktlint-core/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
GROUP=com.pinterest.ktlint
POM_NAME=ktlint-core
POM_ARTIFACT_ID=ktlint-core
POM_PACKAGING=jar
2 changes: 0 additions & 2 deletions ktlint-reporter-baseline/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
GROUP=com.pinterest.ktlint
POM_NAME=ktlint-reporter-baseline
POM_ARTIFACT_ID=ktlint-reporter-baseline
POM_PACKAGING=jar
2 changes: 0 additions & 2 deletions ktlint-reporter-checkstyle/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
GROUP=com.pinterest.ktlint
POM_NAME=ktlint-reporter-checkstyle
POM_ARTIFACT_ID=ktlint-reporter-checkstyle
POM_PACKAGING=jar
2 changes: 0 additions & 2 deletions ktlint-reporter-format/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
GROUP=com.pinterest.ktlint
POM_NAME=ktlint-reporter-format
POM_ARTIFACT_ID=ktlint-reporter-format
POM_PACKAGING=jar
2 changes: 0 additions & 2 deletions ktlint-reporter-html/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
GROUP=com.pinterest.ktlint
POM_NAME=ktlint-reporter-html
POM_ARTIFACT_ID=ktlint-reporter-html
POM_PACKAGING=jar
2 changes: 0 additions & 2 deletions ktlint-reporter-json/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
GROUP=com.pinterest.ktlint
POM_NAME=ktlint-reporter-json
POM_ARTIFACT_ID=ktlint-reporter-json
POM_PACKAGING=jar
2 changes: 0 additions & 2 deletions ktlint-reporter-plain/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
GROUP=com.pinterest.ktlint
POM_NAME=ktlint-reporter-plain
POM_ARTIFACT_ID=ktlint-reporter-plain
POM_PACKAGING=jar
2 changes: 0 additions & 2 deletions ktlint-reporter-sarif/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
GROUP=com.pinterest.ktlint
POM_NAME=ktlint-reporter-sarif
POM_ARTIFACT_ID=ktlint-reporter-sarif
POM_PACKAGING=jar
2 changes: 0 additions & 2 deletions ktlint-ruleset-experimental/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
GROUP=com.pinterest.ktlint
POM_NAME=ktlint-ruleset-experimental
POM_ARTIFACT_ID=ktlint-ruleset-experimental
POM_PACKAGING=jar
2 changes: 0 additions & 2 deletions ktlint-ruleset-standard/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
GROUP=com.pinterest.ktlint
POM_NAME=ktlint-ruleset-standard
POM_ARTIFACT_ID=ktlint-ruleset-standard
POM_PACKAGING=jar
10 changes: 6 additions & 4 deletions ktlint-ruleset-template/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -46,10 +46,12 @@ tasks.register<JavaExec>("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 {
Expand Down
2 changes: 0 additions & 2 deletions ktlint-ruleset-test/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
GROUP=com.pinterest.ktlint
POM_NAME=ktlint-ruleset-test
POM_ARTIFACT_ID=ktlint-ruleset-test
POM_PACKAGING=jar
2 changes: 0 additions & 2 deletions ktlint-test-logging/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
GROUP=com.pinterest.ktlint
POM_NAME=ktlint-test-logging
POM_ARTIFACT_ID=ktlint-test-logging
POM_PACKAGING=jar
2 changes: 0 additions & 2 deletions ktlint-test/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
GROUP=com.pinterest.ktlint
POM_NAME=ktlint-test
POM_ARTIFACT_ID=ktlint-test
POM_PACKAGING=jar
2 changes: 1 addition & 1 deletion ktlint/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ val shadowJarExecutable by tasks.registering(DefaultTask::class) {
signing.sign(execFile)
}
}
finalizedBy(tasks["shadowJarExecutableChecksum"])
finalizedBy(tasks.named("shadowJarExecutableChecksum"))
}

tasks.register<Checksum>("shadowJarExecutableChecksum") {
Expand Down
1 change: 0 additions & 1 deletion ktlint/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
GROUP=com.pinterest
POM_NAME=ktlint
POM_ARTIFACT_ID=ktlint
POM_PACKAGING=jar