requirement:
In selected Gradle sub-projects, we want to reuse environment variable definitions for run
, debug
, test
etc. tasks. For example, I thought the following would be the natural(??) way to go about things:
myproj.gradle
test.dependsOn defineEnvironement( mainClass )
test.doFirst() {
workingDir = "${testFolder}";
}
run.dependsOn defineEnvironement( mainClass )
run.doFirst() {
workingDir = "${runFolder}";
}
And where the defineEnvironment()
task is declared in the common.gradle
or the root project, something like ...
common.gradle
task defineEnvironement( type : JavaExec ) {
println "--> defineEnvironementVariables()"
environment "PROG_HOME", "${RUN_PATH}";
environment "PROG_CONFIG_PATH", "${RUN_PATH}/${cfgFolder}";
:
}
question(s) ...
However that doesn't work at the moment. There are various complaints about my "method signature" for the class. Depending on what variations I run through for the
gradle myproj:test
... command. I have moved that snipped around and used different approaches such as calling it via doFirst()
and looking at different recepies from the web and stackoverflow. Roughly this approach follows the steps from:
Early alternatives rejected a 'method' becaue there is no environment in context -- Which makes sense, the run
task must be an Exec
typ. In I think the key questions here are ...
How do I pass-on the
test
andrun
tasks to thedefineEnvironement
task?And of course, it this the common (best?) practice approach?
If not, what is the prefered method to reuse the
defineEnvironement
steps and only need to specify and update them in one place?
I apologise it this is a bit basic. I would think this kind of thing is what most projects (would like to) do in general by sharing common definitions/build code.