R – Maven WAR plugin not reading configuration when running in tag

maven-2war

I'm trying to get Maven to perform several executions with the WAR plugin. It works fine as long as it's defined in the following way:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
<version>1.0</version>
    <configuration>
    (...)
    </configuration>

But not in the following manner

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>1.0</version>
    <executions>
        <execution>
            <phase>package</phase>
            <configuration>
            (...)
            </configuration>
        </execution>
    </executions>
</plugin>

Where Maven can't find any of the resources I defined in the <configuration> tag. Have I missed anything important, and/or is there a better way of constructing multiple WAR files in a single build?

Best Answer

I didn't see how to turn off the war that's generated by default, but you can use one configuration outside the <executions> element and the rest inside:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1-beta-1</version>
    <configuration>
      <classifier>with-junk</classifier>
      <!-- temp directory that the webapp is assembled in (each must be different) -->
      <webappDirectory>${project.build.directory}/build-with-junk</webappDirectory>
      <webResources>
        <resource>
          <directory>junk</directory>
          <includes>
            <include>**/*</include>
          </includes>
        </resource>
      </webResources>
    </configuration>
    <executions>
      <execution>
        <id>add-other-junk</id>
        <phase>package</phase>
        <goals>
          <goal>war</goal>
        </goals>
        <!-- exclude prior configuration -->
        <inherited>false</inherited>
        <configuration>
          <classifier>with-other-junk</classifier>
          <webappDirectory>${project.build.directory}/build-other-junk</webappDirectory>
          <webResources>
            <resource>
              <directory>other-junk</directory>
              <includes>
                <include>**/*</include>
              </includes>
            </resource>
          </webResources>
        </configuration>
      </execution>
    </executions>
  </plugin>

For me, this builds artifact-0.1-with-junk.war and artifact-0.1-with-other-junk.war and both have the correct files included.

Related Topic