Question

I am trying to use the maven-remote-resources-plugin as per this example to selectively share common resources between multiple maven modules and I'm having a lot of difficulty getting the selective import of the resources to work.

I am trying to use <includes> and <excludes> elements as per below. I haven't seen these mentioned in doco for the plugin anywhere but eclipse provides them as valid options in the command completion and I don't get any errors when I run the pom. So far I haven't been able to get <includes> or <excludes> to have any effect at all on the imported resources

The relevant sections of my pom are;

Shared resources

<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>

Resource consumer

<build>
 ...
  <plugins>
    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-remote-resources-plugin</artifactId>
       <version>1.3</version>
       <configuration>
         <resourceBunldes>
           <resourceBundle>myApp:myApp_sharedresources:${project.version}</resourceBundle>
         </resourceBundles>
         <outputDirectory>${project.build.outputDirectory}</outputDirectory>
         <includes>
           <include>theOnlyResourceIWant.properties</include>
         </includes>
       </configuration>
       <executions>
         <execution>
           <goals>
             <goal>process</goal>
           </goals>
           <phase>generate-resources</phase>
         </execution>
       </executions>
     </plugin>
  </plugins>
</build>

<dependencies>
  <dependency>
    <groupId>myApp</groupId>
    <artifactId>myApp_sharedresources</artifactId>
    <version>1.0</version>
  </dependency>
</dependencies>

I've tried many combinations of <includes> and <excludes> but all so far have had no impact.

So, are

<includes></includes>

and

<excludes></excludes>

valid elements for a maven-remote-resources-plugin configuration, and how do I use them? I can reasonably seperate the resources out into seperate maven modules, but that could create a large number of single file maven modules and add a lot of extra xml so I'd like to avoid it if possible.

I'd really rather not start pawing through the plugin source code, but that is the next step.

Was it helpful?

Solution

I use a temp directory for the shared resources I'm importing and filter that.

Remote resource plugin configuration below. This copies all the shared resources into a temp directory in your project. Setting attached to false means they are not included in your final project artifact, which gives you the opportunity to select the ones you want to include using Maven's normal resource processing.

<plugin>
<artifactId>maven-remote-resources-plugin</artifactId>
<configuration>
  <resourceBundles>
    <resourceBundle>myApp:myApp_sharedresources:${project.version}</resourceBundle>
  </resourceBundles>
  <attached>false</attached>
  <outputDirectory>${project.build.directory}/shared-resources</outputDirectory>
</configuration>
<executions>
   <execution>
     <goals>
       <goal>process</goal>
     </goals>
     <phase>generate-resources</phase>
   </execution>
 </executions>
</plugin>

Resource definition. When the maven-resource-plugin runs (it is bound to the lifecycle by default for jars/wars/ears), it will use the shared resource directory as well as the normal src/main/resources dir. You need to define both. (You may also enable resource filtering if you want.)

<resources>
  <resource>
     <directory>${project.build.directory}/shared-resources</directory>
     <includes>
       <include>theOnlyResourceIWant.properties</include>
     </includes>
  </resource>
  <resource>
     <directory>${basedir}/src/main/resources</directory>
  </resource>
</resources>

I recommend making the shared directory be a subdirectory of ${project.build.directory}, so the clean lifecycle works without changes.

OTHER TIPS

To enable the filter delimiters for the format '#{expr}' (Ruby-style), add the following to your plugin configuration:

<plugin>
    <artifactId>maven-remote-resources-plugin</artifactId>
    <version>1.3</version>
    <executions>
      <execution>
        <id>process-remote-resources</id>
        <goals>
          <goal>process</goal>
        </goals>
        <configuration>
          <filterDelimiters>
            <filterDelimiter>#{*}</filterDelimiter>
          </filterDelimiters>
          [...]
        </configuration>
      </execution>
    </executions>
  </plugin>

Check this link for reference

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