Using the maven-remote-resources-plugin and specifying the resourcesDirectory

6.3k views Asked by At

I'm trying to override the default resources directory (src/main/resources) when using the maven-remote-resources-plugin. However the specified value in the sample below doesn't seem to be taken into account. Would appreciate if someone could give me some pointers.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>my.resource.library</groupId>
    <artifactId>resource-library</artifactId>
    <version>1.0</version>
    <name>ResourceLibrary</name>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-remote-resources-plugin</artifactId>
                <version>1.5</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>bundle</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <resourcesDirectory>${basedir}/common</resourcesDirectory>
                    <includes>
                        <include>**/*</include>
                    </includes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

EDIT: I'm wondering if this is a bug in the plugin, since I see the following in the DEBUG output of the build, which implies that its attempting to use the correct resources directory. Nothing else relevant appears in the debug output.

[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-remote-resources-plugin:1.5:bundle' with basic configurator -->
[DEBUG]   (f) includes = [**/*]
[DEBUG]   (f) outputDirectory = C:\jit\workspace\ResourceLibrary\target\classes
[DEBUG]   (f) resourcesDirectory = C:\jit\workspace\ResourceLibrary\common

EDIT: I think this may actually be a bug so have raised: MRRESOURCES-96

2

There are 2 answers

4
kly On

Why do you need maven-remote-resources-plugin?

If your goal is to override the default resources directory ,then you can use mvn resources:copy-resources, since it's more flexible. An example here.

Alternative

You can also use the resources goal provided by resources plugin, and specify the resources in pom file's block. Example here.


Edit

About maven-remote-resources-plugin, see the usage page:

This will trigger the scanning of that project's $basedir/src/main/resources directory and create the $basedir/target/classes/META-INF/maven/remote-resources.xml manifest file.

That means this plugin will create the remote-resources.xml file, but it doesn't mean that it will copy the resources for you.

I created an empty maven project using your plugin configuration, and it actually did create an remote-resources.xml file. Also, it did not copy the files under ${basedir}/common

To do that, just specify the resources in build section. Example:

<build>
        <resources>
            <resource>
                <directory>${basedir}/common</directory>
            </resource>
            <resource>
                <directory>${basedir}/src/main/resources</directory>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-remote-resources-plugin</artifactId>
                <version>1.5</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>bundle</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <resourcesDirectory>${basedir}/common</resourcesDirectory>
                    <includes>
                        <include>**/*</include>
                    </includes>
                </configuration>
            </plugin>
        </plugins>
</build>
0
Rob On

kly is right about it not copying resources for you (I apologize, I cannot comment yet - not enough reputation).

With the "bundle" goal, you are only generating a manifest with a list of the included resources. The manifest must be packaged in an artifact along with the resources themselves, which will only happen in your instance if you also use copy-resources to put them in the target/classes directory.

You then must use the "process" goal, and list your bundle, in any other project you wish to use the resources from.