我正在尝试在 Maven 构建中使用“if”ant 任务。
我发现很多文章建议使用“ant-nodeps”依赖项。最终所有这些技巧在 maven3 + ant 1.8.1 + maven-antrun-plugin 1.6 上都不起作用。
“发生 Ant BuildException:问题:无法创建任务或键入 if”
有什么可以帮忙的吗?
这是真实的代码(相反,这不是必需的,但以防万一):
<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) Add exactly插件的以下依赖项:
<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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)