Question

I am new to maven. I want to use filtering in a multimodule project. The packaging type of the parent pom is set to pom. The structure of the project is as follows:

pom.xml
     |
     |______MODULE1
     |       |
     |       pom.xml
     |       File1_needed_to_be_filtered
     |
    File2_needed_to_be_filtered

Please note that Module1 is also multimodule project. So please tell me how can I apply filtering to file1 and file2. And if i apply filtering to file1, then where will the processed file be stored (Since pom file whose packaging type is pom do not create any folder named target!) Please help me as this is very critical to me and this issue is addressed nowhere else on the internet.

Was it helpful?

Solution

You could use the maven-assembly-plugin - with a 'dir' format (although if there is ever more than one file, it might make sense to make it an archive of some kind). The descriptor format allows you to filter. This should work with the pom and file hierarchy you describe above.

However, I would recommend putting these in sibling modules instead of the parent. This keeps the logic out of your aggregator pom, and (once you start doing that) you might decide it's easier to use the assembly to distribute them along with your other components, which you'd want a module for anyway.

OTHER TIPS

To have Maven filter resources when copying, set filtering to true for the resource directory in your pom.xml:

<project>
  ...
  <build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filterineg>
      </resource>
    </resources>
  </build>
</project>

But if you want to filter resources, don't put them in a project with a packaging of type pom, this doesn't make sense (for the reason you gave yourself). Actually, I don't understand what you're trying to achieve (since you know this is not how things work).

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