Gradle: how to copy a subproject to another subproject when performing a task?

I have the following multi-project structure in Gradle:

- root-project
  - acceptance-tests
  - sub-java-proj

acceptance-testshas a task cucumber(provided by the Gradle Cucumber-plugin) that runs the Cucumber functions in the project. However, before the functions are launched, I need to do some reboot. In particular, the cucumberfollowing should be done before the Gradle task :

  • Run the tests in sub-java-projand if they pass the file to its jar file (if not crashing)
  • Copy the jar file from 1) to the directory accentance-tests/proglib
  • Run the Cucumber functions as usual.
  • Delete jar file copied to 2)

I am completely new to Gradle, so I'm not sure how to implement this correctly. My first thought was to make it acceptance-testsdependent on sub-java-proj(with the testRuntime configuration), but I believe that this is an abuse of the dependency mechanism: the only reason for this is to ensure that it sub-java-projcompiles to acceptance-tests, but it actually also contradicts the class path by acceptance-testsadding jar of sub-java-proj, as well as problems with transitive dependencies. In short: acceptance-testsshould not have anything to do with sub-java-proj, except to copy it around.

Suggestions on how to do this are greatly appreciated.

Update

So far, I have the following in 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

, , unfix proglib. jar. , ?

+3

All Articles