我正在尝试在 Maven 构建中使用“if”ant 任务。
我发现很多文章建议使用“ant-nodeps”依赖项。最终,所有这些技巧在 maven3 + ant 1.8.1 + maven-antrun-plugin 1.6 上都不起作用。
“发生 Ant BuildException:问题:创建任务或类型失败”
有什么帮助吗?
这是真实的代码(不是必需的,但以防万一):
<profiles>
<profile>
<id>smtpConfigurationProfile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<if>
<isset property="${smtpFile}"/>
<then>
<delete file="${project.build.outputDirectory}/smtp.properties"/>
<copy file="${smtpFile}"
tofile="${project.build.outputDirectory}/smtp.properties"/>
</then>
<elseif>
<isset property="${smtpProfile}"/>
<then>
<delete file="${project.build.outputDirectory}/smtp.properties"/>
<copy file="src/main/resources/${smtpProfile}.smtp.properties"
tofile="${project.build.outputDirectory}/smtp.properties"/>
</then>
<else>
<delete file="${project.build.outputDirectory}/smtp.properties"/>
<copy file="src/main/resources/production.smtp.properties"
tofile="${project.build.outputDirectory}/smtp.properties"/>
</else>
</elseif>
</if>
</tasks>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.8.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
</profiles>
最佳答案
1) 在目标部分的 ant 任务之前添加此行:
<taskdef resource="net/sf/antcontrib/antlib.xml"
classpathref="maven.plugin.classpath" />
2) 添加完全以下依赖到插件:
<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>
关于java - maven3-maven-antrun-插件- "failed to create task or type if",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4760120/