Question

I have a multiplatform project which has several language-specific profiles. The HTML-platform-specific module depends on an "assets-core" module and if "en" profile is enabled, an "assets-en" module resources should also be included into WAR.

Assembling WAR works just fine with an exception that if "assets-core" module contains file with the same file name as "assets-en", it is not overwritten by the file from "assets-en" module.

I tried to use maven-resource-plugin:

  <build>
    <resources>
      <resource>
        <directory>${basedir}/assets-en/src/main/resources</directory>
        <includes>
          <include>**/*</include>
        </includes>
      </resource>
    </resources>
  </build>

with

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <id>copy-prod-resources</id>
            <phase>process-resources</phase>
            <goals>
               <goal>copy-resources</goal>
            </goals>
            <configuration>
              <overwrite>true</overwrite>
              <outputDirectory>${basedir}/target/classes</outputDirectory>
              <resources>
                <resource>
                  <directory>${basedir}/assets-ar/src/main/resources</directory>
                  <includes>
                    <include>**/*</include>
                  </includes>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

and <maven.resources.overwrite>true</maven.resources.overwrite> enabled as other threads suggests, but nothing worked.

maven-war-plugin overlays could also be the solution but I can't have resource module to be packaged with <type>war</type> because the same module is also included in Java project.

Here are the relevant parts of my pom.xmls:

asssets-core/pom.xml

<?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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.example</groupId>
    <artifactId>example-parent</artifactId>
    <version>1.0</version>
  </parent>

  <artifactId>assets-core</artifactId>
</project>

assets-en/pom.xml

<?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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.example</groupId>
    <artifactId>example-parent</artifactId>
    <version>1.0</version>
  </parent>

  <artifactId>assets-en</artifactId>
</project>

example-html/pom.xml

<?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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.example</groupId>
    <artifactId>example-parent</artifactId>
    <version>1.0</version>
  </parent>

  <artifactId>example-html</artifactId>
  <packaging>war</packaging>

  <dependencies>
    <dependency>
      <groupId>com.example</groupId>
      <artifactId>example-core</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>com.example</groupId>
      <artifactId>example-core</artifactId>
      <version>${project.version}</version>
      <classifier>sources</classifier>
    </dependency>

    <dependency>
      <groupId>com.example</groupId>
      <artifactId>assets-core</artifactId>
      <version>${project.version}</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        <version>${gwt.version}</version>
        <executions>
          <execution>
            <phase>prepare-package</phase>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>

    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-war-plugin</artifactId>
          <configuration>
            <failOnMissingWebXml>false</failOnMissingWebXml>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

  <profiles>
    <profile>
      <id>en</id>

      <dependencies>
        <dependency>
          <groupId>com.example</groupId>
          <artifactId>assets-en</artifactId>
          <version>${project.version}</version>
        </dependency>
      </dependencies>
    </profile>
  </profiles>
</project>
Was it helpful?

Solution

OK, so I finally have found a solution. You need to get rid of dependencies to modules and copy the resources using maven-resources-plugin:

example-html/pom.xml

<?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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.example</groupId>
    <artifactId>example-parent</artifactId>
    <version>1.0</version>
  </parent>

  <artifactId>example-html</artifactId>
  <packaging>war</packaging>

  <dependencies>
    <dependency>
      <groupId>com.example</groupId>
      <artifactId>example-core</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>com.example</groupId>
      <artifactId>example-core</artifactId>
      <version>${project.version}</version>
      <classifier>sources</classifier>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        <version>${gwt.version}</version>
        <executions>
          <execution>
            <phase>prepare-package</phase>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-assets-core</id>
            <phase>process-resources</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/ExampleProject/</outputDirectory>
              <resources>
                <resource>
                  <directory>${project.parent.basedir}/assets-core/src/main/resources/assets</directory>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>

    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-war-plugin</artifactId>
          <configuration>
            <failOnMissingWebXml>false</failOnMissingWebXml>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

  <profiles>
    <profile>
      <id>en</id>

      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
              <execution>
                <id>copy-assets-en</id>
                <phase>process-resources</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <overwrite>true</overwrite>
                  <outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/ExampleProject/</outputDirectory>
                  <resources>
                    <resource>
                      <directory>${project.parent.basedir}/assets-en/src/main/resources/assets</directory>
                    </resource>
                  </resources>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top