diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 72ba7978..de9b34be 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -14,6 +14,7 @@ mavencentral-jgit = "7.0.0.202409031743-r" mavencentral-ktlint-gradle = "0.10.0" maven-binarycompatiblity = "0.16.3" maven-dokka = "1.9.20" +maven-ktlint = "1.4.1" [libraries] agp-gradle-implementation = { module = "com.android.tools.build:gradle", version.ref = "google-agp" } # TODO remove @@ -28,6 +29,7 @@ junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "mav assertj-core = { module = "org.assertj:assertj-core", version.ref = "mavencentral-assertj" } eclipse-jgit = { module = "org.eclipse.jgit:org.eclipse.jgit", version.ref = "mavencentral-jgit" } jetbrains-dokka = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "maven-dokka" } +ktlint-cli = { module = "com.pinterest.ktlint:ktlint-cli", version.ref = "maven-ktlint" } [plugins] kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "mavencentral-kotlin" } diff --git a/quality/build.gradle b/quality/build.gradle index 027f8990..069597e5 100644 --- a/quality/build.gradle +++ b/quality/build.gradle @@ -25,6 +25,21 @@ tasks.named("test") { useJUnitPlatform() } +tasks.register("generateVersionProperties", WriteProperties) { writeProps -> + def propertiesFile = new File(sourceSets.main.output.resourcesDir, "starter-quality-gradle-plugin.properties") + if (GradleVersion.current() >= GradleVersion.version("8.1")) { + writeProps.destinationFile = propertiesFile + } else { + //noinspection GrDeprecatedAPIUsage + writeProps.outputFile = propertiesFile + } + writeProps.property("ktlint_version", libs.versions.maven.ktlint) +} + +tasks.named("processResources") { + dependsOn("generateVersionProperties") +} + gradlePlugin { plugins { quality { diff --git a/quality/src/main/kotlin/com/project/starter/quality/internal/Ktlint.kt b/quality/src/main/kotlin/com/project/starter/quality/internal/Ktlint.kt index 6a76480c..46f2ad03 100644 --- a/quality/src/main/kotlin/com/project/starter/quality/internal/Ktlint.kt +++ b/quality/src/main/kotlin/com/project/starter/quality/internal/Ktlint.kt @@ -9,8 +9,8 @@ internal fun Project.configureKtlint() { pluginManager.apply(KtlintGradlePlugin::class.java) extensions.configure(KtlintGradleExtension::class.java) { - experimentalRules.set(true) - disabledRules.set( + experimentalRules.convention(true) + disabledRules.convention( disabledRules.get() + listOf( "import-ordering", "filename", @@ -18,6 +18,7 @@ internal fun Project.configureKtlint() { "experimental:property-naming", ), ) + ktlintVersion.convention(versionProperties.ktlintVersion()) } tasks.named(ProjectCodeStyleTask.TASK_NAME) { diff --git a/quality/src/main/kotlin/com/project/starter/quality/internal/VersionProperties.kt b/quality/src/main/kotlin/com/project/starter/quality/internal/VersionProperties.kt new file mode 100644 index 00000000..6107fcc0 --- /dev/null +++ b/quality/src/main/kotlin/com/project/starter/quality/internal/VersionProperties.kt @@ -0,0 +1,13 @@ +package com.project.starter.quality.internal + +import java.util.Properties + +internal val versionProperties by lazy(::VersionProperties) + +internal class VersionProperties : Properties() { + init { + load(this.javaClass.getResourceAsStream("/starter-quality-gradle-plugin.properties")) + } + + fun ktlintVersion(): String = getProperty("ktlint_version") +} diff --git a/quality/src/test/kotlin/com/project/starter/quality/QualityPluginTest.kt b/quality/src/test/kotlin/com/project/starter/quality/QualityPluginTest.kt index 360e87b0..32334d5d 100644 --- a/quality/src/test/kotlin/com/project/starter/quality/QualityPluginTest.kt +++ b/quality/src/test/kotlin/com/project/starter/quality/QualityPluginTest.kt @@ -30,7 +30,7 @@ internal class QualityPluginTest : WithGradleProjectTest() { options.release.set(targetJavaVersion.majorVersion.toInteger()) } tasks.withType(KotlinCompile).configureEach { - compilerOptions.jvmTarget = JvmTarget.@Companion.fromTarget(targetJavaVersion.toString()) + compilerOptions.jvmTarget = JvmTarget.fromTarget(targetJavaVersion.toString()) } repositories.mavenCentral()