我有一个项目,我依赖于POM打包的项目
<dependency>
<groupId>my.external</groupId>
<artifactId>all-ext-libs</artifactId>
<type>POM</type>
<version>2.0-SNAPSHOT</version>
</dependency>
上面的依赖项有以下POM:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>my.external</groupId>
<artifactId>mvn-root</artifactId>
<version>1.2</version>
</parent>
<groupId>my.external</groupId>
<artifactId>all-ext-libs</artifactId>
<version>2.0-SNAPSHOT</version>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}-${project.version}-r${build.number}</finalName>
<directory>${project.basedir}/target</directory>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<skip>${skipTestCompile}</skip>
</configuration>
</execution>
</executions>
<configuration>
<source>1.8</source>
<target>1.8</target>
<verbose>false</verbose>
<useIncrementalCompilation>false</useIncrementalCompilation>
<executable>${env.JAVA_HOME}/bin/javac</executable>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${skipTestCompile}</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<configuration>
<file>${project.build.finalName}</file>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<tagNameFormat>v@{project.version}</tagNameFormat>
</configuration>
</plugin>
</plugins>
</build>
</project>
当我在mvn clean install -U
项目上my.external
时,它只下载JUnit依赖项,但不下载mockito。我已经确认我的.m2
回购邮件中不存在mockito。
什么时候有一个依赖树,它确实会弹出,但当我从.m2缓存中删除它并执行mvn clean install -U
时它不会被下载:
[INFO] | | \- org.ow2.asm:asm-tree:jar:5.0.2:provided
[INFO] | | \- org.ow2.asm:asm:jar:5.0.2:provided
[INFO] | +- org.apache.maven.reporting:maven-reporting-impl:jar:2.1:provided
[INFO] | +- org.apache.maven.reporting:maven-reporting-api:jar:3.0:provided
[INFO] | +- org.apache.maven:maven-plugin-descriptor:jar:2.2.1:provided
[INFO] | +- org.apache.maven:maven-artifact:jar:2.2.1:compile
[INFO] | +- org.apache.maven.doxia:doxia-core:jar:1.4:provided
[INFO] | | +- org.apache.maven.doxia:doxia-logging-api:jar:1.4:provided
[INFO] | | \- org.codehaus.plexus:plexus-component-annotations:jar:1.5.5:compile
[INFO] | +- org.apache.maven.doxia:doxia-sink-api:jar:1.4:provided
[INFO] | +- org.apache.maven.doxia:doxia-decoration-model:jar:1.4:provided
[INFO] | +- org.apache.maven.doxia:doxia-site-renderer:jar:1.4:provided
[INFO] | | +- org.apache.maven.doxia:doxia-module-xhtml:jar:1.4:provided
[INFO] | | +- org.apache.maven.doxia:doxia-module-fml:jar:1.4:provided
[INFO] | | +- org.codehaus.plexus:plexus-i18n:jar:1.0-beta-7:provided
[INFO] | | +- org.codehaus.plexus:plexus-velocity:jar:1.1.7:provided
[INFO] | | \- org.apache.velocity:velocity-tools:jar:2.0:provided
[INFO] | | +- sslext:sslext:jar:1.2-0:provided
[INFO] | | \- org.apache.struts:struts-tiles:jar:1.3.8:provided
[INFO] | +- org.apache.maven.shared:maven-doxia-tools:jar:1.2.1:provided
[INFO] | | \- org.apache.maven:maven-artifact-manager:jar:2.0.6:compile
[INFO] | | +- org.apache.maven:maven-repository-metadata:jar:2.0.6:compile
[INFO] | | \- org.apache.maven.wagon:wagon-provider-api:jar:1.0-beta-2:compile
[INFO] | +- org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9:compile
[INFO] | | \- classworlds:classworlds:jar:1.1-alpha-2:compile
[INFO] | \- org.sonatype.plexus:plexus-build-api:jar:0.0.7:provided
[INFO] +- junit:junit:jar:3.8.1:test
[INFO] +- org.mockito:mockito-all:jar:1.10.19:test
我一直在使用maven,如果我的理解是正确的,它只是一个下载和管理依赖项的工具。但如果我要求它下载某些内容,它将下载/管理它,以便我的目标应用程序可以看到依赖项。
那么为什么在添加到my.external
项目时拒绝下载它。因为JUnit下载很好并且它具有相同的包装(POM)。
答案 0 :(得分:0)
您的all-ext-libs
有junit和mockito-all为 test 依赖项。这些不是传递性的,因此当您通过pom传递它们时,它们会被忽略。我希望在构建原始项目时忽略它们。
我的猜测是,junit是通过其他路径进入的,而不是通过all-ext-libs
。
要走的路:
compile
。<scope>test</scope>
。