Slackbot
03/09/2022, 3:34 PMThomas Broyer
03/09/2022, 3:47 PMTest
task, not identical but it makes it clearer that it will reset/clear some configuration and not just change a property value)Vampire
03/09/2022, 4:00 PMafterEvaluate
would not be too late to add dependencies or apply plugins. But everytime you use afterEvaluate
you create new race conditions as you then depend on ordering and for example don't see changes done in afterEvaluate
blocks done after your afterEvaluate
block.
And as Thomas correctly said, imho using a method in the extension is the best way, as there is not way to react to properties being set currently. You can either have a method like useSetupX()
or also with parameters that then does what you need, or you can have something like a doThings(Action<SubExtension>)
so that you then can have
myExtension {
doThings {
subExtensionsPropertyA.set(1)
subExtensionsPropertyB.set(1)
}
}
and then in the doThings
before executing the action you could check it was not already configured and after executing the action you can derive your logic from it.
Whichever way you prefer.Justin Breitfeller
03/10/2022, 2:04 PMJustin Breitfeller
03/10/2022, 2:05 PMVampire
03/10/2022, 3:54 PMbeforeResolve
where you add the default dependencies if nothing was configured in the extension.
Or maybe even better you create a new (possibly hidden) configuration where you define default dependencies to be the default ones and if the method is called add non-default dependencies, this way the defaults are only used if no were set explicitly.Justin Breitfeller
03/10/2022, 4:14 PMbeforeResolve
. I suppose that happens post configuration but before tasks are evaluated.Vampire
03/10/2022, 6:15 PMJendrik Johannes
03/12/2022, 1:43 PMplugins {
id("my-java-project-with-junit")
}
Or
plugins {
id("my-java-project-with-testng")
}
Option 2: Let the users “stack” convention plugins
plugins {
id("my-java-project") // JUnit is the default here
}
Or
plugins {
id("my-java-project")
id("my-extra-testng") // Switches to things TestNG
}
I recently strictly use Option 1 several projects which gives you all the control in the plugins and makes it easy to use/understand for the developers as you have a limited set of predefined combinations. If the number of combinations explodes, Option 2 might be better though.
If you feel that you need extensions, I would also do what was proposed above - offer methods on the extensions - like your own myExtension.useTestNG()
which then directly modifies the declared dependencies (and whatever else you want to configure).Justin Breitfeller
03/15/2022, 2:54 PMVampire
03/15/2022, 3:05 PMtestImplementation
or whatever you would have added them otherwise extend your new configuration.Jendrik Johannes
03/15/2022, 6:52 PMtestImplementation
directly is another one.
I think in this case I would probably add the junit dependency directly to testImplementation
in the my-java-project
.
And then in the the my-extra-testng
I would replace/remove the junit dependency again. I would also make my-extra-testng
apply my-java-project
in its plugins block so the order is always clear.Justin Breitfeller
03/15/2022, 7:59 PMVampire
03/15/2022, 8:00 PMJustin Breitfeller
03/25/2022, 2:00 PM