简体   繁体   English

Transitive Maven依赖关系显示在依赖关系中:树但不在lib目录中

[英]Transitive Maven dependency shows up in dependency:tree but not in lib directory

I am using Maven 3.0.3 to build a large java project. 我正在使用Maven 3.0.3构建一个大型java项目。 My pom.xml has a parent which depends on spring-context (compile scope) which in turn depends on spring-expression (also in the compile scope). 我的pom.xml有一个父,它依赖于spring-context (编译范围),而spring-expression依赖于spring-expression (也在编译范围内)。 When I create a dependency tree with mvn:dependencyTree everything looks fine, the spring-expression library turns up as a transitive dependency in compile scope. 当我使用mvn:dependencyTree创建依赖树时 ,一切看起来都很好, spring-expression库在编译范围内变为传递依赖。 However if I build an effective pom with mvn help:effective-pom the entry for spring-expression is missing. 但是,如果我使用mvn help:effective-pom构建一个有效的pom mvn help:effective-pom ,则缺少spring-expression的条目。 Also if I build the project the lib for spring-expression is not included in the lib directory while the one for spring-context is. 另外,如果我构建项目,则spring-expression的lib不包含在lib目录中,而spring-context的lib则不包含在lib目录中。

Until recently the library was included in the build, now something seems to have changed in one of the dependencies. 直到最近,该库包含在构建中,现在其中一个依赖项似乎发生了变化。 However spring-context is still in the compile scope and shows up in the dependency tree, so I don't see why this should have changed the behavior. 但是spring-context仍然在编译范围内并显示在依赖关系树中,因此我不明白为什么这应该改变了行为。

Also, updating Maven (which seems to have solved a possibly related problem here ) is sadly not an option. 此外,更新的Maven(这似乎已经解决了一个可能相关的问题在这里 )是可悲的是不是一种选择。 I have temporarily fixed the problem by adding spring-expression as a direct rather than transitive dependency to my project but I'd rather not clog up the pom with stuff that should already be there. 我暂时通过将spring-expression添加为我的项目的直接而不是传递依赖来解决问题,但我宁愿不用已经存在的东西阻塞pom。 Any ideas? 有任何想法吗?

Update: Weirder and weirder... While trying to come up with a minimal example I found one - sort of. 更新: Weirder和weirder ......在尝试提出一个最小的例子时,我找到了一种。 This is what I came up with: 这就是我想出的:

<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>

It works in that the transitive dependency spring-expression is shown in the output of mvn:dependencyTree : 它的工作原理是传递依赖spring-expressionmvn: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] ------------------------------------------------------------------------

and not in the effective 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">
  <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>

However when I build the project the lib directory does include spring-expression in this example. 但是,当我构建项目时,lib目录在此示例包含spring-expression How can this be? 怎么会这样?

I am running with maven 3.1.1 and the dependency spring-expression is correctly added to WEB-INF/lib. 我正在使用maven 3.1.1运行,并且依赖spring-expression被正确添加到WEB-INF / lib。 The effective pom does not contain spring-expression , but that is normal as the effective pom does not resolve transitive dependencies. 有效的pom不包含spring-expression ,但这是正常的,因为有效的pom不能解决传递依赖性。

The effective pom is just a merged xml file with the current pom plus all it's parents merged together. 有效的pom只是一个合并的xml文件,当前的pom加上所有它的父母合并在一起。 The maven dependency resolution mechanism is applied only after the effective pom is built. 只有在构建有效的pom之后才应用maven依赖性解析机制。

This is the reason why the effective pom only contains the spring-context dependency, because that was the only thing specified in the pom.xml. 这就是为什么有效pom只包含spring-context依赖的原因,因为这是pom.xml中唯一指定的东西。 If there would be parent dependencies in a parent pom they would show up in the effective pom too. 如果父pom中存在父依赖关系,它们也会出现在有效pom中。

This is my output of mvn dependency:tree: 这是我对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

and these is my WEB-INF/lib contents: 这些是我的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

So the issue seems to be some misunderstanding of the effective pom feature together with a missing dependency spring-expression in WEB-INF lib due to a maven bug: this problem is solvable via version upgrade or hardcoding dependency on the pom as workaround as you found out. 所以问题似乎是对有效pom功能的一些误解,以及由于maven错误而在WEB-INF lib中缺少依赖spring-expression :这个问题可以通过版本升级或对pom的硬编码依赖来解决,因为你找到了解决方法出。

Lib spring-expression is not in lib directory when you build your large java project, but is in your minimal example's. 当你构建大型java项目时,lib spring-expression不在lib目录中,但是在你的最小例子中。 And I noticed that you were using maven 3.0.3, this problem is caused by this bug MNG-5121 . 我注意到你使用的是maven 3.0.3,这个问题是由这个bug MNG-5121引起的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM