繁体   English   中英

maven3 - maven-antrun-plugin - “无法创建任务或输入if”

[英]maven3 - maven-antrun-plugin - “failed to create task or type if”

我正在尝试在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>

在这里查看我遇到同样问题的问题。

我通过将我的ant-contrib依赖项从插件移动到项目中来解决它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM