我有 Maven 项目。我使用 maven-assembly-plugin 创建 zip 文件,其中包含所有模块依赖项。 需要创建具有以下结构的 zip:
/my-libs
/other-libs
my-libs
需要打包来自my-lib
依赖的依赖+它的所有传递依赖。
TO other-libs
需要从当前 maven 模块中打包所有 other 依赖项。
基本上我需要有条件地选择目标文件夹:
if (dependency in transitive-dependencies(my-lib))
copy to /my-libs
else
copy to /other-libs
是否可以使用 maven-assembly-plugin
?是否有任何替代的 Maven 插件可以这样做?
最佳答案
需要在程序集XML文件中定义两个dependencySet
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
...
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<useTransitiveFiltering>false</useTransitiveFiltering>
<includes>
<include>com.example:dependency1:jar</include>
<include>com.example:dependency2:jar</include>
...
</includes>
<outputDirectory>/my-libs</outputDirectory>
</dependencySet>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<useTransitiveFiltering>false</useTransitiveFiltering>
<includes>
<include>com.example:other1:jar</include>
<include>com.example:other2:jar</include>
...
</includes>
<outputDirectory>/other-libs</outputDirectory>
</dependencySet>
</dependencySets>
...
</assembly>
文档:
http://maven.apache.org/plugins/maven-assembly-plugin/usage.html
http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html
关于java - 将库及其所有依赖项打包到一个文件夹中,但将其他依赖项打包到单独的文件夹中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54557225/