maven谷歌应用引擎项目中数据核增强器的冲突版本

时间:2009-05-18 14:11:15

标签: google-app-engine maven-2 datanucleus

我在设置datanucleus增强器时遇到问题,需要与谷歌应用引擎项目一起使用。如果我使用datanucleus eclipse插件一切顺利,但在我的maven项目中,我得到一个奇怪的冲突版本错误。

我的POM有这些数据核参考:

<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>

当我尝试构建项目时,我收到以下错误:

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)

我不明白为什么datanucleus需要maven才能下载datanucleus-core-1.1.3.jar,因为pom.xml中没有引用它

我也不明白为什么要注册datanucleus-core-1.1.3.jar ......

有什么想法吗? 提前谢谢......

6 个答案:

答案 0 :(得分:6)

DN M2插件提供了它需要完成其工作所需的最新版本的可用DN罐(除了使用最新版本之外,没有其他明智的方法可以做到这一点)。您希望将“核心”限制为不同的版本,方法是指定核心的插件依赖关系,或者在应用程序中指定

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

答案 1 :(得分:5)

不幸的是,答案在评论中被“隐藏”了:

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

这对我有用!

答案 2 :(得分:2)

我在测试maven gae插件原型时遇到了同样的问题。

我通过在我的gae运行时传递依赖项中添加排除项来修复它

<!-- 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>

然后将核心核心添加为运行时依赖

<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>

保持gae插件部分简单:

<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>

答案 3 :(得分:2)

阅读“How to override a plugin's dependency in Maven”之后,我找到了解决此问题的另一种方法。这是我的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>

答案 4 :(得分:0)

从您当地的maven存储库清除旧版本的datanucleus也解决了这个问题。

答案 5 :(得分:0)

自3.1.1版以来,Maven-datanucleus-plugin已停止提供最新版本的可用datanucleus-core。

检查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)和3.1.0-release(http://mvnrepository.com/artifact/org.datanucleus/maven-datanucleus-plugin/3.1.0-release)的POM文件之间的差异。

对于maven-datanucleus-plugin 3.1.1,datanucleus-core依赖的版本范围是(3.0.99,3.1.99),对于maven-datanucleus-plugin 3.1.0-release,它是(3.0.99, )。难怪旧版本的maven-datanucleus-plugin会自动引入最新版本的datanucleus-core。