1

I have a maven project which builds a WAR and then packs it into a zip file which targets a specific deployment tool. I don't want to upload the WAR as it will be a waste of space.

Is it possible to build the WAR but only upload/deploy the zip in the same pom file?

Edit:

No, the "duplicate" question suggested above does not help the slightest. I have to specify <packaging>war</packaging> and even if I don't, as soon as I use the maven war plugin, it's going to make the war as part of the deployment.

And I also want the other artifacts in the build (source, tests, etc.). I just do not need the war.

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
billc.cn
  • 7,187
  • 3
  • 39
  • 79

1 Answers1

4

Here is a suggested approach to deploy the war or the zip, depending on the need:

  • The default build will still provide a WAR as output
  • A profile is added to skip the normal Maven Deploy Plugin execution as part of the deploy phase and add a further execution (obviously not skipped) deploying only the ZIP file via the deploy-file goal, as suggested by @Michal, but not via command line (better as part of the build).

Depending on the need you can of course switch the default behavior from the profile to the default build or even get rid of the default build (just the WAR) at all.

An example:

<build>
    <finalName>test-war-zip</finalName>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4.1</version>
            <configuration>
                <descriptor>src/assembly/descriptor.xml</descriptor>
            </configuration>
            <executions>
                <execution>
                    <id>create-zip</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <id>deploy-zip</id>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                    <executions>
                        <execution>
                            <id>deploy-zip</id>
                            <phase>deploy</phase>
                            <goals>
                                <goal>deploy-file</goal>
                            </goals>
                            <configuration>
                                <skip>false</skip>
                                <file>${project.build.directory}/your.file.here</file>
                                <repositoryId>your.id.here</repositoryId>
                                <url>http://something.here</url>
                                <groupId>${groupId}</groupId>
                                <artifactId>${artifactId}</artifactId>
                                <version>${version}</version>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

Note the global configuration for the Maven Deploy Plugin and its skip to true. It will effectively skip the deploy goal. A further execution will take care of the ZIP file.

With the approach above, executing the normal build, Maven will keep on deploying the generated WAR, while switching on the profile as following:

mvn clean deploy -Pdeploy-zip

Maven will skip the default execution of the Maven Deploy Plugin (its deploy goal) and execute instead the deploy-file goal during the deploy phase.

As part of the build you will then have:

[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ test-war-zip ---
[INFO] Skipping artifact deployment
[INFO]
[INFO] --- maven-deploy-plugin:2.8.2:deploy-file (deploy-zip) @ test-war-zip ---
Uploaded: http://the.repository.here (986 B at 3.9 KB/sec)

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128