我想在maven阶段测试期间将文件从src目录复制到test / resource目录,当且仅当test / resource目录中不存在该文件时。是否有人知道如何实现这一目标?感谢Advance < / p>
答案 0 :(得分:2)
这是@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为&#34;添加了对插件的依赖&#34;溶液
这个例子中值得注意的变化是:
答案 1 :(得分:1)
您可以copy-maven-plugin
与runIf
一起使用,检查文件是否存在。
答案 2 :(得分:0)
使用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>