java - maven3-maven-antrun-插件- "failed to create task or type if"

标签 java maven if-statement

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

相关文章:

java - 查询数据库中的对象列表,以便从该列表创建对象 : proper way to do

java - ContainerProvider 的独立 Java Websocket 客户端 NoClassDefFoundError

Python:带加法运算的条件switch语句

R If then do - 如何根据条件创建变量

java - 按钮在按住时更改可绘制

java - 参数匹配器的使用无效。如果此方法使用另一个私有(private)方法,我该如何测试它?

java - 将绝对路径中可用的 jar 文件添加到类路径中

java - 导出仅包含未提供的依赖项的 jar Eclipse Maven 项目

java - 从 pom.xml 生成 .pom 文件的正确方法是什么?

JavaScript IF/ELSE 调用另一个 JS 脚本?