2

This question is related to Conflicting versions of datanucleus enhancer in a maven google app engine project. I tried the solution there and it works. But if I run mvn clean compile I get the error

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project XXX: Fatal error compiling: java.lang.NoClassDefFoundError: org/datanucleus/util/AnnotationProcessorUtils: org.datanucleus.util.AnnotationProcessorUtils.

Any idea why? I'm using datanucleus-maven-plugin:3.3.0-release.

The problem is that I have the datanucleus-core twice: one from project dependencies and one from plugin dependencies. In the console after running mvn datanuleus:enhance the following line appears twice:

[INFO] CP: /home/user/.m2/repository/org/datanucleus/datanucleus-core/3.2.7/datanucleus-cor‌​e-3.2.7.jar
Community
  • 1
  • 1
Adrian Ber
  • 20,474
  • 12
  • 67
  • 117

2 Answers2

4

I finally found a workaround for this. It's not the most elegant solution, but I don't think there's another one.

The workaround was to add the datanucleus-core dependency to the compiler plugin (please note the compile scope.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <dependencies>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-core</artifactId>
            <version>3.2.8</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
    ...
</plugin>

The datanucleus-core dependency is added with the runtime scope

<dependency>
    <groupId>org.datanucleus</groupId>
    <artifactId>datanucleus-core</artifactId>
    <version>3.2.8</version>
    <scope>runtime</scope>
</dependency>

And the datanucleus-core default version from the datanucleus enhancer plugin is overridden with 3.2.8.

<plugin>
    <groupId>org.datanucleus</groupId>
    <artifactId>datanucleus-maven-plugin</artifactId>
    <version>3.3.0-release</version>
    <dependencies>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-core</artifactId>
            <version>3.2.8</version>
        </dependency>
    </dependencies>
</plugin>

It works for version 3.2.9 too.

Adrian Ber
  • 20,474
  • 12
  • 67
  • 117
0

Setting datanucleus-core to runtime means you aren't needing it for compile (what the user in that thread needed). You obviously want to run (DataNucleus) annotation processors (pre-compile) so have to have that present for compile, so you set the version of datanucleus-core used by the datanucleus-maven-plugin instead (under its dependency for the plugin), so it matches what is used by the overall pom.xml

DataNucleus
  • 15,497
  • 3
  • 32
  • 37
  • I have the same version in dependencies and plugin dependencies. The problem is that I have the datanucleus-core twice: one from project dependencies and one from plugin dependencies. In the console after running `mvn datanuleus:enhance` the following line appears twice: `[INFO] CP: /home/user/.m2/repository/org/datanucleus/datanucleus-core/3.2.7/datanucleus-core-3.2.7.jar` – Adrian Ber Nov 02 '13 at 00:13
  • All of my projects have datanucleus-core in the pom.xml deps, and I use the M2 enhancer plugin too, so have the same. Why you have it twice you can determine by using "mvn --debug" and see what it says as to the origin of those two entries – DataNucleus Nov 03 '13 at 16:56
  • I have it once from the plugin dependencies itself (I overwrite the version there) and I have it once from the project dependencies. – Adrian Ber Nov 20 '13 at 01:01