5

我有一个正在构建的战争模块,其中包括一些不应该包含的收缩包装罐。即:

WEB-INF/lib/shrinkwrap-api-1.0.0.jar
WEB-INF/lib/shrinkwrap-descriptors-api-base-2.0.0-alpha-2.jar
WEB-INF/lib/shrinkwrap-descriptors-spi-2.0.0-alpha-2.jar
WEB-INF/lib/shrinkwrap-resolver-api-1.0.0-beta-6.jar
WEB-INF/lib/shrinkwrap-spi-1.0.0.jar

这些依赖项都在我们的 pom 中列为测试范围,因此它们不应该出现在我们的打包战争中。下面有更多信息,但我的问题是:为什么这些在这里。显然我缺少一些东西 - 它是什么/我在哪里可以找到它?

当我展示我的有效 pom 时,我看到了以下依赖项(这里省略了一堆东西):

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
...
  <dependencyManagement>
    <dependencies>
    ...
      <dependency>
        <groupId>org.jboss.shrinkwrap</groupId>
        <artifactId>shrinkwrap-extension-descriptors</artifactId>
        <version>1.0.0-beta-6</version>
        <scope>test</scope>
      </dependency>
      <dependency>
        <groupId>org.jboss.shrinkwrap</groupId>
        <artifactId>shrinkwrap-api</artifactId>
        <version>1.0.0</version>
      </dependency>
      <dependency>
        <groupId>org.jboss.shrinkwrap</groupId>
        <artifactId>shrinkwrap-spi</artifactId>
        <version>1.0.0</version>
        <scope>runtime</scope>
      </dependency>
      <dependency>
        <groupId>org.jboss.shrinkwrap</groupId>
        <artifactId>shrinkwrap-impl-base</artifactId>
        <version>1.0.0</version>
        <scope>runtime</scope>
      </dependency>
      <dependency>
        <groupId>org.jboss.shrinkwrap.resolver</groupId>
        <artifactId>shrinkwrap-resolver-api</artifactId>
        <version>1.0.0-beta-6</version>
      </dependency>
      <dependency>
        <groupId>org.jboss.shrinkwrap.resolver</groupId>
        <artifactId>shrinkwrap-resolver-api-maven</artifactId>
        <version>1.0.0-beta-6</version>
      </dependency>
      <dependency>
        <groupId>org.jboss.shrinkwrap.resolver</groupId>
        <artifactId>shrinkwrap-resolver-impl-maven</artifactId>
        <version>1.0.0-beta-6</version>
        <scope>runtime</scope>
      </dependency>
      <dependency>
        <groupId>org.jboss.shrinkwrap.descriptors</groupId>
        <artifactId>shrinkwrap-descriptors-api-base</artifactId>
        <version>2.0.0-alpha-2</version>
      </dependency>
      <dependency>
        <groupId>org.jboss.shrinkwrap.descriptors</groupId>
        <artifactId>shrinkwrap-descriptors-api-javaee</artifactId>
        <version>2.0.0-alpha-2</version>
      </dependency>
      <dependency>
        <groupId>org.jboss.shrinkwrap.descriptors</groupId>
        <artifactId>shrinkwrap-descriptors-api-jboss</artifactId>
        <version>2.0.0-alpha-2</version>
      </dependency>
      <dependency>
        <groupId>org.jboss.shrinkwrap.descriptors</groupId>
        <artifactId>shrinkwrap-descriptors-gen</artifactId>
        <version>2.0.0-alpha-2</version>
        <scope>provided</scope>
      </dependency>
      <dependency>
        <groupId>org.jboss.shrinkwrap.descriptors</groupId>
        <artifactId>shrinkwrap-descriptors-impl-base</artifactId>
        <version>2.0.0-alpha-2</version>
        <scope>runtime</scope>
      </dependency>
      <dependency>
        <groupId>org.jboss.shrinkwrap.descriptors</groupId>
        <artifactId>shrinkwrap-descriptors-impl-javaee</artifactId>
        <version>2.0.0-alpha-2</version>
        <scope>runtime</scope>
      </dependency>
      <dependency>
        <groupId>org.jboss.shrinkwrap.descriptors</groupId>
        <artifactId>shrinkwrap-descriptors-impl-jboss</artifactId>
        <version>2.0.0-alpha-2</version>
        <scope>runtime</scope>
      </dependency>
      <dependency>
        <groupId>org.jboss.shrinkwrap.descriptors</groupId>
        <artifactId>shrinkwrap-descriptors-spi</artifactId>
        <version>2.0.0-alpha-2</version>
        <scope>runtime</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    ...
    <dependency>
      <groupId>org.jboss.shrinkwrap.resolver</groupId>
      <artifactId>shrinkwrap-resolver-api-maven</artifactId>
      <version>1.0.0-beta-6</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.jboss.shrinkwrap.resolver</groupId>
      <artifactId>shrinkwrap-resolver-impl-maven</artifactId>
      <version>1.0.0-beta-6</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.jboss.shrinkwrap</groupId>
      <artifactId>shrinkwrap-impl-base</artifactId>
      <version>1.0.0</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  ...
</project>

当我打印依赖关系树时,我得到下面的输出(仅显示其中包含有问题的 jar 的节点。我确实看到其中一些 jar 被列为“运行时”和“运行时(从测试管理的范围)”但是我不确定这是否相关或它们如何被切换/包含为运行时,因为在大多数情况下,它们所属的依赖项是测试范围:

[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ name_removed ---
...
[INFO] +- org.jboss.arquillian.extension:arquillian-seam2:jar:1.0.0.Alpha2:test
[INFO] |  \- org.jboss.shrinkwrap:shrinkwrap-extension-descriptors:jar:1.0.0-beta-6:test (version managed from 1.0.0-beta-5)
[INFO] +- org.jboss.arquillian.protocol:arquillian-protocol-servlet:jar:1.0.0.Final:test
[INFO] |  +- org.jboss.arquillian.container:arquillian-container-spi:jar:1.0.0.Final:test
[INFO] |  |  +- org.jboss.arquillian.config:arquillian-config-api:jar:1.0.0.Final:test
[INFO] |  |  \- org.jboss.arquillian.config:arquillian-config-impl-base:jar:1.0.0.Final:test
[INFO] |  +- org.jboss.arquillian.container:arquillian-container-test-api:jar:1.0.0.Final:test
[INFO] |  \- org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-spi:jar:2.0.0-alpha-2:runtime
[INFO] |     \- org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-api-base:jar:2.0.0-alpha-2:runtime (version managed from 1.2.0-alpha-1)

[INFO] +- org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-api-maven:jar:1.0.0-beta-6:test (scope not updated to runtime)
[INFO] +- org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-impl-maven:jar:1.0.0-beta-6:test (scope not updated to runtime)
[INFO] |  +- org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-api:jar:1.0.0-beta-6:test
[INFO] |  +- org.sonatype.aether:aether-api:jar:1.8:test
[INFO] |  +- org.sonatype.aether:aether-util:jar:1.8:test
[INFO] |  +- org.sonatype.aether:aether-connector-wagon:jar:1.8:test
[INFO] |  |  +- org.sonatype.aether:aether-spi:jar:1.8:test
[INFO] |  |  \- org.codehaus.plexus:plexus-container-default:jar:1.5.5:test
[INFO] |  |     +- org.codehaus.plexus:plexus-classworlds:jar:2.2.2:test
[INFO] |  |     +- org.apache.xbean:xbean-reflect:jar:3.4:test
[INFO] |  |     |  \- commons-logging:commons-logging-api:jar:1.1:test
[INFO] |  |     \- com.google.collections:google-collections:jar:1.0:test
[INFO] |  +- org.apache.maven:maven-aether-provider:jar:3.0.1:test
[INFO] |  |  +- org.apache.maven:maven-model:jar:3.0.1:test
[INFO] |  |  +- org.apache.maven:maven-model-builder:jar:3.0.1:test
[INFO] |  |  +- org.apache.maven:maven-repository-metadata:jar:3.0.1:test
[INFO] |  |  +- org.sonatype.aether:aether-impl:jar:1.8:test
[INFO] |  |  +- org.codehaus.plexus:plexus-component-annotations:jar:1.5.5:test
[INFO] |  |  \- org.codehaus.plexus:plexus-utils:jar:2.0.4:test
[INFO] |  +- org.apache.maven:maven-settings-builder:jar:3.0.1:test
[INFO] |  |  +- org.codehaus.plexus:plexus-interpolation:jar:1.14:test
[INFO] |  |  +- org.apache.maven:maven-settings:jar:3.0.1:test
[INFO] |  |  \- org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3:test
[INFO] |  |     \- org.sonatype.plexus:plexus-cipher:jar:1.4:test
[INFO] |  +- org.apache.maven.wagon:wagon-provider-api:jar:1.0-beta-7:test
[INFO] |  +- org.apache.maven.wagon:wagon-file:jar:1.0-beta-7:test
[INFO] |  \- org.apache.maven.wagon:wagon-http-lightweight:jar:1.0-beta-7:test
[INFO] |     \- org.apache.maven.wagon:wagon-http-shared:jar:1.0-beta-7:test
[INFO] \- org.jboss.shrinkwrap:shrinkwrap-impl-base:jar:1.0.0:test (scope not updated to runtime)
[INFO]    \- org.jboss.shrinkwrap:shrinkwrap-spi:jar:1.0.0:runtime (scope managed from test)
[INFO]       \- org.jboss.shrinkwrap:shrinkwrap-api:jar:1.0.0:runtime
4

3 回答 3

4

It looks like this was a problem with a BOM used by Arquillian:

https://issues.jboss.org/browse/ARQ-889

We've updated to the fix version and all is well.

于 2012-06-19T18:36:32.570 回答
3

您不想要的 5 个 shrinkwrap jar 都是您的测试范围依赖项的依赖项。但是在dependencyManagement 部分中shrinkwrap-spishrinkwrap-descriptors-spi、 和shrinkwrap-resolver-impl-maven被列为运行时范围。我的猜测是这些运行时声明会覆盖传递依赖项的测试范围。并且运行时范围由这些依赖项的依赖项继承。

所以shrinkwrap-spishrinkwrap-descriptors-spi被包括在内,因为它们在dependencyManagement 中的运行时声明覆盖了从显式测试范围依赖项中传递继承的测试范围。因为这两个依赖项现在是运行时范围的,所以它们也导致shrinkwrap-apishrinkwrap-descriptors-api-base成为运行时。我认为shrinkwrap-resolver-api还从shrinkwrap-resolver-impl-maven(它是dependencyManagement中的运行时)传递运行时范围,由于显式测试范围,它本身不包括在内。

然而,这主要是一个猜测,通过在一个空项目中使用一些收缩包装依赖项测试不同的范围并查看解决了什么来支持。

如果没有理由需要shrinkwrap-spi,shrinkwrap-descriptors-spishrinkwrap-resolver-impl-maven在dependencyManagement 中运行时范围,我将删除范围位并再次尝试打包。如果出于某种原因确实需要将它们设置为运行时范围,则可能必须在依赖项块中将五个 jar 设置为显式测试范围。


编辑:

这是一个简单的项目来演示:

pom.xml

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>my.group</groupId>
    <artifactId>my-artifact</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>3.0.6.RELEASE</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
                <version>3.0.6.RELEASE</version>
                <scope>runtime</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

spring-beans工件取决于spring-core。)

然后我运行mvn clean package并得到以下输出:

[INFO] Building war: /home/matts/test/target/my-artifact-0.0.1-SNAPSHOT.war
[DEBUG] adding directory META-INF/
[DEBUG] adding entry META-INF/MANIFEST.MF
[DEBUG] adding directory WEB-INF/
[DEBUG] adding directory WEB-INF/classes/
[DEBUG] adding directory WEB-INF/lib/
[DEBUG] adding entry WEB-INF/classes/Test.class
[DEBUG] adding entry WEB-INF/lib/spring-core-3.0.6.RELEASE.jar
[DEBUG] adding entry WEB-INF/lib/spring-asm-3.0.6.RELEASE.jar
[DEBUG] adding entry WEB-INF/lib/commons-logging-1.1.1.jar
[DEBUG] adding entry WEB-INF/web.xml

但是,如果我dependencyManagement从 POM 中删除该部分,并再次创建战争,我会得到以下输出:

[INFO] Building war: /home/matts/test/target/my-artifact-0.0.1-SNAPSHOT.war
[DEBUG] adding directory META-INF/
[DEBUG] adding entry META-INF/MANIFEST.MF
[DEBUG] adding directory WEB-INF/
[DEBUG] adding directory WEB-INF/classes/
[DEBUG] adding entry WEB-INF/classes/Test.class
[DEBUG] adding entry WEB-INF/web.xml

即使spring-beans是测试范围,因为我spring-core在该部分中设置了运行时范围dependencyManagement,它仍然包含在战争中。

于 2012-06-19T17:16:19.923 回答
0

您的依赖树报告显示了其中一些 jar 的运行时范围,因此它们相应地包含在战争中,即在运行时可用。有效的 pom 还显示了一些 jar 的默认范围,因此包含。总而言之,您必须追查依赖项的来源。检查你的 pom 中的依赖和依赖管理部分,以及所有的父 pom。

为了更容易调查,我会创建一个声明了其中一些依赖项的测试战争项目,这样您就可以逐步添加和删除 pom 片段,看看它如何影响最终结果。

于 2012-06-19T14:35:21.077 回答