From b1cf070019bdc7f41c06e807525286b662c057f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Kwiecin=CC=81ski?= Date: Sun, 11 Sep 2022 14:22:55 +0200 Subject: [PATCH] Ensure `compileOnly` classpath and default ktlint runtime are kept in sync --- build.gradle.kts | 8 +++++++- .../org/jmailen/gradle/kotlinter/KotlinterExtension.kt | 3 ++- .../jmailen/gradle/kotlinter/support/VersionProperties.kt | 8 ++++++-- .../org/jmailen/gradle/kotlinter/tasks/GitHookTasks.kt | 6 ++---- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 6347a256..fcfddd54 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -87,7 +87,13 @@ tasks { outputs.file(propertiesFile) doLast { - propertiesFile.writeText("version = $projectVersion") + propertiesFile.writeText( + """ + version = $projectVersion + ktlint_version = ${Versions.ktlint} + + """.trimIndent() + ) } } diff --git a/src/main/kotlin/org/jmailen/gradle/kotlinter/KotlinterExtension.kt b/src/main/kotlin/org/jmailen/gradle/kotlinter/KotlinterExtension.kt index 20d27ea2..499bf257 100644 --- a/src/main/kotlin/org/jmailen/gradle/kotlinter/KotlinterExtension.kt +++ b/src/main/kotlin/org/jmailen/gradle/kotlinter/KotlinterExtension.kt @@ -1,6 +1,7 @@ package org.jmailen.gradle.kotlinter import org.jmailen.gradle.kotlinter.support.ReporterType +import org.jmailen.gradle.kotlinter.support.versionProperties open class KotlinterExtension { companion object { @@ -18,5 +19,5 @@ open class KotlinterExtension { var disabledRules = DEFAULT_DISABLED_RULES - var ktlintVersion = "0.47.1" + var ktlintVersion = versionProperties.ktlintVersion() } diff --git a/src/main/kotlin/org/jmailen/gradle/kotlinter/support/VersionProperties.kt b/src/main/kotlin/org/jmailen/gradle/kotlinter/support/VersionProperties.kt index ad42a6e3..1da20ae1 100644 --- a/src/main/kotlin/org/jmailen/gradle/kotlinter/support/VersionProperties.kt +++ b/src/main/kotlin/org/jmailen/gradle/kotlinter/support/VersionProperties.kt @@ -2,10 +2,14 @@ package org.jmailen.gradle.kotlinter.support import java.util.Properties -class VersionProperties : Properties() { +internal val versionProperties by lazy(::VersionProperties) + +internal class VersionProperties : Properties() { init { load(this.javaClass.getResourceAsStream("/version.properties")) } - fun version(): String = getProperty("version") + fun kotlinterVersion(): String = getProperty("version") + + fun ktlintVersion(): String = getProperty("ktlint_version") } diff --git a/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/GitHookTasks.kt b/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/GitHookTasks.kt index d7293210..56a16e30 100644 --- a/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/GitHookTasks.kt +++ b/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/GitHookTasks.kt @@ -5,7 +5,7 @@ import org.gradle.api.provider.Property import org.gradle.api.tasks.Input import org.gradle.api.tasks.Internal import org.gradle.api.tasks.TaskAction -import org.jmailen.gradle.kotlinter.support.VersionProperties +import org.jmailen.gradle.kotlinter.support.versionProperties import java.io.File abstract class InstallPreCommitHookTask : InstallHookTask("pre-commit") { @@ -111,11 +111,9 @@ abstract class InstallHookTask(@get:Internal val hookFileName: String) : Default } companion object { - private val version = VersionProperties().version() - internal const val startHook = "\n##### KOTLINTER HOOK START #####" - internal val hookVersion = "##### KOTLINTER $version #####" + internal val hookVersion = "##### KOTLINTER ${versionProperties.kotlinterVersion()} #####" internal const val endHook = "##### KOTLINTER HOOK END #####\n"