使用资源插件从相邻的Maven模块复制静态文件和目录?

时间:2019-03-26 16:05:44

标签: java maven

我有一个与当前模块相邻的模块,并希望从相邻模块中获取一个包含其子级的目录,并将其内容复制到目标目录中。

我想知道在目录指令中获取到相邻家伙的相对路径的最佳方法。

尝试

                    <plugin>
                        <artifactId>maven-resources-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>copy-resources</id>
                                <phase>generate-resources</phase>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${project.build.directory}</outputDirectory>
                                    <resources>
                                        <resource>
                                            <directory>src/main/resources</directory>
                                            <filtering>true</filtering>
                                        </resource>
                                        <resource>
                                            <directory>../adjacent/src/main/docker/</directory>
                                            <filtering>true</filtering>
                                            <includes>
                                                <include>**/*</include>
                                            </includes>
                                            <excludes>
                                                <exclude>**/nodes/**</exclude>
                                                <exclude>**/data/**</exclude>
                                            </excludes>
                                        </resource>
                                        <resource>
                                            <directory>../adjacent/src/main/docker/</directory>
                                            <filtering>false</filtering>
                                            <includes>
                                                <include>**/data/**</include>
                                            </includes>
                                        </resource>
                                    </resources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
    ```

1 个答案:

答案 0 :(得分:0)

您不必显式声明maven-resources-plugin的执行。也可以在default-resources执行中简化POM来实现:

  <build>
    ...
    <resources>

      <resource>
        <targetPath>..</targetPath>  <!--  relative to the target/classes directory
                                           (i.e. ${project.build.outputDirectory}) -->
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>

      <resource>
        <targetPath>..</targetPath>
        <directory>../adjacent/src/main/docker/</directory>
        <filtering>true</filtering>
        <includes>
          <include>**/*</include>
        </includes>
        <excludes>
          <exclude>**/nodes/**</exclude>
          <exclude>**/data/**</exclude>
        </excludes>
      </resource>

      <resource>
        <targetPath>..</targetPath>
        <directory>../adjacent/src/main/docker/</directory>
        <filtering>false</filtering>
        <includes>
          <include>**/data/**</include>
        </includes>
      </resource>

    </resources>
  ...
</build>

对于<directory>The path is relative to the POM.”。因此,../adjacent/src/...可以。

这还有一个优势,即Eclipse m2e插件会考虑这些声明,即,资源是在 Project Clean ... 而不是在仅限Maven构建。