Is there a way to re-assign the value for the Ant property
task? Or is there another task available for that purpose?
相关问题
- How to add optgroups to a django ModelMultipleChoi
- C# How do I create code to set a form back to defa
- VBA Getting date from properties of a text file
- How to use MSbuild property in TransformXml task?
- How can I have my ant task pass or fail based on t
相关文章
- How do do an async ServiceController.WaitForStatus
- Does JavaScript allow getters and setters?
- Notice: Undefined property - how do I avoid that m
- Using the typical get set properties in C#… with p
- Mocking nested properties with mock
- Passing command line arguments to Java via ant bui
- Python - What is a lazy property?
- ANT - Could not load a dependent class com/jcraft/
Properties are immutable in ant. But that's not as terrible a limitation as it may seem. There's a whole class of programming languages where (most) variables are constant and yet they get stuff done this is called "functional programming."
You can "change" values used by different tasks by deriving new, changed properties from old ones, or changing parameters when calling tasks with the
subant
orantcall
tasks. If you're creative you can usually find a way to solve your problem.For the sake of justice, there is a hack that allows to alter ant's immutable properties without any additional libs (since java 6):
Usage:
As others mentioned, this should be used with care after all canonical approaches proved not to fit.
Since Ant 1.8, you can use the "local" task to change the value of a property within a target. Note that this does NOT change the value of the global property with the same name but it is a way to solve some problems.
See
http://ant.apache.org/manual/Tasks/local.html
Depending on how you want to use the modified property, you can use
macrodef
s.For example, instead of writing the following:
and not being able to call
ant foo
with another message, you could write:You can't change the value of a property in Ant.
If you have some Ant tasks you want to run repeatedly passing in different values I recommend the
macrodef
task as you can run the same macro repeatedly passing in different attributes.For example:
Note that
${property}
is used to reference properties and@{attribute}
is used to reference the attributes passed to the<macrodef>
task.Properties are immutable in ant.
You may be interested in ant-contrib's
var
task.