In a quixotic attempt to avoid duplication I've pu...
# community-support
r
In a quixotic attempt to avoid duplication I've put this in
settings.gradle.kts
, but now I'm worrying that Gradle won't know that a change to
gradle/libs.versions.toml
invalidates the plugins section of
settings.gradle.kts
. Is this a terrible idea?
Copy code
plugins {
  id("com.autonomousapps.build-health") version "2.13.0"

  val kotlinVersion = rootDir.resolve("gradle/libs.versions.toml")
    .readLines()
    .dropWhile { !it.matches("""^\h*\[\h*versions\h*\]\h*$""".toRegex()) }
    .drop(1)
    .takeWhile { !it.matches("""^\h*\[""".toRegex()) }
    .firstNotNullOf {
      """^\h*kotlin\h*=\h*"(?<version>[^"]*)"\h*$""".toRegex()
        .matchEntire(it)?.groups?.get("version")?.value
    }

  // Kotlin must be loaded in the same (or parent) class loader as the
  // Dependency Analysis Plugin. The lines below are one way to accomplish this
  id("org.jetbrains.kotlin.jvm") version kotlinVersion apply false
}
p
You could use a includedBuild instead 🤔
r
I'm fairly sure that won't work with the
com.autonomousapps.build-health
because it won't load the kotlin classes in the correct classloader, which is the reason why I'm loading the
org.jetbrains.kotlin.jvm
plugin in the
settings.gradle.kts
plugins
block.
(I have an included build for a convection plugin that actually applies the plugin)
p
Well, I can add build-health next days but it should work. Or just fork it and test it.
r
But won't that then be applying the
com.autonomousapps.build-health
plugin in individual subprojects
build
rather than as a settings plugin? I'm pretty hazy as to the difference between settings plugins and build plugins but I think they're different, and the
com.autonomousapps.build-health
plugin documentation says it should be applied as a settings plugin: https://github.com/autonomousapps/dependency-analysis-gradle-plugin/wiki/Adding-to-your-project#via-the-build-health-settings-plugin
p
You can write convention settings plugins too :)
r
OK, I'll look into that. Thanks.
p
This is what I did with the MyRepos settings plugin, that loads the included build classpath into the root settings classpath including the KGP and build-Health dependency