Reasons for using Ant Properties files over “Properties Tasks”

拥有回忆 提交于 2019-12-03 19:07:19

Properties tasks tightly couple the build file to environments. If your fellow developers are arguing that they "have to change their ant script" with your suggestions, why aren't they arguing about changing it every time they have to deploy to a new environment? :)

Perhaps you can convince them to allow both properties file and command-line configuration. I set up my Ant builds so that if a build.properties exists in the same directory as the build.xml, it reads it in. Otherwise it uses a set of default properties hard-coded into the build. This is very flexible.

<project name="example">

    <property file="build.properties"/>

    <property name="foo.property" value="foo"/>
    <property name="bar.property" value="bar"/>

    ...
</project>

I don't provide a build.properties with the project (i.e. build.properties is not versioned in SCM). This way developers aren't forced to use the property file. I do provide a build.properties.example file that developers can reference.

Since Ant properties, once set, are immutable, the build file will use properties defined in this order:

  • Properties provided with -D or -propertyfile via the command line
  • Properties loaded from build.properties
  • Default properties within build.xml

Advantages of this approach:

  • The build file is smaller and therefore more maintainable, less bug-prone
  • Developers that just can't get away from setting properties at the command line can still use them.
  • Properties files can be used, but aren't required

The arguments you have are already pretty compelling. If those arguments haven't worked, then arguing isn't going to solve the problem. In fact, nothing is going to solve the problem. Don't assume that people are rational and will do the most practical thing. Their egos are involved.

Stop arguing. Even if you win, the resentment and irritation you create will not be worth it. Winning an argument can be worse than losing.

Make your case, then let it go. It's possible that after a while they will decide to switch to your way (because it actually is better). If that happens, they will act like it was their own idea. There will be no mention of your having proposed it.

On the other hand, they may never switch.

The only solution is to work towards a position of authority, where you can say how things are to be done.

The problem with the first solution (using ant property) is basically hardcoding. It can be convenient when you start a project for yourself but quickly you have to remove that bad habit.

I'm using a property file close to what said robhruska except that I have committed the build.properties file directly. This way you have a default one.

In other hand, I understand I could add those default values in the build.xml. (I will probably try that in the next hours/days ;-) ).

Anyway, I really don't like the first approach and I would force those guys to follow the second one ...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!