如何使用目标 unpack-dependencies 仅从 maven-dependency-plugin 的子文件夹中解压文件?

How to unpack just the files from a sub-folder in maven-dependency-plugin with goal unpack-dependencies?

如何将子文件夹中的文件解压到目标文件夹中?

示例:

我的包包括 ThisFolderThatFolder,我只是想将 ThisFolder 中的文件夹和文件解压到目标目录中,而不是文件夹 Thisfolder 本身。

  <plugin>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
      <execution>
        <id>unpack_this</id>
        <goals>
          <goal>unpack-dependencies</goal>
        </goals>
        <phase>initialize</phase>
        <configuration>
          <includeArtifactIds>ZipFile</includeArtifactIds>
          <includes>ThisFolder/**</includes>
          <stripVersion>true</stripVersion>
          <outputDirectory>${project.build.directory}/dependency</outputDirectory>
        </configuration>
      </execution>
    </executions>
  </plugin>

在这个例子中,我已经差不多了,但是 ThisFolder 包括在内。如果我尝试使用:

<excludes>ThisFolder</excludes>

它只是行不通。有解决办法吗?

Maven 依赖插件是为依赖而制作的,即 Java 档案。 Java 存档中的目录结构对于 class 文件的包结构至关重要。所以,很容易理解为什么你的存档中的目录被插件考虑并且不能被抑制。

目前我能想到的最干净的方法是事后复制文件。参见 Best practices for copying files with Maven

(另一种方法是将 Exec Maven 插件与 zip.exe 一起使用,但这会引入外部依赖性。)

对于上面链接的问题,我更喜欢带有 Wagon Maven Plugin's copy goal as described in fnt's answer 的解决方案。