Gábor Török
04/21/2025, 9:11 PMJavaExec
tasks by presetting some properties like system properties, env properties, classpath, etc, and i am wondering what's the best way for for it would be. these values need to be different based on which environment we want to run in.
i have come up with something like this:
abstract class ExecInStaging : JavaExec() {
init {
systemProperty("appconfig", "config/staging.properties")
systemProperty("log4j.configurationFile", "log4j2-local.xml")
environment("CONSUL_HOST", STAGING_CONSUL)
classpath = project.extensions
.getByType<JavaPluginExtension>()
.sourceSets
.getByName("main")
.runtimeClasspath
}
}
this works - but i am wondering if there are some best practices around this that i am missing? doing all this configuration in the constructor feels a bit weird - especially since now i am getting a bunch of IDE warnings due to Calling non-final function {} in constructor
...
is there a better way to do this?Philip W
04/21/2025, 11:55 PMVampire
04/22/2025, 6:59 AMThomas Broyer
04/22/2025, 12:43 PMJavaExec
, I'd rather make it a DefaultTask
with an injected `ExecOperations`.Gábor Török
04/22/2025, 1:59 PM