我知道mvn dependency:sources
可以下载所有依赖项的源代码。有了mvn copy-dependencies
一个可以下载所有的依赖到指定的本地目录。
如何结合两者,以便我可以将所有依赖项的源复制到目录中?
我不会使用任何这些解决方案。
只需将maven-dependeny-plugin包含到您的Maven构建中,并根据需要调整配置即可:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<configuration>
<outputDirectory>/tmp/alternateLocation</outputDirectory>
</configuration>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>none</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>/tmp/alternateLocation</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
您可以更改几项以满足您的需要,例如,在我给您的示例中,我认为它直接为您提供了解决方案,我已指定在任何阶段都没有要复制的依赖项在tmp中夹。但是我也说我的新目标是复制依赖性。因此,在命令行中这将类似于:
mvn dependency:copy-dependencies
如果您发现我现在将outputDirectory配置了两次。在执行过程中,这意味着仅当您运行指定的Maven构建阶段(如打包,清理,测试等)时,才会考虑使用它。作为插件节点的第一个子级兄弟,这意味着当命令行显式更改依赖插件时,将考虑使用该插件。
您可以在此处找到有关Maven依赖插件的更多信息:
由于您同时需要依赖项和源,因此我能想到的最好方法是正常运行maven,而无需隐式调用实际插件。如果您在清理后阶段运行它(即mvn清理后),它将运行以下两个目标:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<configuration>
<outputDirectory>/tmp/alternateLocation</outputDirectory>
</configuration>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>post-clean</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>/tmp/alternateLocation</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
<execution>
<id>sources</id>
<phase>post-clean</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<classifier>sources</classifier>
<outputDirectory>/tmp/alternateLocation</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
它将始终将副本复制到目标文件夹,但是如果文件已经存在,则不会覆盖。我必须选择一个不常用的阶段。清洁后似乎是这里的最佳人选。这只是在想我想隔离这种构建。后清理还清理构建。如果您只是想在每次构建时都继续使用此插件,那么我建议您将其置于清理或安装阶段。这样,它总是在后台发生,您不必担心。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句