LoremIpsum-42
09/25/2025, 1:07 PMdoLast { } action. As soon as I am calling a function defined in my build.gradle.kts, I am getting a CC violation. I could inline the whole code of that function, but I can't believe that is the correct solution.
How can I call such a function without triggering a violation? A sample would be, I just made the body as small as possible:
tasks.register("npmInstall2") {
doLast {
if (changeLabel()) {
println("changed")
}
}
}
fun changeLabel(): Boolean = false
Hints appreciated, thanks.Vampire
09/25/2025, 1:15 PMdoLast can call it without a reference to the script object.
Of course you need to make sure that the class and the function do not refer to anything of the script instance or the class will be non-static and thus again have a reference to the script object.LoremIpsum-42
09/25/2025, 1:27 PMcompanion object { fun( .... } does solve my immediate problem, although I have to remove the <http://logger.info|logger.info>() calls which would bring back the reference to the script object - do you have an idea how to log stuff via gradle in such a function defined in a companion class?Vampire
09/25/2025, 1:39 PMLogging.getLogger("foo").info("foo")LoremIpsum-42
09/25/2025, 1:44 PMRafael Chaves
09/25/2025, 2:09 PMTask.getLogger() (if the output should be associated with a task)Vampire
09/25/2025, 2:29 PMVampire
09/25/2025, 2:29 PMLoremIpsum-42
09/25/2025, 2:30 PM