【问题标题】:JBehave-Maven-Plugin, wrong cdi-api dependency in classpathJBehave-Maven-Plugin,类路径中的错误 cdi-api 依赖项
【发布时间】:2017-04-26 09:41:32
【问题描述】:

我正在使用 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 类路径的一部分提供的。

有没有人遇到过类似的问题,知道如何解决这个类加载混乱的问题?

// 萨沙

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>

【问题讨论】:

  • 请出示您的 pom 文件...您使用哪个 Maven 版本?您使用哪个版本的 jbehave-maven-plugin?
  • POM 应该不是问题,我使用的是 maven 3.5.0。 cdi-api-1.0 由 maven plexus 类加载器加载(在类加载器链的早期),然后 cdi-api-1.2 由其中一个子类加载器(即 maven-plugin-class-装载机)。所以类加载器链中有同一个类的两个版本。
  • 您在调试输出中看到了吗?此外,我会尝试联系 jbehave-maven-plugin 开发人员,看看他们是否知道这样的事情......
  • 不,调试日志在这里不是很有帮助。我调试了插件代码以找到问题的根本原因。但是,是的,也许插件开发人员可以在这方面获得更多意见。

标签: java maven jbehave jbehave-maven-plugin


【解决方案1】:

我目前面临着类似的问题。我正在开发的插件启动 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 中激活它。

希望这些指针对某人有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-02
    • 2021-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-15
    • 2012-03-12
    相关资源
    最近更新 更多