我使用 cdi-api-1.2 依赖,当使用maven-jbehave-plugin执行jbehave测试时,我注意到类是从 cdi-api-加载的1.0 而不是1.2版本。
经过一些研究后发现,cdi-api-1.0依赖性是由maven本身( $ MAVEN_HOME / lib / )和jbehave-maven-plugin类路径的一部分提供的。 / p>
有没有人有类似的问题和想法如何解决这个类加载混乱?
// 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>
答案 0 :(得分:0)
我目前正面临类似的问题。我正在开发的插件会启动一个Weld容器,以使用cdi-plugin-utils进行CDI注入。当我尝试更新到Weld 3.1.0.Final时,遇到了这个问题,因为该版本需要更新的CDI API:
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]
很遗憾,我还没有解决方案。我尝试过尝试建立类似于this answer的子优先级类加载器,但还没有弄清楚如何在mojo中激活它。
希望这些指针对某人有所帮助。