kc2001
kc2001

Reputation: 5247

How can I exclude certain overlay-derived directories from my war using maven?

We build a webapp using maven 3.5.0 and the maven-war-plugin. We have many overlays, many of which have a tests directory that contains JSP files used for testing certain things in a dev environment. We don't want these included in our war.

We tried the following:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1</version>
    <configuration>
        <overlays>...</overlays>
        <warSourceExcludes>tests</warSourceExcludes>
    </configuration>
</plugin>

This didn't work, nor did a couple of configuration variations:

<packagingExcludes>tests</packagingExcludes>

and

<packagingExcludes>**/${project.artifactId}/tests/**</packagingExcludes>

Is this due to my naive misuse of configuration options, or does it have to do with how overlays are processed?

Upvotes: 0

Views: 960

Answers (2)

kc2001
kc2001

Reputation: 5247

The dependentWarExcludes element worked to eliminate the tests directories and their contents:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <overlays>...</overlays>
        <dependentWarExcludes>tests/**</dependentWarExcludes>
    </configuration>
</plugin>

Upvotes: 0

khmarbaise
khmarbaise

Reputation: 97359

You should use <excludes>..</excludes> (see https://maven.apache.org/plugins/maven-war-plugin/overlays.html) instead of <packagingExcludes>..</packagingExclude>...

 ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.2</version>
        <configuration>
          <overlays>
            <overlay>
              <groupId>com.example.projects</groupId>
              <artifactId>documentedprojectdependency</artifactId>
              <excludes>
                <exclude>WEB-INF/classes/images/sampleimage-dependency.jpg</exclude>
              </excludes>
            </overlay>
          </overlays>
        </configuration>
      </plugin>
    </plugins>
  </build>
  ...

Upvotes: 1

Related Questions