Question

I have a super pom defined in which I specify a "resources" directory for resources. In one of my projects, my pom extends that super pom, and I would like to add an additional resource. I tried:

    <resources>
        <resource>
            <targetPath>/</targetPath>
            <directory>additionalDir</directory>                
        </resource>
    </resources>

But that results in only additionalDir being in the resources and does not include the super pom's resources. Is there a way to extend the super pom's resources?

Was it helpful?

Solution

The behaviour you've described is expected.

Remember that your super POM is inheriting from Maven's default POM and pretty much any plugin that you define in your pom effectively overrides the setting in the default POM. As an example, to enable filtering on the default resource, you have to specify the path in your POM. You do this:

<resources>
  <resource>
    <directory>src/main/resources</directory>
    <filtering>true</filtering>
  </resource>
</resources>

Not this:

<resources>
  <resource>
    <filtering>true</filtering>
  </resource>
</resources>

The default directory does not bubble up for you, even if you've specified it there. There might be a special MOJO to do it for you, but I couldn't find one.

OTHER TIPS

See build-helper-maven-plugin's usage page.

Yes, maven overrides the parent POM's resources when redefining new resource section.

However, a simple way to add resources is to

  1. Remove the resources section from your POM
  2. Show The effective POM
  3. Copy the resources from your effective POM into your project
  4. Replace absolute paths with relative ones
  5. Add your additional resources

I know this question is pretty old by now but maybe someone will find this usefull:

You can easily do that using the maven resource plugin.

Basically, what it does by default (invoking the resources:resources goal) is moving the content of all directories listed in the build/resources section using the declared filter into the ${project.build.outputDirectory} If you now want to add some additional resources without influencing these sections, you can simply move the resources there yourself. An no, this does not mean drag and dropping it there.

The Maven Resources Pluginprovides a goal named resources:copy-resources that does exactly that for you: Coping files using filters from one place to another, or as the plugin doc states:

You can use the mojo copy-resources to copy resources which are not in the default maven layout or not declared in the build/resources element and attach it to a phase

The obvious advantage compared to the build-helper, that is suggested in other solutions, is that, while the build-helper is only able to take action during the generate-sources phase, the resources plugin works in any phase. (Though it would be wise to execute it before the packaging stage)

A full example on how to use this is provided here, as part of the plugins project page.

What this does is coping the content of the not listed resource directory "src/non-packaged-resources" into "${basedir}/target/extra-resources". But since the jar plugin (that creates the jar archive) basically creates a zip archive of the directory "${project.build.outputDirectory}", you may want to put it there.

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