我对Maven很新......
我要做的是在部署阶段跳过maven-deploy-plugin,同时用我自己的插件替换它(即我正在部署到非存储库位置)。
我意识到我可以用其他多种方式做到这一点,但老板希望能够运行:
mvn deploy
获取当前解决方法的结果,即禁用maven-deploy-plugin(似乎禁用整个部署阶段),并从命令行手动指定自定义上载目标。
我目前未能成功完成任务:
<executions>
<execution>
<phase>deploy</phase>
</execution>
</executions>
在包含我的插件规范的build / plugins / plugin部分中,因为部署阶段被跳过:
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
谢谢!
答案 0 :(得分:12)
禁用maven-deploy-plugin(似乎禁用整个部署阶段)
这不正确。禁用maven-deploy-plugin
不会禁用整个部署阶段。这就是它应该如何完成(看起来你已经这样做了):
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
答案 1 :(得分:7)
尝试使用此(未经测试的)替代方法来禁用标准部署插件:
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
答案 2 :(得分:1)
我想以@yegor256 的回答为基础...... 8 年零 4 个月后!
我发现自己在这里陷入了一些充满 cruft 的旧 Maven 配置中。来自 Maven 的思维模式,尽管从现在到积极的黑客攻击已经过去了几年,但我正在重新熟悉 Maven 生命周期。
TLDR... mvn help:effective-pom
是您的朋友。经常使用 IDE 的工具查看有效的 POM(NetBeans 使这很容易。我在 IntelliJ 中添加了一个键盘快捷键。)
在我查看的配置中,以前的开发人员创建了两 (2) 个 deploy-file
执行,一个 war
,一个 jar
。
<build>
...
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<id>deploy-war</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
... omitted ...
</configuration>
</execution>
<execution>
<id>deploy-jar</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
... omitted ...
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
...
</build>
我知道这些执行会附加到 default-deploy
绑定到 deploy
阶段并在日志中观察到这种行为。 default-deploy
会运行,上传一个空的 war 文件,然后 deploy-war
会运行,上传并覆盖第一个 war 文件。
存在多种选择。
skip
和 combine.self="override"
(我的偏好)如上所述,使用 <skip>
作为 <configuration>
选项是可行的。它比将 <phase>
设置为 none
更安全且更便携。
但是,它将被其他执行继承(当然如所呈现的那样)。为防止这种情况发生,you must explicitly tell your additional <execution>
configurations to not inherit。
...
...
<executions>
<execution>
<id>deploy-war</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration combine.self="override">
... omitted ...
</configuration>
</execution>
...
...
default-deploy
另一种选择,可能比 combine.self="override"
更冗长且不太深奥的是插件的 override the execution of the default-deploy
<id>
。
...
<execution>
<id>default-deploy</id>
<configuration>
<skip>true</skip>
</configuration>
</execution>
...
这不会被额外的 <executions>
继承。
正如@yegor256 所指出的,但在附加配置中明确声明 <skip>false</skip>
以“重置”从插件继承的 <skip>
。
HTH。