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:
<target name="define.task" description="New task definition for EclipseLink static weaving"/>
<taskdef name="weave" classname="org.eclipse.persistence.tools.weaving.jpa.StaticWeaveAntTask"/>
</target>
<target name="weaving" description="perform weaving" depends="define.task">
<weave source="c:\myjar.jar"
target="c:\wovenmyjar.jar"
persistenceinfo="c:\myjar-containing-persistenceinfo.jar">
<classpath>
<pathelement path="c:\myjar-dependent.jar"/>
</classpath>
</weave>
</target>
Now I've got 2 questions:
1. How do I 'translate' this into a Gradle approach? I've tried this (based on the docs at http://www.gradle.org/docs/current/userguide/ant.html#N1143F):
task eclipseWeave << {
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) {
}
}
but the problem is that the classpath doesn't seem to work within ant.weave(..)
. The weaving process is aborted after a bit with the message:
Execution failed for task ':eclipseWeave'.
> java.lang.NoClassDefFoundError: some/class/from/my/dependencies
The classpath setting works for ant.taskdef(..)
since the StaticWeaveAntTask is found in my dependencies. How can I make it apply to ant.weave(..)
itself?
2. How do I integrate this into my build, so it is executed automatically after each compileJava
step?
I know this is an old question, but based on the OP's comment for the "gradle" way to do it, I thought I'd share our approach. We are using the JavaExec task and the various available configuration objects.
Since the weaving is done in the classes directory (before the JAR is built) you end up only having to build one jar, not two. Since our jar is quite large, that was important to us.
task performJPAWeaving(type: JavaExec, dependsOn: "compileJava"){
inputs.dir compileJava.destinationDir
outputs.dir compileJava.destinationDir
main "org.eclipse.persistence.tools.weaving.jpa.StaticWeave"
args "-persistenceinfo",
"src/main/resources",
compileJava.destinationDir.getAbsolutePath()
classpath = configurations.compileClasspath
}
tasks.withType(Jar){
dependsOn "performJPAWeaving"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With