Vasilii Ruzov
Vasilii Ruzov

Reputation: 554

Build WAR only once during mvn clean package

I have a maven project that should build war file. When I run mvn clean package I see in log that at first it makes default-war:

--- maven-war-plugin:2.3:war (default-war) @ my-artifact---
 Packaging webapp

And after that it makes the war:

--- maven-war-plugin:2.3:war (war) @ my-artifact---
 Packaging webapp

My pom.xml looks like:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.my.group</groupId>
    <version>1.0.0-SNAPSHOT</version>
    <artifactId>my-artifact</artifactId>
    <packaging>war</packaging>

    <dependencies>
        <...>
    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            <addClasspath>true</addClasspath>
                        </manifest>
                        <manifestEntries>
                            <Implementation-Build>${project.artifactId}-${project.version}</Implementation-Build>
                            <Build-Time>${timestamp}</Build-Time>
                            <Implementation-Revision>${myapp.revision}</Implementation-Revision>
                            <Implementation-CommittedRevision>${myapp.committedRevision}</Implementation-CommittedRevision>
                            <Implementation-CommittedDate>${myapp.committedDate}</Implementation-CommittedDate>
                        </manifestEntries>
                    </archive>
                    <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
                </configuration>
                <executions>
                    <execution>
                        <id>war</id>
                        <phase>package</phase>
                        <goals>
                            <goal>war</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

So what I want is to disable building of default-war.

Upvotes: 1

Views: 1228

Answers (1)

Tunaki
Tunaki

Reputation: 137064

You should remove the <executions> tag from the maven-war-plugin configuration. By default, this plugin will execute at the package phase, without any configuration. This would be the correct configuration:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.3</version>
    <configuration>
        <archive>
            <manifest>
                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                <addClasspath>true</addClasspath>
            </manifest>
            <manifestEntries>
                <Implementation-Build>${project.artifactId}-${project.version}</Implementation-Build>
                <Build-Time>${timestamp}</Build-Time>
                <Implementation-Revision>${myapp.revision}</Implementation-Revision>
                <Implementation-CommittedRevision>${myapp.committedRevision}</Implementation-CommittedRevision>
                <Implementation-CommittedDate>${myapp.committedDate}</Implementation-CommittedDate>
            </manifestEntries>
        </archive>
        <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
    </configuration>
</plugin>

Upvotes: 2

Related Questions