Domanda

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
È stato utile?

Soluzione

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.

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top