Maven-dependency-plugin: overWrite = false 忽略
Maven-dependency-plugin: overWrite = false ignored
我的问题是我想使用 Maven 从 .jar
文件中提取文件,但前提是文件不存在于输出目录中。因此,如果我有一个文件 /src/META-INF/beans.xml
,那么我只想提取 persistence.xml
,等等
遗憾的是,maven-plugin 忽略了我尝试过的所有与 <overWrite>false</overWrite>
的组合。
问题:知道我做错了什么吗?可能吗?
<build>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>unpack</id>
<phase>validate</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId> ... </groupId>
<artifactId> ... </artifactId>
<version>${project.version}</version>
<outputDirectory>${basedir}/src/META-INF</outputDirectory>
<includes>beans.xml,persistence.xml</includes>
<overWrite>false</overWrite>
</artifactItem>
</artifactItems>
<overWriteIfNewer>false</overWriteIfNewer>
<overWrite>false</overWrite>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteReleases>false</overWriteReleases>
</configuration>
</execution>
</executions>
</plugin>
...
</build>
简单的overWrite
属性其实是插件的doesn't exist as a property,所以直接被插件忽略了
此外,您正在写信给 ${basedir}/src/META-INF
,您的项目,这可能不是最佳选择,但在某些情况下仍然是合理的。
因此您只想在项目的 validate
阶段并且很可能只在第一次构建期间编写一次:也就是说,如果存在,不要再次覆盖它。
对于这些要求,以下可能更适合:
- 使用 Maven profile
对文件使用 activation
选项 missing
:也就是说,如果文件不存在(有史以来第一次)激活将执行您的插件配置的配置文件;当文件已经存在时,不要激活配置文件,任何操作显然不会覆盖任何内容
<profiles>
<profile>
<id>unpack-files</id>
<activation>
<file>
<missing>${basedir}/src/META-INF/beans.xml</missing>
</file>
</activation>
<build>
<plugins>
<!-- move here the maven-dependency-plugin unpack execution -->
</plugins>
</build>
</profile>
</profiles>
因此您仍然可以完全控制此逻辑:
- 没有文件时会激活,先执行
- 它仍然可以按需激活,通过它的
id
(mvn clean install -Punpack-files
)
我的问题是我想使用 Maven 从 .jar
文件中提取文件,但前提是文件不存在于输出目录中。因此,如果我有一个文件 /src/META-INF/beans.xml
,那么我只想提取 persistence.xml
,等等
遗憾的是,maven-plugin 忽略了我尝试过的所有与 <overWrite>false</overWrite>
的组合。
问题:知道我做错了什么吗?可能吗?
<build>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>unpack</id>
<phase>validate</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId> ... </groupId>
<artifactId> ... </artifactId>
<version>${project.version}</version>
<outputDirectory>${basedir}/src/META-INF</outputDirectory>
<includes>beans.xml,persistence.xml</includes>
<overWrite>false</overWrite>
</artifactItem>
</artifactItems>
<overWriteIfNewer>false</overWriteIfNewer>
<overWrite>false</overWrite>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteReleases>false</overWriteReleases>
</configuration>
</execution>
</executions>
</plugin>
...
</build>
简单的overWrite
属性其实是插件的doesn't exist as a property,所以直接被插件忽略了
此外,您正在写信给 ${basedir}/src/META-INF
,您的项目,这可能不是最佳选择,但在某些情况下仍然是合理的。
因此您只想在项目的 validate
阶段并且很可能只在第一次构建期间编写一次:也就是说,如果存在,不要再次覆盖它。
对于这些要求,以下可能更适合:
- 使用 Maven profile
对文件使用
activation
选项missing
:也就是说,如果文件不存在(有史以来第一次)激活将执行您的插件配置的配置文件;当文件已经存在时,不要激活配置文件,任何操作显然不会覆盖任何内容<profiles> <profile> <id>unpack-files</id> <activation> <file> <missing>${basedir}/src/META-INF/beans.xml</missing> </file> </activation> <build> <plugins> <!-- move here the maven-dependency-plugin unpack execution --> </plugins> </build> </profile> </profiles>
因此您仍然可以完全控制此逻辑:
- 没有文件时会激活,先执行
- 它仍然可以按需激活,通过它的
id
(mvn clean install -Punpack-files
)