【问题标题】:How to correctly setup a conditional task with Maven-Ant?如何使用 Maven-Ant 正确设置条件任务?
【发布时间】:2016-08-09 02:36:10
【问题描述】:

这里是新的 Ant 用户。我创建了一个条件任务,它作为 Maven Ant 插件在内部运行。我面临的问题是条件目标:在构建过程中找不到“ui-test-condition”。

返回的错误是:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.6:run (uitests) on project myProject: An Ant BuildException has occured: Target "ui-test-condition" does not exist in the project "maven-antrun-". It is used from target "ui-test-run". -> [Help 1]

这表明下面的代码中存在语法错误,但我无法确定问题所在。非常感谢任何帮助。

<target name="ui-test" depends="ui-test-run,ui-test-skip"/>

<target name="ui-test-condition">
  <condition property="ui-test-condition-run">
    <and>
      <istrue value="${ui.test}"/>
  </and>
  </condition>
</target>

<target name="ui-test-run" depends="ui-test-condition" if="ui-test-condition-run">
  <echo>Running tests</echo>
  <exec dir="src/main/webapp/ui" executable="src/main/webapp/ui/${some.executable}"
    resolveexecutable="true" failonerror="true">
    <arg value="-e" />
    <arg value="foo/run" />
  </exec>
</target>

<target name="ui-test-skip" depends="ui-test-condition" unless="ui-test-condition-run">
  <echo>Tests are skipped</echo>
</target>

【问题讨论】:

标签: ant maven


【解决方案1】:

我遇到了完全相同的问题,我发现答案是 maven-antrun-plugin 不支持目标的 depends 属性。

摘自http://maven.apache.org/plugins/maven-antrun-plugin/usage.html

Ultimately, you could specify some Ant <target/> attributes in the <target/> tag. Only depends attribute in Ant <target/> is not wrapped.

这并不妨碍该功能发挥作用,至少从经验来看是这样;只需删除 depends 属性并正确排序目标,它就可以工作。

此外,maven-antrun-plugin 只考虑最后一个target。因此,您需要找到一种方法来直接在该目标中评估您的状况。

【讨论】:

    猜你喜欢
    • 2023-04-06
    • 2012-01-02
    • 2013-01-15
    • 2011-02-07
    • 1970-01-01
    • 1970-01-01
    • 2013-06-19
    • 1970-01-01
    • 2022-06-10
    相关资源
    最近更新 更多