If you need this information during assembly, you should always determine the target name, because most of the time you are inside the target. Thus, you can add a line of code to the target body, which sets the properties / names according to the name. This will be a purely manual approach.
Perhaps you need some kind of general (ordinary) task, say, a line of code that can be copied to any target and determines the current target name. I do not know how to build a property that provides this name. But if you write a custom task and subclass org.apache.tools.ant.Task , then you can get the name of the "parent" target and build the property.
(If apache published the API on the Internet, I was able to give a more accurate answer ...)
EDIT
It is possible from the outside. You can implement a listener and attach it to ant. In this way, the listener will be notified when the goal is entered. But the problem may be to change the property "inside" ant. I do not know if this listener really "lives" in the same virtual machine as the ant stream.
source share