maven3 - maven-antrun-plugin - “无法创建任务或类型,如果” [英] maven3 - maven-antrun-plugin - "failed to create task or type if"

查看:242
本文介绍了maven3 - maven-antrun-plugin - “无法创建任务或类型,如果”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在maven构建中使用ifant任务。

I'm trying to use "if" ant tasks within maven build.

我发现许多文章建议使用ant-nodeps依赖项。最终所有这些技巧都不适用于maven3 + ant 1.8.1 + maven-antrun-plugin 1.6。

I found many articles that suggest using "ant-nodeps" dependency. Eventually all this tricks did not work on maven3 + ant 1.8.1 + maven-antrun-plugin 1.6.

Ant BuildException出现了:问题:失败创建任务或输入如果

可以提供任何帮助吗?

这是真正的代码(而不是,没有必要,但以防万一):

Here's real code (rather, it is not necessary, but just in case):

 <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任务之前添加此行:

1) Add this line before ant tasks in target section:

<taskdef resource="net/sf/antcontrib/antlib.xml" 
 classpathref="maven.plugin.classpath" />

2)将完全以下依赖项添加到插件中:

2) Add exactly the following dependencies to plugin:

                        <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>

这篇关于maven3 - maven-antrun-plugin - “无法创建任务或类型,如果”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆