Maven - maven-remote-resources-plugin not including all resource directories

592 views Asked by At

I have a project with multiple resource directories:

src/main/resources
src/main/generator
src/main/generator2

I declare these resource directories as following:

<build>
    <resources>
        <resource>
            <directory>${basedir}/src/main/resources</directory>
        </resource>
        <resource>
            <directory>${basedir}/src/main/generator</directory>
        </resource>
        <resource>
            <directory>${basedir}/src/main/generator2</directory>
        </resource>
    </resources>
    ....
</build>

I am using maven-remote-resources-plugin to make these resources available in other projects. I am using this plugin as following:

<build>
    <resources>
        <resource>
            <directory>${basedir}/src/main/resources</directory>
        </resource>
        <resource>
            <directory>${basedir}/src/main/generator</directory>
        </resource>
        <resource>
            <directory>${basedir}/src/main/generator2</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>
                <includes>
                    <include>**/*</include>
                </includes>
            </configuration>
        </plugin>
    </plugins>
</build>

After building, all resources from all three resource directories are in the JAR. That's great. However, remote-resources.xml only contains the resources from src/main/resources. How can I fix this?

I tried playing around with the resourcesDirectory configuration property, but it seems I can only set one resource directory? I could set this property as following, but this seems like an ugly hack:

<configuration>
    <resourcesDirectory>${basedir}/src/main</resourcesDirectory>
    <includes>
        <include>**/*</include>
    </includes>
</configuration>
1

There are 1 answers

1
Puce On

Not 100% sure, but you could try either something like:

<configuration>
    <resourcesDirectory>${basedir}/src/main</resourcesDirectory>
    <includes>
        <include>resources/**/*</include>
        <include>generator/**/*</include>
        <include>generator2/**/*</include>
    </includes>
</configuration>

or try different executions:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-remote-resources-plugin</artifactId>
        <version>1.5</version>
        <executions>
            <execution>
                <id>bundle-resources</id>
                <goals>
                    <goal>bundle</goal>
                </goals>
            </execution>
            <execution>
                <id>bundle-generator</id>
                <goals>
                    <goal>bundle</goal>
                </goals>
                <configuration>
                    <resourcesDirectory>${basedir}/src/main/generator</resourcesDirectory>
                </configuration>
            </execution>
            <execution>
                <id>bundle-generator2</id>
                <goals>
                    <goal>bundle</goal>
                </goals>
                <configuration>
                    <resourcesDirectory>${basedir}/src/main/generator2</resourcesDirectory>
                </configuration>
            </execution>
        </executions>
    </plugin>

but I'm not sure if remote-resources.xml will be merged or overwritten.

You could also try to execute the plugin in a later phase on the output directory (prepare-package to be safe, but process-sources might work as well as I think resources:resources will be executed first):

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-remote-resources-plugin</artifactId>
        <version>1.5</version>
        <executions>
            <execution>
                <id>bundle-resources</id>
                <phase>prepare-package</phase>
                <goals>
                    <goal>bundle</goal>
                </goals>
                <configuration>
                    <resourcesDirectory>${project.build.outputDirectory}</resourcesDirectory>
                    <includes>
                        <include>file1</include>
                        <include>file2</include>
                    </includes>
                </configuration>
            </execution>
        </executions>
    </plugin>