Skip to content
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
25 changes: 24 additions & 1 deletion build-plugins/build-support/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ repositories {

dependencies {
// make our custom lint rules available to the buildscript classpath
runtimeOnly(project(":ktlint-rules"))
runtimeOnly(project(":ktlint-rules")) {
// Ensure that kotlin-compiler-embeddable isn't included in the buildscript classpath
exclude(group = "org.jetbrains.kotlin", module = "kotlin-compiler-embeddable")
}

implementation(libs.nexusPublishPlugin)
compileOnly(gradleApi())
implementation("aws.sdk.kotlin:s3:1.1.+")
Expand All @@ -36,7 +40,26 @@ gradlePlugin {
}
}

val generateKtlintVersion by tasks.registering {
// generate the version of the runtime to use as a resource.
// this keeps us from having to manually change version numbers in multiple places
val resourcesDir = layout.buildDirectory.dir("resources/main/aws/sdk/kotlin/gradle/dsl").get()

val versionCatalog = rootProject.file("gradle/libs.versions.toml")
inputs.file(versionCatalog)

val versionFile = file("$resourcesDir/ktlint-version.txt")
outputs.file(versionFile)

val version = libs.ktlint.cli.ruleset.core.get().version
sourceSets.main.get().output.dir(resourcesDir)
doLast {
versionFile.writeText("$version")
}
}

tasks.withType<KotlinCompile> {
dependsOn(generateKtlintVersion)
compilerOptions {
jvmTarget.set(JvmTarget.JVM_1_8)
freeCompilerArgs.add("-opt-in=kotlin.RequiresOptIn")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,23 @@ import org.gradle.language.base.plugins.LifecycleBasePlugin
fun Project.configureLinting(lintPaths: List<String>) {
verifyRootProject { "Kotlin SDK lint configuration is expected to be configured on the root project" }

val ktlintVersion = object {} // Can't use Project.javaClass because that's using the Gradle classloader
.javaClass
.getResource("ktlint-version.txt")
?.readText()
?: error("Missing ktlint-version.txt")

val ktlint by configurations.creating

dependencies {
val ktlintVersion = "1.3.0"
ktlint("com.pinterest.ktlint:ktlint-cli:$ktlintVersion") {
attributes {
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.SHADOWED))
}
}
}

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

Expand Down
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ val ktlint by configurations.creating
dependencies {
ktlint(libs.ktlint.cli) {
attributes {
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.SHADOWED))
}
}

ktlint(project(":ktlint-rules"))
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
ktlint = "1.5.0"
ktlint = "1.3.0"
Copy link
Member

Choose a reason for hiding this comment

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

Do we really have to downgrade our ktlint version to get this fix? If so, could we open an issue to Ktlint to fix this problem, so we are unblocked for future upgrades?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The downgrade is to match the version we were previously setting explicitly in configureLinting. In that sense, it's only a downgrade for aws-kotlin-repo-tools which was previously using 1.5.0.

The 1.5.0 version actually isn't relevant to the compiler warning. The same warning happened whether we used 1.3.0 or 1.5.0. The actual problem was using the non-shadowed ktlint-cli variant.

smithy-version = "1.53.0"
smithy-gradle-plugin-version = "1.1.0"
junit-version = "5.10.1"
Expand All @@ -16,4 +16,4 @@ smithy-gradle-base-plugin = { module = "software.amazon.smithy.gradle:smithy-bas
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-version" }

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