title: Gradle: how to copy subproject jar to another subproject when task is run?
body: <p>I have the following multiproject structure in Gradle:</p>
  
  <pre><code>- root-project
    - acceptance-tests
    - sub-java-proj
  </code></pre>
  
  <p><code>acceptance-tests</code> has a task <code>cucumber</code> (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 the<code>cucumber</code> task Gradle should do the following:</p>
  
  <ol>
  <li>Run tests in <code>sub-java-proj</code> and if they pass produce its jar file (if not fail)</li>
  <li>Copy the jar file from 1) into the directory <code>accentance-tests/proglib</code></li>
  <li>Run the Cucumber features like normal</li>
  <li>Delete the jar file copied in 2)</li>
  </ol>
  
  <p>I'm completely new to Gradle so I am not sure how to properly implement this. My first thought was to make <code>acceptance-tests</code> depend on <code>sub-java-proj</code> (with testRuntime config), but I feel this is an abuse of the dependency mechanism: the only reason to do this is to ensure <code>sub-java-proj</code> is compiled before <code>acceptance-tests</code> is run, but in reality this also messes with the classpath of <code>acceptance-tests</code> by adding the jar from <code>sub-java-proj</code> and there's also problems with transitive dependencies. In short: <code>acceptance-tests</code> should not have <em>anything</em> to do with <code>sub-java-proj</code> besides copying it's jar around.</p>
  
  <p>Suggestions on how to accomplish this are very much appreciated.</p>
  
  <h3>Update</h3>
  
  <p>So far I have the followingin <code>acceptance-tests/build.gradle</code>:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>However, this works except that unfix deletes the <code>proglib</code> directory too. It should only delete the jar file. Any ideas how to fix this?</p>