首页 > 解决方案 > 资源无法使用 maven-dependency-plugin 正确复制

问题描述

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

我试图在这个问题上使用第一个答案: 使用依赖项的资源?

<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 的一些重要内容,所以如果听起来有些奇怪,请告诉我。

标签: javaxmlmavendependency-management

解决方案


是从哪里抄来的?

您的担忧来自 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:对不起我的英语。


推荐阅读