【发布时间】:2015-03-10 15:22:44
【问题描述】:
在我的 maven pom 中,我有一个额外的 jar 文件,我想将它包含在我的可部署文件中。我已经成功构建了 jar 文件,我想我会使用 maven-deploy-plugin,就像这样(版本方面,我使用的是 dependencyManagement 中的 2.8.2):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<id>deploy-special-jar</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<repositoryId>${project.distributionManagement.repository.id}</repositoryId>
<url>${project.distributionManagement.repository.url}</url>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}-special</version>
<file>${project.build.directory}/special.jar</file>
</configuration>
</execution>
</executions>
</plugin>
这很好用,但有一个小问题。如果您注意到,上面的 pom 使用 project.distributionManagement.repository.url 来作为 repositoryId 和 url 参数。然而,这意味着无论我是构建快照还是发布版本,我总是部署到我的发布区域,这并不理想。如果我正在构建快照怎么办?嗯,答案好像是把project.distributionManagement.repository.url改成project.distributionManagement.snapshotRepository.url
我不喜欢手动更改这些行的想法,因为我喜欢使用 maven-release-plugin 在快照版本和发布版本之间切换。现在,我必须添加一些脚本来每次更改这些行。这是可能的,但并不理想。
似乎有人在 2008 年之前询问过这个确切的问题,并且没有一个很好的答案: http://maven.40175.n5.nabble.com/problems-with-the-maven-deploy-plugin-td107307.html 所以,我想我会在这里添加它,看看人们想出了什么。
我正在考虑使用 build-helper 插件来动态更改此属性,但这似乎是一个潜在的兔子洞,尤其是因为 以前有人试图做类似的事情(出于其他原因,但概念相似): Check if Maven pom is SNAPSHOT
那么,这里的正确答案是什么?这应该是功能请求吗?或者,有没有一种简单的方法可以解决人们使用的这个问题?我很好奇其他人做了什么。有人对 build-helper 插件有任何帮助吗?
谢谢!
【问题讨论】:
-
也许是个愚蠢的问题 .. 为什么这个 jar 的处理方式必须与 maven 为您构建的所有其他 jar 和工件不同?
-
如果确实有必要做一个补充工件(我有疑问),请使用build-helper-maven-plugin,它可以解决所有这些问题,如 url 等。
-
最重要的问题是:special.jar 是如何构建的?由马文?
-
@khmarbaise 是的,它是由 maven 构建的。我目前的情况是我需要制作一个常规 jar 以及第二个 jar 文件,该文件本质上是第一个删除了一些敏感内容的文件。由于这实际上只是第一个 jar 的扩展,我认为最快的方法是复制 jarfile,然后运行 truezip 插件删除正确的部分,然后使用 maven-deploy 重新上传-插入。也许我的方法是错误的?
-
@chrislott 我想我可以添加另一个子项目来生成这个特殊的 jarfile。在我的特殊情况下,想要制作两个 jarfile 似乎更容易,因为特殊的 jar 文件本质上是已经由 maven 构建的 jarfile,但其中的一些内容被删除了。
标签: maven release snapshot maven-deploy-plugin deploying