【发布时间】:2023-03-20 08:43:02
【问题描述】:
我正在尝试将 maven 依赖项 jar 的内容解压缩到我的 classes 文件夹中,同时包含传递依赖项。我也不想解压我项目的所有依赖项。只有一个会很好,如果我可以对它们的列表执行此操作,那就更好了。找到了类似的解决方案,但没有解决我的确切问题。
示例主项目 Pom:
.
.
.
<dependencies>
<dependency>
<groupId>com.test.dep</groupId>
<artifact>first-dependency</artifact>
</dependency>
<dependency>
<groupId>com.test.dep</groupId>
<artifact>second-dependency</artifact>
</dependency>
</dependencies>
.
.
.
第二个依赖Pom示例:
.
.
.
<dependencies>
<dependency>
<groupId>com.test.dep</groupId>
<artifact>third-dependency</artifact>
</dependency>
<dependency>
<groupId>com.test.dep</groupId>
<artifact>fourth-dependency</artifact>
</dependency>
</dependencies>
.
.
.
我希望将second-dependency 解压缩到嵌套在target 下的classes 文件夹中,并且还希望它所依赖的任何工件(third-dependency、fourth-dependency)仍然包含在我的lib 中文件夹(未解压)。
我尝试了以下方法(不包括我的依赖项中的工件):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.test.dep</groupId>
<artifactId>second-dependency</artifactId>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<includes>**/*</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
这确实在我的classes 文件夹中包含second-dependency 的内容,但在我的主要项目lib 目录中不包含third-dependency 或fourth-dependency。
有什么想法吗?
【问题讨论】:
标签: java maven jar dependencies pom.xml