12

I'm pretty new to Maven...

What I'm trying to do is skip the maven-deploy-plugin during the deploy phase, while replacing it with my own plugin (i.e. I'm deploying to a non-repository location).

I realize I could do this in multiple other ways, but the boss wants to be able to run:

mvn deploy

To get the results of my current workaround, which is disabling the maven-deploy-plugin (which seems to be disabling the entire deploy phase), and manually specifying the custom upload goal from the command line.

I'm currently failing to succeed in my mission with:

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

in the build/plugins/plugin section containing my plugin specification, since the deploy phase is skipped by:

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

Thanks!

jbeck
  • 2,184
  • 1
  • 19
  • 21

3 Answers3

18

disabling the maven-deploy-plugin (which seems to be disabling the entire deploy phase)

This is not correct. Disabling maven-deploy-plugin doesn't disable the entire deploy phase. This is how it should be done (looks like you're doing it already):

<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-deploy-plugin</artifactId>
        <configuration>
            <skip>true</skip>
        </configuration>
      </plugin>
    </plugins>
  </pluginManagement>
</build>
yegor256
  • 102,010
  • 123
  • 446
  • 597
  • Hi, In case where I'd like to deploy-file instead of deploy, what should be the configuration? – Guru May 09 '19 at 13:55
9

Try this (untested) alternative for disabling the standard deploy plugin:

<plugin>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>2.7</version>
    <executions>
        <execution>
            <id>default-deploy</id>
            <phase>none</phase>
        </execution>
    </executions>
</plugin>
Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
  • 1
    This will work until `maven-deploy-plugin` (in some future version) decides to bind itself to some other execution ID, different from `default-deploy` – yegor256 Oct 08 '12 at 07:18
  • This works and it is useful if you want to replace the standard deploy behavior with e.g. a specific deploy-file execution. – Justin Rowe Feb 03 '14 at 14:14
  • 1
    @yegor256 I agree. Although I would imagine that would be picked up quite quickly during a cautious move to a new version of Maven. – Duncan Jones Feb 03 '14 at 14:15
  • 1
    @JustinRowe But how can I define another deploy execution after I have disabled the deploy plugin? – wings May 13 '15 at 10:56
  • Just add another execution that does what you want in the phase you want – Justin Rowe Jun 01 '15 at 11:44
1

I want to build on @yegor256's answer a bit... 8 years, 4 months later!

I found myself here getting into the weeds on some legacy Maven configurations that were full of cruft. Coming from a Maven mindset, albeit some years between now and active hacking, I was re-familiarizing myself with the Maven lifecycle.

TLDR... mvn help:effective-pom is your friend. Use your IDE's tools for viewing the effective POM often (NetBeans makes it easy. I added a keyboard shortcut in IntelliJ.)

In the configuration I was reviewing, the previous developers had created two (2) deploy-file executions, one war, one 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>

I was aware that these executions would be appended to the default-deploy bound to the deploy phase and observed this behavior in the logs. The default-deploy would run, uploading an empty war file, then the deploy-war would run, uploading, and overwriting, the first war file.

Several options exist.

skip and combine.self="override" (my preference)

As presented, using <skip> as a <configuration> option is viable. It is safe and more portable than setting setting the <phase> to none.

However, it will be inherited by the other executions (certainly as presented). To prevent this, 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>
...
...

Override default-deploy

Another option, possibly more verbose and lest esoteric than combine.self="override" is to override the execution of the default-deploy <id> of the plugin.

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

This will not be inherited by the additional <executions>.

Another option

As @yegor256 notes, but in the additional configurations explicitly state <skip>false</skip> to "reset" the inherited <skip> from the plugin.

HTH.

javafueled
  • 494
  • 1
  • 5
  • 23