我有一个正在建造的战争模块,并且包括一些它不应该的收缩包装罐。即:
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
这些依赖项都在我们的poms中列为test-scoped,因此它们不应该在我们的打包战争中。更多信息如下,但我的问题是:为什么这些在这里。显然我缺少一些东西 - 它是什么/我在哪里可以找到它?
当我展示我的有效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被列为“运行时”和“运行时”(范围由test测试) )“但是我不确定它是否相关或者它们如何被切换/包含在运行时中,因为在大多数情况下,它们所属的依赖项是测试范围:
[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
答案 0 :(得分:4)
答案 1 :(得分:3)
您不想要的5个收缩包装罐都是您的测试范围依赖项的依赖项。但是在dependencyManagement部分中,shrinkwrap-spi
,shrinkwrap-descriptors-spi
和shrinkwrap-resolver-impl-maven
被列为运行时范围。我的猜测是这些运行时声明覆盖了传递依赖项的测试范围。并且运行时作用域由这些依赖项的依赖项继承。
因此包含shrinkwrap-spi
和shrinkwrap-descriptors-spi
是因为它们在dependencyManagement中的运行时声明会覆盖从您的显式测试范围依赖项传递继承的测试范围。因为这两个依赖项现在是运行时范围的,所以它们也会导致shrinkwrap-api
和shrinkwrap-descriptors-api-base
成为运行时。我认为shrinkwrap-resolver-api
也可以从shrinkwrap-resolver-impl-maven
(它是dependencyManagement中的运行时)传递给运行时范围,由于显式的测试范围,它本身不包括在内。
然而,这主要是猜测,通过在空项目中测试不同的范围和一些收缩包依赖关系以及查看已解决的内容来支持。
如果没有理由需要shrinkwrap-spi
,shrinkwrap-descriptors-spi
和shrinkwrap-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
但是如果我从POM中移除dependencyManagement
部分并再次创建战争,我会得到以下输出:
[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
部分中的运行时范围,但它仍然包含在战争中。
答案 2 :(得分:0)
您的依赖关系树报告显示了其中一些jar的运行时范围,因此它们会相应地包含在war中,即在运行时可用。有效的pom还显示了一些罐子的默认范围,因此包含。总而言之,您必须追溯依赖关系的起源。检查你的poms中的依赖关系和依赖关系管理部分,以及所有父poms。
为了便于调查,我创建了一个测试war项目,其中声明了一些依赖项,因此您可以逐步添加和删除pom片段,看看它如何影响最终结果。