【发布时间】:2014-03-11 07:29:45
【问题描述】:
我想在 Maven 阶段测试期间将文件从 src 目录复制到 test/resource 目录,当且仅当文件在 test/resource 目录中不存在时。有没有人知道我们如何实现这一点?提前感谢
【问题讨论】:
标签: jakarta-ee ant maven-3 maven-plugin
我想在 Maven 阶段测试期间将文件从 src 目录复制到 test/resource 目录,当且仅当文件在 test/resource 目录中不存在时。有没有人知道我们如何实现这一点?提前感谢
【问题讨论】:
标签: jakarta-ee ant maven-3 maven-plugin
这是@Saif Asif 答案的更新版本,它在 Maven3 上对我有用:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>test</phase>
<configuration>
<target>
<taskdef resource="net/sf/antcontrib/antlib.xml" classpathref="maven.dependency.classpath" />
<if>
<available file="/path/to/your/file "/>
<then>
<!-- Do something with it -->
<copy file="/your/file" tofile="/some/destination/path" />
</then>
</if>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
<exclusions>
<exclusion>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.8.1</version>
</dependency>
</dependencies>
</plugin>
感谢https://stackoverflow.com/a/13701310/1410035 提供的“向插件添加依赖项”解决方案。
此示例中值得注意的变化是:
【讨论】:
您可以使用copy-maven-plugin 和runIf 检查文件是否存在。
【讨论】:
使用Maven AntRun plugin 来完成此操作。在你的 pom.xml 中,使用类似
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>test</phase>
<configuration>
<tasks>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
<if>
<available file="/path/to/your/file "/>
<then>
<!-- Do something with it -->
<copy file="/your/file" tofile="/some/destination/path" />
</then>
</if>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
【讨论】: