Skip to content

Commit

Permalink
Ensure compileOnly classpath and default ktlint runtime are kept in…
Browse files Browse the repository at this point in the history
… sync
  • Loading branch information
mateuszkwiecinski committed Sep 11, 2022
1 parent a778787 commit 2fd861d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
10 changes: 8 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ dependencies {
"ktlint-reporter-plain",
"ktlint-reporter-sarif",
"ktlint-ruleset-experimental",
"ktlint-ruleset-standard"
"ktlint-ruleset-standard",
).forEach { module ->
compileOnly("com.pinterest.ktlint:$module:${Versions.ktlint}")
testImplementation("com.pinterest.ktlint:$module:${Versions.ktlint}")
Expand All @@ -85,7 +85,13 @@ tasks {
outputs.file(propertiesFile)

doLast {
propertiesFile.writeText("version = $projectVersion")
propertiesFile.writeText(
"""
version = $projectVersion
ktlint_version = ${Versions.ktlint}
""".trimIndent(),
)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -18,5 +19,5 @@ open class KotlinterExtension {

var disabledRules = DEFAULT_DISABLED_RULES

var ktlintVersion = "0.47.1"
var ktlintVersion = versionProperties.ktlintVersion()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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"

Expand Down

0 comments on commit 2fd861d

Please sign in to comment.