Is there a way I can get the detekt plugin version...
# detekt
e
Is there a way I can get the detekt plugin version inside another custom task? I’m trying to abstract away some behavior that’s in each of our projects. We download the detekt config from a central location (artifactory) and have a file there for every version, like
detekt-config-1.15.yml
and
detekt-config-1.19.yml
etc. I’d like my task to just discover the version of detekt and built the URL automatically. I can do something like
Copy code
project.extensions.findByName("io.gitlab.arturbosch.detekt")
to find the plugin, but then how can I introspect that to find the version?
Maybe this?
Copy code
val detektPlugin = project.extensions.findByName("detekt") as CodeQualityExtension
val version = detektPlugin.toolVersion
that’s actually
null
😞
both of these work:
Copy code
val version = project.configurations.getByName(CONFIGURATION_DETEKT).dependencies.first { it.group == "io.gitlab.arturbosch.detekt" }.version!!
and
Copy code
val version = Properties().run {
    DetektPlugin::class.java.classLoader.getResourceAsStream("versions.properties").bufferedReader()
        .let { load(it) }
    getProperty("detektVersion")
}