Maven 将传递依赖项的 JAR 解压到文件夹中
Maven unpack transitive dependencies' JAR to a folder
我的私有存储库中有两个 Maven 工件,com.test.Parent
和 com.test.Child
。 Child
依赖于 Parent
.
我想让 Maven 做的唯一一件事就是下载 Child
jar 及其依赖的所有内容,然后将其解压到一个目录中。
我能够通过调用 mvn clean dependency:unpack
组合一个 pom.xml
下载 Child
,但是为了下载传递依赖,我不得不手动将它包含在 pom
。
我要的是调用,比如maven initialize
,我需要的依赖就会被下载下来。我现在拥有的是:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>initialize</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.test</groupId>
<artifactId>Child</artifactId>
<version>1.2.3</version>
<type>jar</type>
<includes>**</includes>
<excludes>META-INF/**</excludes>
<outputDirectory>somepath/sources</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
<execution>
<id>unpack-dependencies</id>
<phase>initialize</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<excludeTransitive>false</excludeTransitive>
<includes>**</includes>
<outputDirectory>somepath/depend</outputDirectory>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.test</groupId>
<artifactId>Child</artifactId>
<version>1.2.3</version>
<type>jar</type>
</dependency>
</dependencies>
</plugin>
</plugins>
但是,当我运行 mvn clean initialize
时,只有子文件被下载和解压。
com.test.Child
的 POM 文件包含:
<groupId>com.test</groupId>
<artifactId>Child</artifactId>
<version>1.2.3</version>
<dependencies>
<dependency>
<groupId>com.test</groupId>
<artifactId>Parent</artifactId>
<version>7.8.9</version>
</dependency>
</dependencies>
您发现设置有任何问题吗?最终结果是开发者只需下载一个 pom.xml、运行 mvn <something>
并且所有依赖项将自动下载并解包到特定结构。
谢谢
编辑:
当我删除我的本地 Maven 存储库和 运行 这个 pom 时,Child
和 Parent
都会被下载。所以存在依赖性,但是 unpack-dependencies
目标没有选择 Parent
。
我通过将 <dependencies>
块移到 <plugins>
之外解决了这个问题。所以最终的POM结构为:
<project>
<build>
<plugins>
<plugin>
...
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.test</groupId>
<artifactId>Child</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
</project>
但如果有人能向我解释为什么这有帮助,我将不胜感激。
我的私有存储库中有两个 Maven 工件,com.test.Parent
和 com.test.Child
。 Child
依赖于 Parent
.
我想让 Maven 做的唯一一件事就是下载 Child
jar 及其依赖的所有内容,然后将其解压到一个目录中。
我能够通过调用 mvn clean dependency:unpack
组合一个 pom.xml
下载 Child
,但是为了下载传递依赖,我不得不手动将它包含在 pom
。
我要的是调用,比如maven initialize
,我需要的依赖就会被下载下来。我现在拥有的是:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>initialize</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.test</groupId>
<artifactId>Child</artifactId>
<version>1.2.3</version>
<type>jar</type>
<includes>**</includes>
<excludes>META-INF/**</excludes>
<outputDirectory>somepath/sources</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
<execution>
<id>unpack-dependencies</id>
<phase>initialize</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<excludeTransitive>false</excludeTransitive>
<includes>**</includes>
<outputDirectory>somepath/depend</outputDirectory>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.test</groupId>
<artifactId>Child</artifactId>
<version>1.2.3</version>
<type>jar</type>
</dependency>
</dependencies>
</plugin>
</plugins>
但是,当我运行 mvn clean initialize
时,只有子文件被下载和解压。
com.test.Child
的 POM 文件包含:
<groupId>com.test</groupId>
<artifactId>Child</artifactId>
<version>1.2.3</version>
<dependencies>
<dependency>
<groupId>com.test</groupId>
<artifactId>Parent</artifactId>
<version>7.8.9</version>
</dependency>
</dependencies>
您发现设置有任何问题吗?最终结果是开发者只需下载一个 pom.xml、运行 mvn <something>
并且所有依赖项将自动下载并解包到特定结构。
谢谢
编辑:
当我删除我的本地 Maven 存储库和 运行 这个 pom 时,Child
和 Parent
都会被下载。所以存在依赖性,但是 unpack-dependencies
目标没有选择 Parent
。
我通过将 <dependencies>
块移到 <plugins>
之外解决了这个问题。所以最终的POM结构为:
<project>
<build>
<plugins>
<plugin>
...
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.test</groupId>
<artifactId>Child</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
</project>
但如果有人能向我解释为什么这有帮助,我将不胜感激。