Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 322
Max Nanasy Avatar asked Aug 24 '12 20:08

Max Nanasy


1 Answers

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.

like image 83
ssloan Avatar answered Oct 19 '22 06:10

ssloan