Question

I am trying to use the maven-remote-resources-plugin to share a number of resources across modules in a multi module maven project. Unfortunately the shared binary resources are being corrupted during bundlling, presumably by filtering.

I am confident the corruption is happening at this stage as extracting the shared-resources jar from my local repository contains broken binary files.

Is there any to switch off filtering for maven-remote-resources-plugin?

At the moment the pom in my shared resources module looks like

<build>
  <plugins>
    <plugin>
       <artifactId>maven-remote-resources-plugin</artifactId>
       <executions>
         <execution>
           <goals>
             <goal>bundle</goal>
           </goals>
         </execution>
       </executions>
       <configuration>
         <includes>
           <include>**/*</include>
         </includes>
       </configuration>
     </plugin>
  </plugins>
</build>

<dependencies>
  <dependency>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-remote-resources-plugin</artifactId>
    <version>1.3</version>
  </dependency>
</dependencies>
Was it helpful?

Solution

It sounds like the resources are being corrupted during bundling. Since the resource project is just a jar it executes the resources plugin as part of the default lifecycle. Try adding this to the resource project's POM.

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.6</version>
    <executions>
      <execution>
        <id>default-resources</id>
        <configuration>
          <nonFilteredFileExtensions>
            <nonFilteredFileExtension>exe</nonFilteredFileExtension>
            <nonFilteredFileExtension>dontFilterMeEither</nonFilteredFileExtension>
          </nonFilteredFileExtensions>
          [...]
        </configuration>
      </execution>
    </executions>
  </plugin>

The docs describe which binary files are left unfiltered by default; the config above adds extensions to the list.

OTHER TIPS

did you try :

<plugin>
        <artifactId>maven-remote-resources-plugin</artifactId>
        <version>1.3</version>
        <executions>
          <execution>
            <id>process-remote-resources</id>
            <goals>
              <goal>process</goal>
            </goals>
            <configuration>
              <useDefaultFilterDelimiters>false</useDefaultFilterDelimiters>
              [...]
            </configuration>
          </execution>
        </executions>
      </plugin>

The approach we've taken to solve this is below.
Note I misunderstood user944849's answer so I have not tested it and it may work.

We created the jar in the local repository directly using a resources clause in the shared-resources pom. I think this is using the maven-resources-plugin (?).

Then used the maven-dependency-plugin to unpack it to a temporary directory, and filtered the desired resources within the resources clause of the resource-consumer pom.

shared-resources

<build>
  <resources>
    <resource>
      <directory>src/main/resources</directory>
      <filtering>false</filtering>
      <includes>
        <include>**/*</include>
      </includes>
    </resource>
  </resources>
</build>

resource-consumer

<build>
  <resources>
    <resource>
      <directory>${project.build.directory}/shared-resources</directory>
      <includes>
        <include>theOnlyOneIWant.properties</include>
      </includes>
    </resource>
  </resources>
  [...]
  <plugins>
    <plugin>
      <artifactId>maven-dependency-plugin</artifactId>
      <version>2.5</version>
      <executions>
        <execution>
          <id>shared-resources</id>
          <goals>
            <goal>unpack-dependencies</goal>
          </goal>
          <phase>generate-resources</phase>
          <configuration>
            <includeGroupIds>myProjectGroup</includeGroupIds>
            <includeArtifactIds>myProjectSharedResources</includeArtifactIds>
            <outputDirectory>$project.build.directory}/shared-resources</outputDirectory>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

This may not work for all instances where the maven-remote-resources-plugin could be used, but it is working for us and solved the issue of binary resource corruption.

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