我可以修改Maven的部署阶段,用自己的插件替换maven-deploy-plugin吗?

12

我对Maven比较陌生...

我的目标是在部署阶段跳过maven-deploy-plugin,同时替换为自己的插件(即我要将其部署到非存储库位置)。

我意识到可以用多种其他方式来实现这一点,但老板希望能够运行:

mvn deploy

以获得当前解决方法的结果,该方法是禁用maven-deploy-plugin(似乎禁用了整个部署阶段),并从命令行手动指定自定义上传目标。

目前我未能成功完成任务:

<executions>
    <execution>
        <phase>deploy</phase>
    </execution>
</executions>

在 build/plugins/plugin 部分包含了我的插件规范,因为 deploy 阶段被跳过了:

        <plugin>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>2.7</version>
            <configuration>
                <skip>true</skip>
            </configuration>
        </plugin>

谢谢!

3个回答

18

禁用maven-deploy-plugin(似乎会禁用整个deploy阶段)

这是不正确的。禁用maven-deploy-plugin并不会禁用整个deploy阶段。应该采取以下方式进行操作(看起来你已经这样做了):

<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-deploy-plugin</artifactId>
        <configuration>
            <skip>true</skip>
        </configuration>
      </plugin>
    </plugins>
  </pluginManagement>
</build>

嗨,如果我想使用deploy-file而不是deploy进行部署,应该如何配置? - Guru

9

尝试使用以下(未经测试的)替代方法来禁用标准部署插件:

<plugin>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>2.7</version>
    <executions>
        <execution>
            <id>default-deploy</id>
            <phase>none</phase>
        </execution>
    </executions>
</plugin>

1
这将有效,直到“maven-deploy-plugin”(在某个未来版本中)决定将自己绑定到与“default-deploy”不同的其他执行ID。 - yegor256
这个功能非常实用,如果你想要替换标准的部署行为,例如使用特定的部署文件执行。 - Justin Rowe
1
@yegor256 我同意。虽然我想,在对Maven的新版本谨慎迁移过程中,这应该会很快被注意到。 - Duncan Jones
1
@JustinRowe 但是在我禁用部署插件之后,我如何定义另一个部署执行呢? - wings
只需添加另一个执行步骤,以在所需的阶段执行您想要的操作。 - Justin Rowe

1
我希望在 @yegor256 的回答上进一步完善... 8年4个月后!
我发现自己陷入了一些遗留的Maven配置细节中,这些细节充满了cruft。尽管现在和当时的活跃开发之间隔了几年时间,但出于Maven的思维方式,我正在重新熟悉Maven生命周期。
简而言之... 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>

我知道这些执行将附加到绑定到“deploy”阶段的“default-deploy”中,并在日志中观察到了这种行为。默认部署将运行,上传一个空的war文件,然后“deploy-war”将运行,上传并覆盖第一个war文件。
有几个选项可用。
“跳过”和“combine.self =“override””(我的首选)
如所示,使用“”作为“”选项是可行的。它比将“”设置为“none”更安全、更便携。
但是,它将被其他执行继承(当然是按照所示的方式)。为了防止这种情况,您必须明确告诉您的其他配置不要继承
...
...
      <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"更冗长且不那么神秘的选项是覆盖插件的<id>执行的default-deploy

...
        <execution>
          <id>default-deploy</id>
          <configuration>
            <skip>true</skip>
          </configuration>
        </execution>
...

这将不会被额外的<executions>继承。

另一个选项

正如@yegor256所指出的那样,但是在额外的配置中明确声明<skip>false</skip>以“重置”插件继承的<skip>

希望这有帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接