简体   繁体   English

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

[英]Maven - maven-remote-resources-plugin not including all resource directories

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. 我正在使用maven-remote-resources-plugin在其他项目中提供这些资源。 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. 构建之后,来自所有三个资源目录的所有资源都在JAR中。 That's great. 那很棒。 However, remote-resources.xml only contains the resources from src/main/resources . 但是, remote-resources.xml仅包含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? 我尝试使用resourcesDirectory配置属性,但似乎我只能设置一个资源目录? 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>

Not 100% sure, but you could try either something like: 不是100%肯定,但你可以试试像:

<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. 但我不确定remote-resources.xml是否会被合并或覆盖。

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): 您也可以尝试在输出目录的稍后阶段执行插件(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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM