tags:

views:

496

answers:

2

Hi,

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"&gt;
    <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&lt;/url&gt;

    <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

+1  A: 

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>
Pascal Thivent
That's right direction but the problem is that I want _'*.war'_ artifact to contain various _'*.properties'_ config files but _'*.zip'_ artifact to contain those files at _'conf'_ directory instead. I.e. it's not possible just to declare dependency to the war-packaged project and build custom standalone delivery unit. However, it seems that I can just generate not single but multiple artifacts from _'war-'_packaged project. Anyway, thanks for the advice.
denis.zhdanov
I don't get it. Do you succeed in creating the zip with the desired content in the war module? If yes, can't you unpack the war and apply the same "assembly logic" in another module?
Pascal Thivent
Agreed. That looks more naturally.
denis.zhdanov
A: 

I am working with a multi-module project. I don't want the artifacts from child modules to be deployed but only the assembled version. I am trying to avoid both the install and deploy phase for child modules. and tags are not working. Can you please provide me guidance as how this can be achieved?

Pavani Challa