簡體   English   中英

數據核增強器在Maven中的依賴關系沖突-第2部分

[英]Datanucleus enhancer conflicting dependencies in maven - part 2

這個問題與Maven Google App Engine項目中的Datanucleus Enhancer版本沖突 我在那里嘗試了解決方案,並且有效。 但是如果我運行mvn clean compile我會得到錯誤

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.

知道為什么嗎? 我正在使用datanucleus-maven-plugin:3.3.0-release。

問題是我有兩次datanucleus-core:一次來自項目依賴性,一次來自插件依賴性。 在運行mvn datanuleus:enhance之后,在控制台中,以下行出現兩次:

[INFO] CP: /home/user/.m2/repository/org/datanucleus/datanucleus-core/3.2.7/datanucleus-cor‌​e-3.2.7.jar

我終於找到了解決方法。 這不是最優雅的解決方案,但我認為沒有其他解決方案。

解決方法是將datanucleus-core依賴項添加到編譯器插件中(請注意compile范圍。

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

datanucleus-core依賴項與runtime作用域一起添加

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

並且datanucleus Enhancer插件的datanucleus-core默認版本被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>

它也適用於3.2.9版本。

將datanucleus-core設置為運行時意味着您不需要編譯它(該線程中的用戶需要什么)。 您顯然想運行(DataNucleus)批注處理器(預編譯),因此必須存在該批注處理器才能進行編譯,因此您改為設置datanucleus-maven-plugin使用的datanucleus-core版本(取決於其對插件的依賴) ,因此它與整個pom.xml使用的內容匹配

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM