【问题标题】:How to change location with Maven Dependency Plugin?如何使用 Maven 依赖插件更改位置?
【发布时间】:2020-07-22 06:48:57
【问题描述】:

我需要将一些资源从工件复制到特定位置。 我需要更改位置而不使其变平。

例如:

my-res-artifact
\
 someroot/subdir1/
 + myres1.dat
 + myres2.dat       
 \ 
  subdir12
  + myres3.dat

我想将它复制到subdir1 目录,但删除someroot 根目录。这不适用于以下情况:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>unpack-additional-resources</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
                <includeGroupIds>com.example</includeGroupIds>
                <includeArtifactIds>my-res-artifact</includeArtifactIds>
                <includes>someroot/subdir1/**</includes>
                <outputDirectory>${project.build.directory}</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

目录结构someroot/subdir1/ 被保留。

【问题讨论】:

  • 你为什么要做这样的事情? Spring Boot 就是这样工作的。为什么需要复制资源?
  • @khmarbaise 我有一个很好的理由,这超出了这个问题的分数。我也可以更改示例。
  • 不,它们没有超出范围,因为它们对于您想要实现的目标很重要......

标签: maven build maven-dependency-plugin


【解决方案1】:

文件名可以通过文件映射器更改。

这个技巧也适用于整个地点:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>unpack-additional-resources</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
                <includeGroupIds>com.example</includeGroupIds>
                <includeArtifactIds>my-res-artifact</includeArtifactIds>
                <includes>someroot/subdir1/**</includes>
                <outputDirectory>${project.build.directory}</outputDirectory>
                <fileMappers>
                    <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
                        <pattern>someroot/subdir1</pattern>
                        <replacement>subdir1</replacement>
                    </fileMapper>
                </fileMappers>
            </configuration>
        </execution>
    </executions>
</plugin>

【讨论】:

    猜你喜欢
    • 2013-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-28
    • 2012-06-30
    相关资源
    最近更新 更多