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 gradle build scripts to kts #1449

Merged
merged 27 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
117 changes: 0 additions & 117 deletions build.gradle

This file was deleted.

123 changes: 123 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
plugins {
id(libs.plugins.kotlin.jvm.get().pluginId) 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")
// 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.
// Sources in "ktlint/src/test/resources" are excluded as those source contain lint errors that have to be detected by
// unit tests and should not be reported/fixed.
args(
"**/src/**/*.kt",
"**.kts",
"!**/build/**",
paul-dingemans marked this conversation as resolved.
Show resolved Hide resolved
"!ktlint/src/test/resources/**",
"--baseline=ktlint/src/test/resources/test-baseline.xml",
"--experimental",
"--verbose"
)
}

// 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: Task by lazy {
projects.ktlint.dependencyProject.tasks["shadowJarExecutable"]
}

// Explicitly adding dependency on "shadowJarExecutable" as Gradle does not it set via "releaseAssets" property
tasks.githubRelease {
dependsOn({
shadowJarExecutable
})
}

githubRelease {
token(githubToken)
owner("pinterest")
repo("ktlint")
tagName(project.property("VERSION_NAME").toString())
releaseName(project.property("VERSION_NAME").toString())
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
shadowJarExecutable.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["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.githubRelease)
}

tasks.register<DefaultTask>("publishNewRelease") {
group = "Help"
description = "Triggers uploading new archives and publish announcements"
dependsOn(announceRelease, homebrewBumpFormula, tasks.githubRelease)
}

tasks.wrapper {
gradleVersion = libs.versions.gradle.get()
distributionSha256Sum = libs.versions.gradleSha256.get()
distributionType = Wrapper.DistributionType.BIN
}
15 changes: 6 additions & 9 deletions buildSrc/src/main/kotlin/ktlint-kotlin-common.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("org.jetbrains.kotlin.jvm")
kotlin("jvm")
}

repositories {
Expand All @@ -19,14 +19,11 @@ kotlin {
}
}

tasks
.withType<KotlinCompile>()
.configureEach {
kotlinOptions {
apiVersion = "1.4"
@Suppress("SuspiciousCollectionReassignment")
freeCompilerArgs += listOf("-opt-in=kotlin.RequiresOptIn")
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
@Suppress("SuspiciousCollectionReassignment")
freeCompilerArgs += listOf("-opt-in=kotlin.RequiresOptIn")
}
}

addAdditionalJdkVersionTests()
26 changes: 13 additions & 13 deletions buildSrc/src/main/kotlin/ktlint-publication.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,31 @@ project.group = project.property("GROUP")
publishing {
publications {
create<MavenPublication>("maven") {
groupId = project.property("GROUP") as String?
artifactId = project.property("POM_ARTIFACT_ID") as String?
version = project.property("VERSION_NAME") as String?
groupId = project.property("GROUP").toString()
artifactId = project.property("POM_ARTIFACT_ID").toString()
version = project.property("VERSION_NAME").toString()

pom {
name.set(project.property("POM_NAME") as String?)
description.set(project.property("POM_DESCRIPTION") as String?)
url.set(project.property("POM_URL") as String?)
name.set(project.property("POM_NAME").toString())
description.set(project.property("POM_DESCRIPTION").toString())
url.set(project.property("POM_URL").toString())
licenses {
license {
name.set(project.property("POM_LICENSE_NAME") as String?)
url.set(project.property("POM_LICENSE_URL") as String?)
name.set(project.property("POM_LICENSE_NAME").toString())
url.set(project.property("POM_LICENSE_URL").toString())
distribution.set("repo")
}
}
developers {
developer {
id.set(project.property("POM_DEVELOPER_ID") as String?)
name.set(project.property("POM_DEVELOPER_NAME") as String?)
id.set(project.property("POM_DEVELOPER_ID").toString())
name.set(project.property("POM_DEVELOPER_NAME").toString())
}
}
scm {
url.set(project.property("POM_SCM_URL") as String?)
connection.set(project.property("POM_SCM_CONNECTION") as String?)
developerConnection.set(project.property("POM_SCM_DEV_CONNECTION") as String?)
url.set(project.property("POM_SCM_URL").toString())
connection.set(project.property("POM_SCM_CONNECTION").toString())
developerConnection.set(project.property("POM_SCM_DEV_CONNECTION").toString())
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
gradle = "7.4"
gradleSha256 = "8cc27038d5dbd815759851ba53e70cf62e481b87494cc97cfd97982ada5ba634"
kotlin = "1.6.0"
kotlin = "1.6.21"

[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
Expand Down
13 changes: 13 additions & 0 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,19 @@
<sha256 value="43c86e6467b2f8f15351e7a44b4b235b6f18b2df6b49a9c05ebdcabac130ccc0" origin="Generated by Gradle because artifact wasn't signed"/>
</artifact>
</component>
<component group="com.gradle" name="gradle-enterprise-gradle-plugin" version="3.8.1">
<artifact name="gradle-enterprise-gradle-plugin-3.8.1.jar">
<pgp value="314fe82e5a4c5377bca2edec5208812e1e4a6db0"/>
</artifact>
<artifact name="gradle-enterprise-gradle-plugin-3.8.1.pom">
<sha256 value="e47a53196079934edf14b36b4b77e380d17327a3d8eeab05ba061ca3fc1334a5" origin="Generated by Gradle because artifact wasn't signed"/>
</artifact>
</component>
<component group="com.gradle.enterprise" name="com.gradle.enterprise.gradle.plugin" version="3.8.1">
<artifact name="com.gradle.enterprise.gradle.plugin-3.8.1.pom">
<sha256 value="9fc8ccc9212ea0903c17dbea3c3dfb406d6db5490b6e65aa13a7af1fecda82b4" origin="Generated by Gradle because artifact wasn't signed"/>
</artifact>
</component>
<component group="gradle.plugin.com.github.johnrengelman" name="shadow" version="7.1.1">
<artifact name="shadow-7.1.1.jar">
<sha256 value="a870861a7a3d54ffd97822051a27b2f1b86dd5c480317f0b97f3b27581b742af" origin="Generated by Gradle because artifact wasn't signed"/>
Expand Down
17 changes: 0 additions & 17 deletions ktlint-core/build.gradle

This file was deleted.

17 changes: 17 additions & 0 deletions ktlint-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugins {
`ktlint-publication`
`ktlint-kotlin-common`
}

dependencies {
api(libs.kotlin.compiler)
api(libs.ec4j)
api(libs.logging)

// Standard ruleset is required for EditConfigLoaderTest only
testImplementation(projects.ktlintRulesetStandard)
testImplementation(projects.ktlintTestLogging)
testImplementation(libs.junit5)
testImplementation(libs.assertj)
testImplementation(libs.jimfs)
}
11 changes: 0 additions & 11 deletions ktlint-reporter-baseline/build.gradle

This file was deleted.

Loading