代码之家  ›  专栏  ›  技术社区  ›  MattT

未使用maven依赖插件正确复制资源

  •  0
  • MattT  · 技术社区  · 6 年前

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

    我试图用这个问题的第一个答案: 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> 
    

    以下是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~
    

    在依赖于核心的模块的目标目录中,我没有看到任何被复制的内容。

    基本上,我有三个问题:

    它是从哪里复制的?

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

    1 回复  |  直到 6 年前
        1
  •  0
  •   jguyet    6 年前

    它是从哪里复制的?

    你的烦恼来自路径:

    <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

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

    他试着阅读下面的包裹 **/核心资源

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

    PS:对不起我的英语。