I have the following multiproject structure in Gradle:
- root-project
- acceptance-tests
- sub-java-proj
acceptance-tests
has a task cucumber
(provided by Gradle Cucumber-plugin) which runs the Cucumber features in the project. However, I need to do some bootstrapping before the features are run. In particular, before thecucumber
task Gradle should do the following:
- Run tests in
sub-java-proj
and if they pass produce its jar file (if not fail) - Copy the jar file from 1) into the directory
accentance-tests/proglib
- Run the Cucumber features like normal
- Delete the jar file copied in 2)
I'm completely new to Gradle so I am not sure how to properly implement this. My first thought was to make acceptance-tests
depend on sub-java-proj
(with testRuntime config), but I feel this is an abuse of the dependency mechanism: the only reason to do this is to ensure sub-java-proj
is compiled before acceptance-tests
is run, but in reality this also messes with the classpath of acceptance-tests
by adding the jar from sub-java-proj
and there's also problems with transitive dependencies. In short: acceptance-tests
should not have anything to do with sub-java-proj
besides copying it's jar around.
Suggestions on how to accomplish this are very much appreciated.
Update
So far I have the followingin acceptance-tests/build.gradle
:
task fix(dependsOn: ':sub-java-proj:jar', type: Copy) {
from tasks.getByPath(':sub-java-proj:jar')
to 'proglib'
}
task unfix(type: Delete) {
delete fix
}
cucumber.dependsOn fix
cucumber.finalizedBy unfix
However, this works except that unfix deletes the proglib
directory too. It should only delete the jar file. Any ideas how to fix this?