如何将子文件夹中的文件解压到目标文件夹中?
示例:
我的包包含 ThisFolder
和 ThatFolder
,我只想将 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 归档文件内的目录结构对于类文件的包结构至关重要。因此,很容易理解为什么插件会考虑存档中的目录并且无法抑制它们。
目前我能想到的最简洁的方法是随后复制文件。请参阅Best practices for copying files with Maven .
(另一种方法是将 Exec Maven 插件与 zip.exe
一起使用,但这会引入外部依赖项。)
我更喜欢 Wagon Maven Plugin's copy
goal 的解决方案如 fnt's answer 中所述回答上面链接的问题。
关于maven - 如何使用目标 unpack-dependency 解压 maven-dependency-plugin 中子文件夹中的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48623388/