I am developing a convention plugin for Detekt. I ...
# plugin-development
l
I am developing a convention plugin for Detekt. I was wondering if I could access the version defined in buildSrc/build.gradle.kts? Detekt has two places where I need to define the version. • One in buildSrc/build.gradle.kts
Copy code
dependencies {
    implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:[version]")
}
• One in my convention plugin in buildSrc/src/main/kotlin/detekt-conventions.gradle.kts
Copy code
dependencies {
    detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:[version]")
}
Is there a way to define a constant somewhere that I can reuse to simplify updates? (Note that my version of Gradle doesn't support version catalogs) Or a way to get the version from the other place?
e
you could do something like
Copy code
Detekt::class.java.getResourceAsStream("/detekt-versions.properties").use { Properties().apply { load(it) } }.getProperty("detektVersion")
since Detekt happens to ship a resource inside their JAR that contains its own version info. I'm not sure it's worth depending on their internals to save you from having two constants to update though.