Static weaving with EclipseLink broken with Gradle 4.2.1


(george thomas) #1

A project I am working on uses EclipseLink and the build performs static weaving on compiled classes. The idiom we employ looks like the snippet in this answer on Stack Overflow. This works fine up till Gradle 4.1. Once we upgrade the wrapper to 4.2.1, however, the weaving fails with the following error:

:compileJavaException in thread "main" Local Exception Stack:
Exception [EclipseLink-40007] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.StaticWeaveException
Exception Description: An exception was thrown while weaving: [Ljava.lang.String;@34c45dca
Internal Exception: Exception [EclipseLink-40002] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.StaticWeaveException
Exception Description: No source was specified for weaving
        at org.eclipse.persistence.exceptions.StaticWeaveException.exceptionPerformWeaving(StaticWeaveException.java:138)
        at org.eclipse.persistence.tools.weaving.jpa.StaticWeave.main(StaticWeave.java:86)
Caused by: Exception [EclipseLink-40002] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.StaticWeaveException
Exception Description: No source was specified for weaving
        at org.eclipse.persistence.exceptions.StaticWeaveException.missingSource(StaticWeaveException.java:89)
        at org.eclipse.persistence.tools.weaving.jpa.StaticWeaveProcessor.preProcess(StaticWeaveProcessor.java:190)
        at org.eclipse.persistence.tools.weaving.jpa.StaticWeaveProcessor.performWeaving(StaticWeaveProcessor.java:172)
        at org.eclipse.persistence.tools.weaving.jpa.StaticWeave.start(StaticWeave.java:115)
        at org.eclipse.persistence.tools.weaving.jpa.StaticWeave.main(StaticWeave.java:84)
 FAILED

Running the build with --info gave me some more information and I saw that org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter was deleting the directory containing the output of the compiler, before the weaving began. This explained why the weaver could not find any source files.

I found this issue, which led me this commit via the linked pull request.

I was able to reproduce this problem with a simple standalone project.

Is this an expected change in behavior across minor releases or is this a bug?


(Stefan Oehme) #2

The linked snippet is broken, it calls execute on another task. That is always wrong and will be an error in future Gradle versions.

Please use Project.javaExec to call Java tools imperatively. If that doesn’t fix the issue, then I’d consider it a bug. Please report it on GitHub in that case.


(george thomas) #3

Thanks @st_oehme. I had read about the use of execute being a smell. I refactored the snippet to use Project.javaexec instead and things work fine. I have dropped a comment to the answer on Stack Overflow as well.

A pointer to some place in the official documentation that discourages the use of execute would be much appreciated.


(James Justinic) #4

It’s not just that using this method is discouraged, but as far as the official documentation is concerned, this method doesn’t exist. The official documentation covers the public API. You shouldn’t expect to find references to specific undocumented internals discouraging their use as you’re not supposed to even be aware of these internals as a user. You’re discouraged from using anything that is not in the documented public API.


(george thomas) #5

Thanks @jjustinic. That makes sense. This snippet was the first time I had seen execute being used and I had just assumed that it was one of the many things about Gradle that I didn’t know about :slight_smile:

As for my problem, I ended up refactoring the block even further, because directly using Project.javaexec made the script vulnerable to the limitations of CreateProcess on Windows. I switched to using the EclipseLink weave Ant Task, which also made the build faster :slight_smile: