【问题标题】:Maven - How can I package sources of all dependencies when packagingMaven - 打包时如何打包所有依赖项的源
【发布时间】:2017-11-06 19:57:52
【问题描述】:
所以我明白了如何使用 jar-with-dependencies 描述符将依赖项打包到可执行 JAR 中。
但是,我还想创建一个源包,它不仅包括我的项目的源,还包括嵌入在我的可执行 JAR 中的所有依赖项的源。
如何做到这一点?
【问题讨论】:
标签:
java
maven
maven-assembly-plugin
maven-source-plugin
【解决方案1】:
这是我最后用的:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>src-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<classifier>sources</classifier>
<failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>
<outputDirectory>${project.build.directory}/sources</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
它将所有已知依赖项的源递归复制到target/source 目录中。很方便!
注意:使用unpack-dependencies 目标来解压缩目标目录中的所有源代码。
参考:https://maven.apache.org/plugins/maven-dependency-plugin/index.html