我使用的是cdi-api-1.2依赖性,在使用maven-j既要插件执行j既要测试时,我注意到类是从cdi-api-1.0加载的,而不是从1.2版本加载的。
经过一些研究发现,cdi-api-1.0依赖是由maven本身($MAVEN_HOME/lib/)和j既要maven插件类路径的一部分提供的。
有没有人有类似的问题和如何解决这个类装载混乱的想法?
// Sascha
POM:
<dependencies>
<dependency>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-core-example</artifactId>
<version>4.1</version>
</dependency>
<dependency>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-weld</artifactId>
<version>4.1</version>
<exclusions>
<exclusion>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se</artifactId>
<version>2.3.5.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<version>2.3.5.Final</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<executions>
<execution>
<id>unpack-view-resources</id>
<phase>pre-integration-test</phase>
<goals>
<goal>unpack-view-resources</goal>
</goals>
</execution>
<execution>
<id>embeddable-stories</id>
<phase>integration-test</phase>
<configuration>
<includes>
<include>**/JBehaveWeldStories.java</include>
</includes>
<ignoreFailureInStories>true</ignoreFailureInStories>
<ignoreFailureInView>true</ignoreFailureInView>
</configuration>
<goals>
<goal>run-stories-as-embeddables</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>发布于 2019-03-05 20:52:45
我目前正面临一个类似的问题。我正在开发的一个插件将启动一个Weld容器,以便使用cdi-plugin-utils获得CDI注入。当我试图更新到Weld 3.1.0 newer时,遇到了这个问题,因为该版本需要一个更新的CDI:
java.lang.IncompatibleClassChangeError: javax.enterprise.inject.Any and javax.enterprise.inject.Any$Literal disagree on InnerClasses attribute
使用-verbose:class JVM选项(在我的示例中是invoker.mavenOpts=-verbose:class),可以清楚地看到从何处加载违规类:
[Loaded javax.enterprise.inject.Any from file:/path/to/maven/3.5.4/libexec/lib/cdi-api-1.0.jar]
...
[Loaded javax.enterprise.inject.Any$Literal from file:/path/to/my-maven-plugin/target/local-repo/org/jboss/weld/se/weld-se-shaded/3.1.0.Final/weld-se-shaded-3.1.0.Final.jar]不幸的是,我还没有找到解决办法。我尝试过建立一个类似于这个答案的子级第一类加载器,但是还没有弄清楚如何在魔咒中激活它。
希望这些建议能帮到别人。
https://stackoverflow.com/questions/43630484
复制相似问题