Activate filtering in maven-remote-resources-plugin

618 views Asked by At

To share a resource (a properties file) between multiple projects I want to use the maven-remote-resources-plugin. The shared properties file should be filtered by Maven such that the actual program can retrieve some build-information.

Because the properties file is always the same, my goal is to have a parent pom which handles the processing of that file. The structure of the projects is therefore:

  • resource bundle project (contains the properties file)
  • parent pom
    • Project 1
    • Project 2
    • ...

Ideally the pom.xml of Project X contains no information about the properties file.

Actually I am really close to my goal.

In the parent pom I added:

<plugin>
  <artifactId>maven-remote-resources-plugin</artifactId>
  <version>1.5</version>
  <executions>
    <execution>
      <id>process-remote-resources</id>
      <goals>
        <goal>process</goal>
      </goals>
      <configuration>
        <resourceBundles>
          <resourceBundle>com.gillesB:resourceJar:1.0</resourceBundle>
        </resourceBundles>
        <runOnlyAtExecutionRoot>true</runOnlyAtExecutionRoot>
      </configuration>
    </execution>
  </executions>
</plugin>

I also added the dependency to com.gillesB:resourceJar:1.0.

When I build Project X the properties file is written to target/maven-shared-archive-resources and it is also added to the generated jar. But the placeholders in the file are not replaced with the actual values.

If I add the following to the Project X pom:

<resource>
  <directory>${project.build.directory}/maven-shared-archive-resources</directory>
  <filtering>true</filtering>
</resource>

The properties file in the jar gets filtered. But to achieve this the child pom must be changed.

As I have not seen <resource> in the documentation and the process-goal has its own filter-parameters, I expected that filtering would work out of the box.

Further Information

I checked the debug logs and it seems that the file is copied twice:

[INFO] Copying 1 resource
[DEBUG] file app.properties has a filtered file extension
[DEBUG] filtering D:\projectX\target\maven-shared-archive-resources\app.properties to D:\projectX\target\classes\app.properties
[DEBUG] resource with targetPath null
directory D:\pX\target\maven-shared-archive-resources
excludes []
includes []
[DEBUG] ignoreDelta true
[INFO] Copying 1 resource
[DEBUG] file app.properties has a filtered file extension
[DEBUG] copy D:\projectX\target\maven-shared-archive-resources\app.properties to D:\projectX\target\classes\app.properties
[DEBUG] no use filter components

If I omit the <resource> only the second part appears in the log. After looking for no use filter components the most useful result was the source code. Unfortunately that is not very useful to me.

0

There are 0 answers