Maven - maven-remote-resources-plugin不包括所有资源目录

时间:2017-09-10 07:43:19

标签: java maven maven-resources-plugin maven-remote-resources

我有一个包含多个资源目录的项目:

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

我将这些资源目录声明如下:

<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>

我正在使用maven-remote-resources-plugin在其他项目中提供这些资源。我使用这个插件如下:

<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>

构建之后,来自所有三个资源目录的所有资源都在JAR中。那很棒。但是,remote-resources.xml仅包含来自src/main/resources的资源。我该如何解决这个问题?

我尝试使用resourcesDirectory配置属性,但似乎我只能设置一个资源目录?我可以设置这个属性如下,但这看起来像一个丑陋的黑客:

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

1 个答案:

答案 0 :(得分:0)

不是100%肯定,但您可以尝试以下内容:

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

或尝试不同的执行:

    <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>

但我不确定是否会合并或覆盖remote-resources.xml。

您也可以尝试在输出目录的later phase中执行插件(prepare-package是安全的,但是进程源可能与我认为资源一样有效:资源将首先执行):

    <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>