Slackbot
07/31/2022, 7:40 PMMartin
07/31/2022, 7:41 PMafterEvaluate{}
could have its own documentation page after all this time 😅Eli Graber
07/31/2022, 7:42 PMclass MyKgpPlugin : Plugin<Project> {
override fun apply(target: Project) {
val ext = target.extensions.create("myExtension", MyExtension::class.java)
// configure KGP; should this be wrapped in afterEvaluate
}
}
Martin
07/31/2022, 7:43 PMplugins.withId("org.jetbrains.kotlin.jvm"){}
Martin
07/31/2022, 7:43 PMEli Graber
07/31/2022, 7:44 PMMartin
07/31/2022, 7:44 PMMartin
07/31/2022, 7:45 PMafterEvaluate{}
is when other plugins were using afterEvaluate{}
and I needed to override them somehowEli Graber
07/31/2022, 7:45 PMEli Graber
07/31/2022, 7:46 PMMartin
07/31/2022, 7:47 PMoverride fun apply(target: Settings) {
val ext = target.extensions.create("githubPackagesPluginManagementRepo", Extension::class.java)
val password = ext.password
if(password == null) {
require(ext.ejsonSecretsFile.isPresent) {
"ejsonSecretsFile must be set"
}
Martin
07/31/2022, 7:48 PMMartin
07/31/2022, 7:48 PM@TaskAction
method)Eli Graber
07/31/2022, 7:49 PMextensions.create
doesn't mean that the configuration block was called, so the values in the extension object aren't set it (and will always be the default from the plugin's perspective)Martin
07/31/2022, 7:50 PMMartin
07/31/2022, 7:51 PMMartin
07/31/2022, 7:51 PMEli Graber
07/31/2022, 7:53 PMafterEvaluate
Hence the problemMartin
07/31/2022, 7:55 PMVampire
07/31/2022, 7:58 PMmyExtension {
configuration {
a = "b"
}
}
grossws
07/31/2022, 7:58 PMAction
)..Eli Graber
07/31/2022, 7:58 PMgrossws
07/31/2022, 8:00 PMexecute
. Also you can check the configuration after that call (e.g. for inconsistencies)Eli Graber
07/31/2022, 8:01 PMMartin
07/31/2022, 8:04 PMplugins {
id("com.example")
}
// no configuration at all but I still want to register tasks based on default values
vs
plugins {
id("com.example")
}
// explicit configuration. Use these values to register tasks
myExtension {
configuration {
// some stuff
}
}
grossws
07/31/2022, 8:04 PMMartin
07/31/2022, 8:06 PMconfiguration
Action called at all?grossws
07/31/2022, 8:10 PMconfiguration
or notMartin
07/31/2022, 8:14 PMconfiguration
. That's more noise in the ./gradlew tasks --all
output, etc...Eli Graber
07/31/2022, 8:15 PMgrossws
07/31/2022, 8:20 PMgrossws
07/31/2022, 8:24 PMEli Graber
07/31/2022, 9:03 PMEli Graber
07/31/2022, 9:26 PMafterEvaluate
is OK in cases where you're not reading from anywhere but your own extension?Vampire
07/31/2022, 9:27 PMEli Graber
07/31/2022, 9:28 PMafterEvaluate
?Eli Graber
07/31/2022, 9:30 PMafterEvaluate
that is run after mine does?
In this specific case I wouldn't be too worried about that, because it is for internal use only. But I guess it could become a concern if this project grew, and someone ended up using the extension improperly.Vampire
07/31/2022, 9:32 PMBut wouldn't that happen anyways, even if I didn't use afterEvaluate?
Sure, but if you don't use
afterEvaluate
but either evaluate late in execution phase, or reactive like on function call, that will work properly. If you use afterEvaluate
you depend on order of those calls. You could prevent further configuration after you evaluated the values to prevent sneaky bugs, but best is still to avoid afterEvaluate
wherever possibleVampire
07/31/2022, 9:34 PMOh are you saying that someone can set the values on my extension in an afterEvaluate that is run after mine does?
Exactly
In this specific case I wouldn't be too worried about that, because it is for internal use only. But I guess it could become a concern if this project grew, and someone ended up using the extension improperly.
Well, I usually try to do it right right away, so that debts don't cumulate. But sure, if all is internal you might maybe get away with it. :-)
Eli Graber
07/31/2022, 9:35 PMafterEvaluate
😅Vampire
07/31/2022, 9:36 PM