Skip to content

Commit caedfe6

Browse files
authored
fix: stop including embedded compiler in ktlint tasks (#82)
1 parent b864c86 commit caedfe6

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ 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
24+
exclude(group = "org.jetbrains.kotlin", module = "kotlin-compiler-embeddable")
25+
}
26+
2327
implementation(libs.nexusPublishPlugin)
2428
compileOnly(gradleApi())
2529
implementation("aws.sdk.kotlin:s3:1.1.+")
@@ -36,7 +40,26 @@ gradlePlugin {
3640
}
3741
}
3842

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

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,23 @@ 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 {
27-
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
32+
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.SHADOWED))
2833
}
2934
}
3035
}
3136

32-
// add the buildscript classpath which should pickup our custom ktlint-rules (via runtimeOnly dep on this plugin)
37+
// add the buildscript classpath which should pick up our custom ktlint-rules (via runtimeOnly dep on this plugin)
3338
// plus any custom rules added by consumer
3439
val execKtlintClasspath = ktlint + buildscript.configurations.getByName("classpath")
3540

build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ val ktlint by configurations.creating
4949
dependencies {
5050
ktlint(libs.ktlint.cli) {
5151
attributes {
52-
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
52+
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.SHADOWED))
5353
}
5454
}
55+
5556
ktlint(project(":ktlint-rules"))
5657
}
5758

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[versions]
2-
ktlint = "1.5.0"
2+
ktlint = "1.3.0"
33
smithy-version = "1.53.0"
44
smithy-gradle-plugin-version = "1.1.0"
55
junit-version = "5.10.1"
@@ -16,4 +16,4 @@ smithy-gradle-base-plugin = { module = "software.amazon.smithy.gradle:smithy-bas
1616
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-version" }
1717

1818
[plugins]
19-
plugin-publish = { id = "com.gradle.plugin-publish", version = "1.2.1"}
19+
plugin-publish = { id = "com.gradle.plugin-publish", version = "1.2.1"}

0 commit comments

Comments
 (0)