Can I make a Maven profile add webResources to a war and still add non-profiled webResources?

StackOverflow https://stackoverflow.com/questions/12115908

  •  28-06-2021
  •  | 
  •  

Question

Example:

I would hope and expect the following pom to deploy both profileResources and commonResources when the "profile" profile is active, but it deploys only profileResources. What can I do to achieve the desired effect?

<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.example</groupId>
  <artifactId>test</artifactId>
  <packaging>war</packaging>
  <version>0.0.0</version>
  <profiles>
    <profile>
      <id>profile</id>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
              <webResources>
                <resource>
                  <directory>src/main/profileResources</directory>
                </resource>
              </webResources>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1.1</version>
        <configuration>
          <webResources>
            <resource>
              <directory>src/main/commonResources</directory>
            </resource>
          </webResources>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Working Version (for future reference)

<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.example</groupId>
  <artifactId>test</artifactId>
  <packaging>war</packaging>
  <version>0.0.0</version>
  <profiles>
    <profile>
      <id>profile</id>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
              <webResources>
                <resource>
                  <directory>src/main/profileResources</directory>
                </resource>
              </webResources>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1.1</version>
        <configuration>
          <webResources combine.children="append">
            <resource>
              <directory>src/main/commonResources</directory>
            </resource>
          </webResources>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Git Word Diff Between Broken and Working Versions

diff --git a/tmp/broken-pom.xml b/tmp/working-pom.xml
index 2fd9bbf..b04683f 100644
--- a/tmp/broken-pom.xml
+++ b/tmp/working-pom.xml
@@ -31,5 +31,5 @@
        <version>2.1.1</version>
        <configuration>
          <webResources{+ combine.children="append"+}>
            <resource>
              <directory>src/main/commonResources</directory>
Was it helpful?

Solution

Try adding combine.children="append" to the resources element in the non-profile plugin- I think it's messing up because the default behaviour means the profile settings will override anything with the same name higher up the tree. See http://maven.apache.org/pom.html#Plugins for details on merging/appending attributes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top