【问题标题】:resources not properly copying with maven-dependency-plugin资源无法使用 maven-dependency-plugin 正确复制
【发布时间】:2018-07-09 23:45:30
【问题描述】:

我正在尝试让 maven 将一些资源(特别是 master.css 文件)从 Core 模块复制到所有依赖它的模块中。

我试图在这个问题上使用第一个答案:Use a dependency's resources?

<build>
        <plugins>
            <!--Extract core's resources-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.2</version>
                <executions>
                    <execution>
                        <id>unpack</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeGroupIds>${project.groupId}</includeGroupIds>
                            <includeArtifactIds>core</includeArtifactIds>
                            <excludeTransitive>true</excludeTransitive>
                            <overWrite>true</overWrite>
                            <outputDirectory>${project.build.directory}/core-resources</outputDirectory>
                            <excludes>org/**,META-INF/**,rebel.xml</excludes>
                            <overWriteReleases>true</overWriteReleases>
                            <overWriteSnapshots>true</overWriteSnapshots>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <!--New resource locations-->
        <resources>
            <resource>
                <filtering>false</filtering>
                <directory>${project.build.directory}/core-resources</directory>
            </resource>
            <resource>
                <filtering>false</filtering>
                <directory>${basedir}/src/main/resources</directory>
            </resource>
        </resources>
    </build> 

我将此代码放在 Core 的 pom.xml 文件中(不是父项目——对吗?)/但我遇到了问题——我不确定我是否正确地做所有事情。我在依赖 Core 的模块的目标目录中没有看到任何复制的内容。

这是我 mvn clean install 时该部分的输出:

--- maven-dependency-plugin:2.1:unpack-dependencies (unpack) @ Core ---

--- maven-resources-plugin:3.0.2:resources (default-resources) @ Core ---
Using 'UTF-8' encoding to copy filtered resources.
skip non existing resourceDirectory {project-directory}\Core\target\core-resources
Copying 16 resources

其中 {project-directory} 是我的项目的完整路径。

我的核心资源文件夹如下所示:

src/main/resources
    /core-resources
        master.css
    /fxml
        ~some stuff~
    /imgs
        ~some stuff~
    /styles
        ~some stuff~

我没有在依赖 Core 的模块的目标目录中看到任何复制的内容。

基本上,我有 3 个问题:

从哪里复制?

复制到哪里?

为什么现在不复制任何东西?

如果需要任何其他信息,我可以提供。我不太擅长 maven,老实说,maven 文档对我来说是希腊语。我可能误解了关于 maven 的一些重要内容,所以如果听起来有些奇怪,请告诉我。

【问题讨论】:

  • 你的模块如何表达对core的依赖? core 是否在依赖它的项目的&lt;dependencies&gt; 中列出?如果它是带有父母/孩子的多模块项目,那么只需使用来自依赖孩子的..\core\src\main\resources

标签: java xml maven dependency-management


【解决方案1】:

从哪里复制?

您的担忧来自于 PATH:

<build>
    <plugins>
        <!--Extract core's resources-->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.2</version>
            <executions>
                <execution>
                    <id>unpack</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>unpack-dependencies</goal>
                    </goals>
                    <configuration>
                        <includeGroupIds>${project.groupId}</includeGroupIds>
                        <includeArtifactIds>core</includeArtifactIds>
                        <excludeTransitive>true</excludeTransitive>
                        <overWrite>true</overWrite>
                        <!-- HERE -->
                        <outputDirectory>${project.build.directory}/core-resources</outputDirectory>
                        <excludes>org/**,META-INF/**,rebel.xml</excludes>
                        <overWriteReleases>true</overWriteReleases>
                        <overWriteSnapshots>true</overWriteSnapshots>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <!--New resource locations-->
    <resources>
        <!-- AND HERE -->
        <resource>
            <filtering>false</filtering>
            <directory>${project.build.directory}/core-resources</directory>
        </resource>
        <resource>
            <filtering>false</filtering>
            <directory>${basedir}/src/main/resources</directory>
        </resource>
    </resources>
</build> 

复制到哪里?

他试图复制**/core-resources

为什么现在不复制任何东西?

他尝试阅读以下包**/core-resources

另一个是正确的超出插件版本的

<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>

PS:对不起英语。

【讨论】:

  • 那么我需要改变什么?我在 Core/src/main/resources/core-resources 中有 master.css。我想访问依赖于 Core 的模块中的 master.css。
  • 如果您的 master.css 在您的资源路径中,则其内容将复制到 dest outputDirectory。
  • 我没有看到它被复制到任何地方。我打开 [依赖于核心的模块]/target/classes 并没有看到核心资源。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-26
  • 1970-01-01
  • 2017-05-30
  • 1970-01-01
  • 2011-09-21
  • 1970-01-01
相关资源
最近更新 更多