20

I'm having a problem setting up datanucleus enhancer to use with a google app engine project. If I use the datanucleus eclipse plugin everything goes well, but in my maven project I get a strange conflicting version error.

My POM has these datanucleus references:

<dependency>
    <groupId>org.datanucleus</groupId>
    <artifactId>datanucleus-core</artifactId>
    <version>1.1.0</version>
</dependency>

...

<plugin>
    <groupId>org.datanucleus</groupId>
    <artifactId>maven-datanucleus-plugin</artifactId>
    <version>1.1.0</version>
    <configuration>
        <mappingIncludes>**/*.class</mappingIncludes>
        <verbose>true</verbose>
        <enhancerName>ASM</enhancerName>
        <api>JDO</api>
    </configuration>
    <executions>
        <execution>
        <phase>compile</phase>
        <goals>
            <goal>enhance</goal>
        </goals>
        </execution>
    </executions>
</plugin>

When I try to build the project I get the following error:

Exception in thread "main" Plugin (Bundle) "org.datanucleus" is already registered. 
Ensure you dont have multiple JAR versions of the same plugin in the classpath. The URL "file:/Users/drome/.m2/repository/org/datanucleus/datanucleus-core/1.1.0/**datanucleus-core-1.1.0.jar**" is already registered, and you are trying to register an identical plugin located at URL "file:/Users/drome/.m2/repository/org/datanucleus/datanucleus-core/1.1.3/**datanucleus-core-1.1.3.jar**."
org.datanucleus.exceptions.NucleusException: Plugin (Bundle) "org.datanucleus" is already registered. Ensure you dont have multiple JAR versions of the same plugin in the classpath. The URL "file:/Users/drome/.m2/repository/org/datanucleus/datanucleus-core/1.1.0/datanucleus-core-1.1.0.jar" is already registered, and you are trying to register an identical plugin located at URL "file:/Users/drome/.m2/repository/org/datanucleus/datanucleus-core/1.1.3/datanucleus-core-1.1.3.jar."
at org.datanucleus.plugin.NonManagedPluginRegistry.registerBundle(NonManagedPluginRegistry.java:437)
at org.datanucleus.plugin.NonManagedPluginRegistry.registerBundle(NonManagedPluginRegistry.java:343)
at org.datanucleus.plugin.NonManagedPluginRegistry.registerExtensions(NonManagedPluginRegistry.java:227
)
at org.datanucleus.plugin.NonManagedPluginRegistry.registerExtensionPoints(NonManagedPluginRegistry.jav
a:159)
at org.datanucleus.plugin.PluginManager.registerExtensionPoints(PluginManager.java:82)
at org.datanucleus.OMFContext.(OMFContext.java:164)
at org.datanucleus.enhancer.DataNucleusEnhancer.(DataNucleusEnhancer.java:171)
at org.datanucleus.enhancer.DataNucleusEnhancer.(DataNucleusEnhancer.java:149)
at org.datanucleus.enhancer.DataNucleusEnhancer.main(DataNucleusEnhancer.java:1157)

I don't understand why datanucleus required maven to download datanucleus-core-1.1.3.jar since this is not referenced in the pom.xml

I also do not understand why datanucleus-core-1.1.3.jar is being registered...

Any ideas? Thanks in advance...

stivlo
  • 83,644
  • 31
  • 142
  • 199
ivo
  • 4,101
  • 5
  • 33
  • 42

6 Answers6

6

The DN M2 plugin pulls in the latest versions of the available DN jars that it needs to do its job (there is no other sensible way to do it other than use the latest). You want to restrict "core" to a different version, either by specifying the plugin dependency of core, or by specifying that in your application to

<dependency>
    <groupId>org.datanucleus</groupId>
    <artifactId>datanucleus-core</artifactId>
    <version>1.1.0</version>
    <scope>runtime</scope> 
</dependency>
DataNucleus
  • 15,497
  • 3
  • 32
  • 37
  • I don't think it is possible to exclude a different version of the same artifact. group-a artifact-a 1.0 group-c excluded-artifact – ivo May 18 '09 at 16:31
  • 1
    The DN M2 plugin does the only reasonable thing it can do; use the latest. I see of no other way to have an M2 plugin and not have to release a new version every time we release a new version of a dependent jar and is what M2 version ranges was introduced for. Other people have had no problem handling this http://groups.google.com/group/google-appengine-java/browse_thread/thread/aeaffa3f33e1e4e2/095300c75cd9da39?lnk=gst&q=maven-datanucleus#095300c75cd9da39 Obviously Google updating their DN plugin jar would mean it is irrelevant. – DataNucleus May 18 '09 at 18:34
  • Following the link you provided, indeed changing the scope to 'runtime' fixed the issue. Thanks for the support :-) – ivo May 18 '09 at 23:04
  • I tried this and it seems to work. 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`. – Adrian Ber Oct 29 '13 at 22:28
5

Unfortunately the answer is "hidden" in the comments:

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

That worked for me!

dlinsin
  • 19,249
  • 13
  • 42
  • 53
2

After reading "How to override a plugin's dependency in Maven", I found another way to fix this. Here is my POM:

<plugin>
  <groupId>org.datanucleus</groupId>
  <artifactId>maven-datanucleus-plugin</artifactId>
  <version>3.1.0-m3</version>
  <configuration>
    <verbose>true</verbose>
  </configuration>

  <executions>
    <execution>
      <phase>process-classes</phase>
      <goals>
        <goal>enhance</goal>
      </goals>
    </execution>
  </executions>

  <dependencies>
    <dependency>
      <groupId>org.datanucleus</groupId>
      <artifactId>datanucleus-core</artifactId>
      <version>3.0.4</version>
    </dependency>
  </dependencies>
</plugin>
btpka3
  • 3,720
  • 2
  • 23
  • 26
  • I think this is the more sane answer for this. Fixing the scope to runtime doesn't work for me anyway. What I really want is to fix the version of datanucleus-core used by the enhancer to be the same as what's used by my application. – John Michelau Jan 09 '14 at 02:46
2

I ran into the same issue while testing a maven gae plugin archetype.

I fixed it by adding exclusions in my gae runtime transitive dependencies

<!-- Google App Engine meta-package -->
        <dependency>
            <groupId>net.kindleit</groupId>
            <artifactId>gae-runtime</artifactId>
            <version>${gae.version}</version>
            <type>pom</type>
            <exclusions>
                <exclusion>
                    <groupId>com.google.appengine.orm</groupId>
                    <artifactId>datanucleus-core</artifactId>
                </exclusion>

            </exclusions>
        </dependency>

and then adding the nucleus core as a runtime dependency

<dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-core</artifactId>
            <version>${datanucleus-core.version}</version>
            <scope>runtime</scope>
            <exclusions>
                <exclusion>
                    <groupId>javax.transaction</groupId>
                    <artifactId>transaction-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

as keeping the gae plugin section simple:

<plugin>
                <groupId>org.datanucleus</groupId>
                <artifactId>maven-datanucleus-plugin</artifactId>
                <version>${maven-datanucleus-plugin.version}</version>
                <configuration>
                    <!--
                        Make sure this path contains your persistent classes!
                    -->
                    <mappingIncludes>**/model/*.class</mappingIncludes>
                    <verbose>true</verbose>
                    <enhancerName>ASM</enhancerName>
                    <api>JDO</api>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>enhance</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
Francois
  • 1,851
  • 1
  • 13
  • 15
0

clearing your old version of datanucleus from your local maven repository also solving the problem.

0

Maven-datanucleus-plugin has stopped pulling in the latest versions of the available datanucleus-core since version 3.1.1.

Check the differences between the POM files for Maven-datanucleus-plugin 3.1.1 (http://repo1.maven.org/maven2/org/datanucleus/maven-datanucleus-plugin/3.1.1/maven-datanucleus-plugin-3.1.1.pom) and 3.1.0-release (http://mvnrepository.com/artifact/org.datanucleus/maven-datanucleus-plugin/3.1.0-release).

For maven-datanucleus-plugin 3.1.1 the version range of datanucleus-core dependency is (3.0.99, 3.1.99), and for maven-datanucleus-plugin 3.1.0-release it is (3.0.99, ). No wonder for the older versions of maven-datanucleus-plugin, it automatically pulls in the latest versions of datanucleus-core.