Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: avoid deploying project package-implied artifact during standard build lifecycle

Tags:

java

maven-2

Is it possible to avoid deploying the artifact that is built according to the project packaging during 'deploy:deploy' processing?

I mean the following:

  • suppose we have a 'pom.xml' for web application and define packaging type as 'war';
  • we want to assemble either '*.war' artifact or '*.zip' that contains our application as well as a servlet container;
  • we want to deploy only that '*.zip' artifact during 'deploy:deploy' processing;

I.e. I want to be able to run 'mvn deploy' and has the following results:

  1. 'myapp.war' is constructed;
  2. 'myapp-standalone.zip' is constructed;
  3. 'myapp-standalone.zip' is deployed to the target remote repository (note that I don't bother if 'myapp.war' is installed to the local repository here);

I checked 'war:war documentation' and found 'primaryArtifact' parameter. However, it mentions only local repository.

I tried the following POM but it still deploys either '*.war' or '*.zip' to remote repository:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.mygroup</groupId>
    <artifactId>myapp</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>myapp</name>
    <url>http://maven.apache.org</url>

    <dependencies>
        <!-- dependencies go here -->
    </dependencies>

    <build>
        <plugins>
            <! -- plugins like 'compiler' etc -->

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <primaryArtifact>false</primaryArtifact>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <id>myapp-standalone</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>src/main/assembly/standalone.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <distributionManagement>
        <repository>
            <-- target repository information -->
        </repository>
        <snapshotRepository>
            <-- target repository information -->
        </snapshotRepository>
    </distributionManagement>
</project>

It seems that I can get desired behavior via declaring project packaging as 'pom' and manually configuring all mojos implied by 'war' packaging ('resources:resources', 'compiler:compile', 'resources:testResources', 'compiler:testCompile', 'surefire:test', 'war:war', 'install:install', 'deploy:deploy'). However, that would make the POM rather verbose and I'd like to avoid that.

As far as I understand, Maven way is to always have an artifact implied by project packaging type as a one of project artifacts. But it's not clear what Maven user is expected to do if he or she wants to get an artifact that is not matched to any default packing types (e.g. single '*.zip' archive).

Any thoughts?

Regards, Denis

like image 896
denis.zhdanov Avatar asked Oct 13 '09 10:10

denis.zhdanov


1 Answers

According to the Maven Deploy Plugin documentation:

deploy:deploy is used to automatically install the artifact, its pom and the attached artifacts produced by a particular project. [...]

So I don't think it's possible to prevent your war from being deployed "as is".

However, to obtain the desired effect, you could add a specific module to your build that would be in charge of producing the assembly (the assembly would depend on the war module) and configure the deploy plugin in the war module to skip deployment as follows:

         <plugin>
           <artifactId>maven-deploy-plugin</artifactId>
           <version>X.Y</version>
           <configuration>
             <skip>true</skip>
           </configuration>
         </plugin>
like image 175
Pascal Thivent Avatar answered Nov 14 '22 23:11

Pascal Thivent