4

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

Jitesh Vassa
  • 477
  • 5
  • 12
  • Not that this is the reason, but [`basedir` is deprecated in favor of `project.basedir.`](http://maven.apache.org/components/ref/3-LATEST/maven-model-builder/#Model_Interpolation) – Gerold Broser Jun 06 '15 at 16:35
  • Have you tried to add a file extension in `?` – Gerold Broser Jun 06 '15 at 16:49
  • @GeroldBroser thanks for the heads up on [project.basedir](http://maven.apache.org/components/ref/3-LATEST/maven-model-builder/#Model_Interpolation). I've just tried the following includes, but none of them appear to work: `common.txt`, `**/*.txt`, `*.txt`. – Jitesh Vassa Jun 08 '15 at 13:05
  • Can you supply the output of the build? – Gerold Broser Jun 08 '15 at 13:16
  • @GeroldBroser I've added some of the DEBUG output from the build to my original post. – Jitesh Vassa Jun 10 '15 at 12:24

2 Answers2

3

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>
kly
  • 89
  • 1
  • 2
  • Thanks for your suggestion. I'm using the remote resources plugin because I want to be able to pool resources into a single project that can be included by other projects. – Jitesh Vassa Jun 10 '15 at 12:25
  • The [bundle](http://maven.apache.org/plugins/maven-remote-resources-plugin/bundle-mojo.html) goal seems to imply that the plugin should be including those resources: "Bundle up resources that should be considered as a remote-resource." – Jitesh Vassa Jun 17 '15 at 08:50
  • @JiteshVassa By default it **does** include the resources, it just includes the resources in **src/main/resources** directory, as specified in [goal overview](http://maven.apache.org/plugins/maven-remote-resources-plugin/). However, this behavior is not driven by this plugin per se. In your case, you want it to include resources in `${basedir}/common`, so you need to add extra behavior by utilising the way I presented. PS, some plugins do allow you to specify the resources you want to copy, like copy-resources. I think this one just doesn't do that. – kly Jun 17 '15 at 11:07
  • The name "resourcesDirectory" and its [description](http://maven.apache.org/plugins/maven-remote-resources-plugin/bundle-mojo.html#resourcesDirectory) make people think that it would copy the resources. But it doesn't. So one can argue that it is a bug. – kly Jun 17 '15 at 11:48
-1

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.

Rob
  • 100
  • 1
  • 3