Java – transitive Maven dependency depends on: tree but not displayed in lib directory

I'm using Maven 3.0 Build a large java project My POM XML has a parent, which depends on spring context (compilation scope), while spring depends on spring expression (also compilation scope) When I create a dependency tree using MVN: dependency tree, everything looks good, and the spring expression library becomes a pass through dependency within the compilation scope However, if I use MVN help to build an effective POM: the effective POM lacks the entry of spring expression In addition, if I build a project, the Lib of spring expression is not included in the Lib directory, while the Lib of spring context is not included in the Lib directory

Until recently, the library was included in the build, and now one of the dependencies seems to have changed However, spring context is still in compilation scope and displayed in the dependency tree, so I don't understand why this should change the behavior

In addition, updating Maven (which seems to have solved possible related problems here) is unfortunately not an option For the time being, I solve the problem by adding spring expression as a direct rather than a passing dependency of my project, but I'd rather not block POM with what already exists Any ideas?

Update: weirder and weirder... When trying to give a minimal example, I found one That's 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>

Its working principle is to pass the dependency spring expression, which is displayed in the output of 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] ------------------------------------------------------------------------

Instead of a valid 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 contains spring - expression. In this example How did this happen?

Solution

I'm using Maven 3.1 1 runs and relies on spring expression to correctly add to WEB-INF / lib A valid POM does not contain spring expression, but this is normal because a valid POM cannot solve the delivery dependency

A valid POM is just a merged XML file. The current POM plus all its parents are merged together Maven dependency resolution mechanism is applied only after building a valid POM

This is why valid POMS only contain spring context dependencies, because this is POM The only thing specified in XML If there are parent dependencies in the parent POM, they will also appear in the valid POM

This is the output of my dependency on 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

These are my web inf / lib content:

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 problem seems to be some misunderstanding about the effective POM function and the lack of dependency on spring expression in WEB-INF lib due to Maven error: this problem can be solved by version upgrade or hard coding dependency on POM, because you have found a solution

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>