Fitnesse maven-classpath-plugin 与 Guava jar 冲突

Posted

技术标签:

【中文标题】Fitnesse maven-classpath-plugin 与 Guava jar 冲突【英文标题】:Fitnesse maven-classpath-plugin conflicting with Guava jar 【发布时间】:2018-03-29 13:00:32 【问题描述】:

我正在尝试在我的项目中设置 Fitnesse,但我在使用番石榴罐时遇到了一些问题 这就是我的 pom.xml 的样子:

<dependencies>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>23.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.fitnesse/fitnesse -->
    <dependency>
        <groupId>org.fitnesse</groupId>
        <artifactId>fitnesse</artifactId>
        <version>20161106</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.fitnesse.plugins</groupId>
        <artifactId>maven-classpath-plugin</artifactId>
        <version>1.9</version>
        <scope>runtime</scope>
    </dependency>
</dependencies>

<profiles>
    <profile>
        <id>integration-test</id>
        <properties>
            <skip.unit.tests>false</skip.unit.tests>
        </properties>
    </profile>
    <profile>
        <id>standalone</id>
        <properties>
            <skip.unit.tests>true</skip.unit.tests>
        </properties>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <version>1.6</version>
                    <executions>
                        <execution>
                            <id>start-fitnesse</id>
                            <phase>test</phase>
                            <configuration>
                                <tasks>
                                    <echo taskname="fitnesse" message="Starting FitNesse..."/>
                                    <java classname="fitnesseMain.FitNesseMain"
                                          classpathref="maven.runtime.classpath" fork="true">
                                        <arg line="-p 9090"/>
                                        <arg line="-d ."/>
                                        <arg line="-o"/>
                                    </java>
                                </tasks>
                            </configuration>
                            <goals>
                                <goal>run</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
        <dependencies>
        </dependencies>
    </profile>
</profiles>

我正在使用maven-classpath-plugin 在 Fitnesse 中设置类路径。这个插件传递使用org.sonatype.sisu:sisu-guava:jar:0.9.9:runtime jar。而且我的项目还需要 Guava jar。 Maven 依赖树:

[INFO] --- maven-dependency-plugin:3.0.1:tree (default-cli) @ testProject ---
[INFO] com.rdm:testProject:jar:1.0-SNAPSHOT
[INFO] +- com.google.guava:guava:jar:23.0:compile
[INFO] |  +- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] |  +- com.google.errorprone:error_prone_annotations:jar:2.0.18:compile
[INFO] |  +- com.google.j2objc:j2objc-annotations:jar:1.1:compile
[INFO] |  \- org.codehaus.mojo:animal-sniffer-annotations:jar:1.14:compile
[INFO] +- org.fitnesse:fitnesse:jar:20161106:runtime
[INFO] |  +- org.htmlparser:htmlparser:jar:2.1:runtime
[INFO] |  +- org.htmlparser:htmllexer:jar:2.1:runtime
[INFO] |  +- org.apache.velocity:velocity:jar:1.7:runtime
[INFO] |  +- commons-lang:commons-lang:jar:2.6:runtime
[INFO] |  +- commons-collections:commons-collections:jar:3.2.2:runtime
[INFO] |  +- org.json:json:jar:20151123:runtime
[INFO] |  +- com.googlecode.java-diff-utils:diffutils:jar:1.3.0:runtime
[INFO] |  +- org.apache.ant:ant:jar:1.9.6:runtime
[INFO] |  |  \- org.apache.ant:ant-launcher:jar:1.9.6:runtime
[INFO] |  \- junit:junit:jar:4.12:runtime
[INFO] |     \- org.hamcrest:hamcrest-core:jar:1.3:runtime
[INFO] \- org.fitnesse.plugins:maven-classpath-plugin:jar:1.9:runtime
[INFO]    \- org.apache.maven:maven-embedder:jar:3.0.4:runtime
[INFO]       +- org.apache.maven:maven-settings:jar:3.0.4:runtime
[INFO]       +- org.apache.maven:maven-core:jar:3.0.4:runtime
[INFO]       |  +- org.apache.maven:maven-model:jar:3.0.4:runtime
[INFO]       |  +- org.apache.maven:maven-settings-builder:jar:3.0.4:runtime
[INFO]       |  +- org.apache.maven:maven-repository-metadata:jar:3.0.4:runtime
[INFO]       |  +- org.apache.maven:maven-artifact:jar:3.0.4:runtime
[INFO]       |  +- org.apache.maven:maven-aether-provider:jar:3.0.4:runtime
[INFO]       |  |  \- org.sonatype.aether:aether-spi:jar:1.13.1:runtime
[INFO]       |  +- org.sonatype.aether:aether-impl:jar:1.13.1:runtime
[INFO]       |  +- org.sonatype.aether:aether-api:jar:1.13.1:runtime
[INFO]       |  +- org.sonatype.aether:aether-util:jar:1.13.1:runtime
[INFO]       |  \- org.codehaus.plexus:plexus-interpolation:jar:1.14:runtime
[INFO]       +- org.apache.maven:maven-plugin-api:jar:3.0.4:runtime
[INFO]       +- org.apache.maven:maven-model-builder:jar:3.0.4:runtime
[INFO]       +- org.apache.maven:maven-compat:jar:3.0.4:runtime
[INFO]       |  \- org.apache.maven.wagon:wagon-provider-api:jar:2.2:runtime
[INFO]       +- org.codehaus.plexus:plexus-utils:jar:2.0.6:runtime
[INFO]       +- org.codehaus.plexus:plexus-classworlds:jar:2.4:runtime
[INFO]       +- org.sonatype.sisu:sisu-inject-plexus:jar:2.3.0:runtime
[INFO]       |  \- org.sonatype.sisu:sisu-inject-bean:jar:2.3.0:runtime
[INFO]       |     \- org.sonatype.sisu:sisu-guice:jar:no_aop:3.1.0:runtime
[INFO]       |        \- org.sonatype.sisu:sisu-guava:jar:0.9.9:runtime
[INFO]       +- org.codehaus.plexus:plexus-component-annotations:jar:1.5.5:runtime
[INFO]       +- org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3:runtime
[INFO]       +- org.sonatype.plexus:plexus-cipher:jar:1.7:runtime
[INFO]       \- commons-cli:commons-cli:jar:1.2:runtime

这是我尝试启动健身服务器时遇到的错误:

[fitnesse] Starting FitNesse...
     [java] SEVERE: Error while starting the FitNesse [Unable to instantiate component for type fitnesse.wikitext.widgets.MavenClasspathSymbolType]
     [java] fitnesse.components.ComponentInstantiationException: Unable to instantiate component for type fitnesse.wikitext.widgets.MavenClasspathSymb
olType
     [java]     at fitnesse.components.ComponentFactory.createComponent(ComponentFactory.java:75)
     [java]     at fitnesse.plugins.PropertyBasedPluginFeatureFactory$8.register(PropertyBasedPluginFeatureFactory.java:152)
     [java]     at fitnesse.plugins.PropertyBasedPluginFeatureFactory.forEachClass(PropertyBasedPluginFeatureFactory.java:144)
     [java]     at fitnesse.plugins.PropertyBasedPluginFeatureFactory.forEachObject(PropertyBasedPluginFeatureFactory.java:150)
     [java]     at fitnesse.plugins.PropertyBasedPluginFeatureFactory.registerSymbolTypes(PropertyBasedPluginFeatureFactory.java:75)
     [java]     at fitnesse.plugins.PluginsLoader.loadSymbolTypes(PluginsLoader.java:87)
     [java]     at fitnesse.ContextConfigurator.makeFitNesseContext(ContextConfigurator.java:151)
     [java]     at fitnesseMain.FitNesseMain.launchFitNesse(FitNesseMain.java:69)
     [java]     at fitnesseMain.FitNesseMain.launchFitNesse(FitNesseMain.java:58)
     [java]     at fitnesseMain.FitNesseMain.mai
     [java] n(FitNesseMain.java:38)
     [java] Caused by: java.lang.reflect.InvocationTargetException
     [java]     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     [java]     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
     [java]     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
     [java]     at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
     [java]     at fitnesse.components.ComponentFactory.createComponent(ComponentFactory.java:72)
     [java]     ... 9 more
     [java] Caused by: java.lang.NoSuchMethodError: com.google.common.collect.MapMaker.makeComputingMap(Lcom/google/common/base/Function;)Ljava/util/c
oncurrent/ConcurrentMap;
     [java]     at com.google.inject.internal.Annotations$AnnotationChecker.<init>(Annotations.java:104)
     [java]     at com.google.inject.internal.Annotations.<clinit>(Annotations.java:122)
     [java]     at com.google.inject.Key.ensureRetainedAtRuntime(Key.java:362)
     [java]     at com.google.inject.Key.strategyFor(Key.java:354)
     [java]     at com.google.inject.Key.get(Key.java:222)
     [java]     at org.sonatype.guice.bean.binders.ParameterKeys.<clinit>(ParameterKeys.java:23)
     [java]     at org.codehaus.plexus.DefaultPlexusContainer$ContainerModule.configure(DefaultPlexusContainer.java:801)
     [java]     at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:229)
     [java]     at com.google.inject.spi.Elements.getElements(Elements.java:103)
     [java]     at com.google.inject.spi.Elements.getElements(Elements.java:80)
     [java]     at org.sonatype.guice.bean.binders.MergedModule.configure(MergedModule.java:54)
     [java]     at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:229)
     [java]     at com.google.inject.spi.Elements.getElements(Elements.java:103)
     [java]     at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:136)
     [java]     at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104)
     [java]     at com.google.inject.Guice.createInjector(Guice.java:94)
     [java]     at com.google.inject.Guice.createInjector(Guice.java:71)
     [java]     at com.google.inject.Guice.createInjector(Guice.java:61)
     [java]     at org.codehaus.plexus.DefaultPlexusContainer.addPlexusInjector(DefaultPlexusContainer.java:470)
     [java]     at org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:196)
     [java]     at org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:160)
     [java]     at fitnesse.wikitext.widgets.MavenClasspathExtractor.buildPlexusContainer(MavenClasspathExtractor.java:219)
     [java]     at fitnesse.wikitext.widgets.MavenClasspathExtractor.buildPlexusContainer(MavenClasspathExtractor.java:215)
     [java]     at fitnesse.wikitext.widgets.MavenClasspathExtractor.<init>(MavenClasspathExtractor.java:51)
     [java]     at fitnesse.wikitext.widgets.MavenClasspathSymbolType.<init>(MavenClasspathSymbolType.java:39)
     [java]     ... 14 more

现在,如果在 maven-classpath-plugin 之后声明 Guava 依赖项,那么我不会遇到这个问题,但是我的单元测试和集成测试失败,MethodNotFoundException 并且如果我在 maven-classpath- 上声明 Guava 依赖项插件然后fitnesse服务器不会出现如上所示的错误。

我看到了类似的问题Drools 6 sisu-guava conflicts with guava

任何建议或解决方法都会很有帮助。

编辑:找到了一个更简单的解决方案 - 我在我的 pom.xml 中添加了以下依赖项:

<dependency>
    <groupId>org.apache.maven</groupId>
    <artifactId>maven-embedder</artifactId>
    <version>3.5.0</version>
    <scope>runtime</scope>
</dependency>

这会停止 sisu-guava 的传递下载。现在测试和健身服务器都可以工作了

【问题讨论】:

【参考方案1】:

这似乎与Fitnesse Maven Classpath error 非常相似。使用我提到的两种方法之一来处理 wiki 库和运行测试的固定装置之间的依赖冲突。

【讨论】:

以上是关于Fitnesse maven-classpath-plugin 与 Guava jar 冲突的主要内容,如果未能解决你的问题,请参考以下文章

Fitnesse Maven 类路径错误

Fitnesse Slim的使用

使用 SLIM 使用 Python 编写 Fitnesse 测试

如何将 Fitnesse 页面添加到版本控制?

给Fitnesse添加json格式报告

Fitnesse-The Slim Tables