【问题标题】:Maven - maven-remote-resources-plugin not including all resource directoriesMaven - maven-remote-resources-plugin 不包括所有资源目录
【发布时间】:2018-02-18 16:12:20
【问题描述】:

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

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>

【问题讨论】:

  • 首先你在另一个项目中需要什么样的资源?
  • 正如我在另一个问题中已经提到的那样,您似乎走错了路......
  • @khmarbaise 我试图在另一张票的评论中回答这个问题:stackoverflow.com/questions/46133900/…

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


【解决方案1】:

不是 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,但 process-sources 可能会像我认为 resources:resources 一样工作):

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

【讨论】:

  • 我会尝试这些事情并告诉你!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-02-19
  • 1970-01-01
  • 1970-01-01
  • 2013-11-20
  • 2012-07-11
  • 2015-08-20
  • 2014-07-17
相关资源
最近更新 更多