Skip to content

Commit 9bb3310

Browse files
committed
fix: use consistent version of ktlint in build-support plugin and ensure that kotlin-compiler-embeddable isn't in buildscript classpaths
1 parent 76b6034 commit 9bb3310

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

build-plugins/build-support/build.gradle.kts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ repositories {
1919

2020
dependencies {
2121
// make our custom lint rules available to the buildscript classpath
22-
runtimeOnly(project(":ktlint-rules"))
22+
runtimeOnly(project(":ktlint-rules")) {
23+
// Ensure that kotlin-compiler-embeddable isn't included in the buildscript classpath in consuming modules
24+
exclude(group = "org.jetbrains.kotlin", module = "kotlin-compiler-embeddable")
25+
}
2326
implementation(libs.nexusPublishPlugin)
2427
compileOnly(gradleApi())
2528
implementation("aws.sdk.kotlin:s3:1.1.+")
@@ -36,7 +39,26 @@ gradlePlugin {
3639
}
3740
}
3841

42+
val generateKtlintVersion by tasks.registering {
43+
// generate the version of the runtime to use as a resource.
44+
// this keeps us from having to manually change version numbers in multiple places
45+
val resourcesDir = layout.buildDirectory.dir("resources/main/aws/sdk/kotlin/gradle/dsl").get()
46+
47+
val versionCatalog = rootProject.file("gradle/libs.versions.toml")
48+
inputs.file(versionCatalog)
49+
50+
val versionFile = file("$resourcesDir/ktlint-version.txt")
51+
outputs.file(versionFile)
52+
53+
val version = libs.ktlint.cli.ruleset.core.get().version
54+
sourceSets.main.get().output.dir(resourcesDir)
55+
doLast {
56+
versionFile.writeText("$version")
57+
}
58+
}
59+
3960
tasks.withType<KotlinCompile> {
61+
dependsOn(generateKtlintVersion)
4062
compilerOptions {
4163
jvmTarget.set(JvmTarget.JVM_1_8)
4264
freeCompilerArgs.add("-opt-in=kotlin.RequiresOptIn")

build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/CodeStyle.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,21 @@ import org.gradle.language.base.plugins.LifecycleBasePlugin
1818
fun Project.configureLinting(lintPaths: List<String>) {
1919
verifyRootProject { "Kotlin SDK lint configuration is expected to be configured on the root project" }
2020

21+
val ktlintVersion = object {} // Can't use Project.javaClass because that's using the Gradle classloader
22+
.javaClass
23+
.getResource("ktlint-version.txt")
24+
?.readText()
25+
?: error("Missing ktlint-version.txt")
26+
2127
val ktlint by configurations.creating
2228

2329
dependencies {
24-
val ktlintVersion = "1.3.0"
2530
ktlint("com.pinterest.ktlint:ktlint-cli:$ktlintVersion") {
2631
attributes {
2732
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
2833
}
34+
// Ensure that kotlin-compiler-embeddable isn't included in the buildscript classpath in consuming modules
35+
exclude(group = "org.jetbrains.kotlin", module = "kotlin-compiler-embeddable")
2936
}
3037
}
3138

build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ dependencies {
5151
attributes {
5252
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
5353
}
54+
// Ensure that kotlin-compiler-embeddable isn't included in the buildscript classpath
55+
exclude(group = "org.jetbrains.kotlin", module = "kotlin-compiler-embeddable")
5456
}
5557
ktlint(project(":ktlint-rules"))
5658
}

0 commit comments

Comments
 (0)