[英]Transitive Maven dependency shows up in dependency:tree but not in lib directory
我正在使用Maven 3.0.3構建一個大型java項目。 我的pom.xml有一個父,它依賴於spring-context
(編譯范圍),而spring-expression
依賴於spring-expression
(也在編譯范圍內)。 當我使用mvn:dependencyTree
創建依賴樹時 ,一切看起來都很好, spring-expression
庫在編譯范圍內變為傳遞依賴。 但是,如果我使用mvn help:effective-pom
構建一個有效的pom mvn help:effective-pom
,則缺少spring-expression
的條目。 另外,如果我構建項目,則spring-expression
的lib不包含在lib目錄中,而spring-context
的lib則不包含在lib目錄中。
直到最近,該庫已包含在構建中,現在其中一個依賴項似乎發生了變化。 但是spring-context
仍然在編譯范圍內並顯示在依賴關系樹中,因此我不明白為什么這應該改變了行為。
此外,更新的Maven(這似乎已經解決了一個可能相關的問題在這里 )是可悲的是不是一種選擇。 我暫時通過將spring-expression
添加為我的項目的直接而不是傳遞依賴來解決問題,但我寧願不用已經存在的東西阻塞pom。 有任何想法嗎?
更新: Weirder和weirder ......在嘗試提出一個最小的例子時,我找到了一種。 這就是我想出的:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.test.project</groupId>
<artifactId>test-project</artifactId>
<packaging>war</packaging>
<version>0.1-SNAPSHOT</version>
<name>Test Project</name>
<properties>
<spring.version>3.2.4.RELEASE</spring.version>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
它的工作原理是傳遞依賴spring-expression
在mvn:dependencyTree
的輸出中顯示:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Test Project 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ test-project ---
[INFO] org.test.project:test-project:war:0.1-SNAPSHOT
[INFO] \- org.springframework:spring-context:jar:3.2.4.RELEASE:runtime
[INFO] +- org.springframework:spring-aop:jar:3.2.4.RELEASE:runtime
[INFO] | \- aopalliance:aopalliance:jar:1.0:runtime
[INFO] +- org.springframework:spring-beans:jar:3.2.4.RELEASE:runtime
[INFO] +- org.springframework:spring-core:jar:3.2.4.RELEASE:runtime
[INFO] | \- commons-logging:commons-logging:jar:1.1.1:runtime
[INFO] \- org.springframework:spring-expression:jar:3.2.4.RELEASE:runtime
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.922s
[INFO] Finished at: Thu Apr 10 16:17:42 CEST 2014
[INFO] Final Memory: 5M/15M
[INFO] ------------------------------------------------------------------------
而不是有效的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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.test.project</groupId>
<artifactId>test-project</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Test Project</name>
<distributionManagement>
<repository>
<id>internal_repo</id>
<name>Repository for internal artefacts</name>
<url>http://internal/url</url>
</repository>
<snapshotRepository>
<id>internal_repo</id>
<name>Repository for internal artefacts</name>
<url>http://internal/url</url>
</snapshotRepository>
</distributionManagement>
<properties>
<downloadJavadocs>true</downloadJavadocs>
<downloadSources>true</downloadSources>
<spring.version>3.2.4.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.4.RELEASE</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>central</id>
<url>http://internal/url</url>
</repository>
<repository>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>maven3</id>
<url>http://internal/url</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>central</id>
<url>http://internal/url</url>
</pluginRepository>
<pluginRepository>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>maven3</id>
<url>http://internal/url</url>
</pluginRepository>
</pluginRepositories>
<build>
<sourceDirectory>c:\projects\test-project\src\main\java</sourceDirectory>
<scriptSourceDirectory>c:\projects\test-project\src\main\scripts</scriptSourceDirectory>
<testSourceDirectory>c:\projects\test-project\src\test\java</testSourceDirectory>
<outputDirectory>c:\projects\test-project\target\classes</outputDirectory>
<testOutputDirectory>c:\projects\test-project\target\test-classes</testOutputDirectory>
<resources>
<resource>
<directory>c:\projects\test-project\src\main\resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>c:\projects\test-project\src\test\resources</directory>
</testResource>
</testResources>
<directory>c:\projects\test-project\target</directory>
<finalName>test-project-0.1-SNAPSHOT</finalName>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<id>default-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>default-install</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<id>default-resources</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
<execution>
<id>default-testResources</id>
<phase>process-test-resources</phase>
<goals>
<goal>testResources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.2</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<id>default-war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>2.0.1</version>
<executions>
<execution>
<id>default-site</id>
<phase>site</phase>
<goals>
<goal>site</goal>
</goals>
<configuration>
<outputDirectory>c:\projects\test-project\target\site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
<execution>
<id>default-deploy</id>
<phase>site-deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<outputDirectory>c:\projects\test-project\target\site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
</executions>
<configuration>
<outputDirectory>c:\projects\test-project\target\site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<outputDirectory>c:\projects\test-project\target\site</outputDirectory>
</reporting>
</project>
但是,當我構建項目時,lib目錄在此示例中包含spring-expression
。 怎么會這樣?
我正在使用maven 3.1.1運行,並且依賴spring-expression
被正確添加到WEB-INF / lib。 有效的pom不包含spring-expression
,但這是正常的,因為有效的pom不能解決傳遞依賴性。
有效的pom只是一個合並的xml文件,當前的pom加上所有它的父母合並在一起。 只有在構建有效的pom之后才應用maven依賴性解析機制。
這就是為什么有效pom只包含spring-context
依賴的原因,因為這是pom.xml中唯一指定的東西。 如果父pom中存在父依賴關系,它們也會出現在有效pom中。
這是我對mvn依賴的輸出:tree:
INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ test-project ---
[INFO] org.test.project:test-project:war:0.1-SNAPSHOT
[INFO] \- org.springframework:spring-context:jar:3.2.4.RELEASE:runtime
[INFO] +- org.springframework:spring-aop:jar:3.2.4.RELEASE:runtime
[INFO] | \- aopalliance:aopalliance:jar:1.0:runtime
[INFO] +- org.springframework:spring-beans:jar:3.2.4.RELEASE:runtime
[INFO] +- org.springframework:spring-core:jar:3.2.4.RELEASE:runtime
[INFO] | \- commons-logging:commons-logging:jar:1.1.1:runtime
[INFO] \- org.springframework:spring-expression:jar:3.2.4.RELEASE:runtime
這些是我的WEB-INF / lib內容:
aopalliance-1.0.jar
commons-logging-1.1.1.jar
spring-aop-3.2.4.RELEASE.jar
spring-beans-3.2.4.RELEASE.jar
spring-context-3.2.4.RELEASE.jar
spring-core-3.2.4.RELEASE.jar
spring-expression-3.2.4.RELEASE.jar
所以問題似乎是對有效pom功能的一些誤解,以及由於maven錯誤而在WEB-INF lib中缺少依賴spring-expression
:這個問題可以通過版本升級或對pom的硬編碼依賴來解決,因為你找到了解決方法出。
當你構建大型java項目時,lib spring-expression
不在lib目錄中,但是在你的最小例子中。 我注意到你使用的是maven 3.0.3,這個問題是由這個bug MNG-5121引起的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.