title: How to enable Eclipselink's static weaving from Gradle
body: <p>I'd like to enable Eclipselink's static weaving for my JPA classes from Gradle. The Eclipselink docs explain how to do this in an Ant task:</p>
  
  <pre><code>&lt;target name="define.task" description="New task definition for EclipseLink static weaving"/&gt;
  
  &lt;taskdef name="weave" classname="org.eclipse.persistence.tools.weaving.jpa.StaticWeaveAntTask"/&gt;
  &lt;/target&gt;
  &lt;target name="weaving" description="perform weaving" depends="define.task"&gt;
      &lt;weave  source="c:\myjar.jar"
              target="c:\wovenmyjar.jar"
              persistenceinfo="c:\myjar-containing-persistenceinfo.jar"&gt;
          &lt;classpath&gt;
              &lt;pathelement path="c:\myjar-dependent.jar"/&gt;
          &lt;/classpath&gt;
  
      &lt;/weave&gt;
  &lt;/target&gt;
  </code></pre>
  
  <p>Now I've got 2 questions:</p>
  
  <p><strong>1. How do I 'translate' this into a Gradle approach?</strong>
  I've tried this (based on the docs at <a href="http://www.gradle.org/docs/current/userguide/ant.html#N1143F" rel="nofollow">http://www.gradle.org/docs/current/userguide/ant.html#N1143F</a>):</p>
  
  <pre><code>task eclipseWeave &lt;&lt; {
      ant.taskdef(name: "weave",
                  classname: "org.eclipse.persistence.tools.weaving.jpa.StaticWeaveAntTask",
                  classpath: configurations.compile.asPath)
  
      ant.weave(source: relativePath(compileJava.destinationDir),
                target: relativePath(compileJava.destinationDir),
                persistenceinfo: relativePath(processResources.destinationDir) {
      }
  }
  </code></pre>
  
  <p>but the problem is that the classpath doesn't seem to work within <code>ant.weave(..)</code>. The weaving process is aborted after a bit with the message:</p>
  
  <pre><code>Execution failed for task ':eclipseWeave'.
  &gt; java.lang.NoClassDefFoundError: some/class/from/my/dependencies
  </code></pre>
  
  <p>The classpath setting works for <code>ant.taskdef(..)</code> since the StaticWeaveAntTask is found in my dependencies. How can I make it apply to <code>ant.weave(..)</code> itself?</p>
  
  <p><strong>2. How do I integrate this into my build, so it is executed automatically after each <code>compileJava</code> step?</strong></p>