Nick Kleban
11/21/2023, 9:03 AMbuild-logic
(included build) inside app/build.gradle.kts
in the plugins { }
block?
I have function that looks like
fun isCI() = System.getenv("GITLAB_CI").toBoolean()
And I can use it in the app/build.gradle.kts
everywhere except plugins
block where I get “Unresolved reference” error
plugins {
alias(libs.plugins...) apply isCI()
}
Vampire
11/21/2023, 9:07 AMplugins { ... }
block is extracted and evaluated separately, there your build logic is not yet available. That block actually depends on your plugin and thus adds it to the class path, so you cannot use things inside due to hen-and-egg problem.Nick Kleban
11/21/2023, 9:13 AMbuild-logic
that wraps original plugin and makes this check and apply inside but maybe there is some better approach.ephemient
11/21/2023, 9:15 AMephemient
11/21/2023, 9:16 AMisCI()
check down into task.onlyIf {}
etc.Nick Kleban
11/21/2023, 9:29 AMassemble
task finalizedBy
block implicitly and the only way around it is either disable the plugin or remove\disable tasks added by the plugin. First way seems better to me as I don’t need to know anything about plugin internals.mbonnin
11/21/2023, 9:50 AMplugins {}
block without applying it:
plugins {
id("com.example").apply(false)
}
And then apply it in your build script
if (isCI()) {
plugins.apply("com.example")
}
mbonnin
11/21/2023, 9:51 AMVampire
11/21/2023, 10:04 AMmbonnin
11/21/2023, 10:05 AMmbonnin
11/21/2023, 10:06 AMVampire
11/21/2023, 10:08 AMVampire
11/21/2023, 10:08 AMmbonnin
11/21/2023, 10:08 AMmbonnin
11/21/2023, 10:09 AMSystem.getenv("CI")
is always the same value, CC can be reusedNick Kleban
11/21/2023, 10:09 AMmbonnin
11/21/2023, 10:09 AMVampire
11/21/2023, 10:10 AMbut cc will work the same locally without the plugin applied, right?Sure, I just meant that you can do without having different builds on CI and locally which is always potential for differences and thus f***up - if not now then in the future - when everything you want is local speed and making the build use CC locally is enough.
mbonnin
11/21/2023, 10:10 AMmbonnin
11/21/2023, 10:11 AMVampire
11/21/2023, 10:13 AMNick Kleban
11/21/2023, 10:14 AM