缺少file/build.properties时的Ant警告/失败?

Ben*_*age 4 ant build-process

我的团队ant任务build.properties通过使用属性文件标记从文件中提取特定于开发人员的信息:

<property file="${user.home}/build.properties.txt" />
Run Code Online (Sandbox Code Playgroud)

但是,当缺少此文件时,无论如何都会继续执行.稍后在构建过程中,它会尝试访问尚未定义的属性,并尝试登录svn服务器${user.name}以及其他类似错误.这些错误很难调试,因为我使用的一些ant任务没有提供有用的错误消息.

我的主要问题是:如果无法找到属性文件,有没有办法让ant快速失败?

oer*_*ers 8

我认为你可以结合使用和失败:

如果存在File,则设置属性

<available file="${user.home}/build.properties.txt" property="build.properties.present"/>
Run Code Online (Sandbox Code Playgroud)

如果未设置属性,则会失败

<fail unless="build.properties.present"/>
Run Code Online (Sandbox Code Playgroud)


dev*_*ity 8

您可以先添加显式检查.就像是:

<fail message="Missing build.properties">
  <condition>
    <not>
      <available file="${user.home}/build.properties.txt" />
    </not>
  </condition>
</fail>
Run Code Online (Sandbox Code Playgroud)

可能会做的伎俩.


Ale*_*yak 5

我建议,不要测试特定属性文件的存在,测试属性定义.这样,可以以不同方式提供此属性(例如as -Duser.name=myname).

您可以在失败消息中提供建议的文件名.

例如

<fail message="user.name property is not set.
    It is usually defined in ${user.home}/build.properties.txt">
  <condition>
    <not><isset property="user.name"/></not>
  </condition>
</fail>
Run Code Online (Sandbox Code Playgroud)