How to add property tag inside target tag in build.xml file in ant

I have the same source code for 5 projects, and I want to build each project with the same build file in ANT. I want to create code using the name of each project.

+4
source share
2 answers

I suggest you define the targets in the build.xml file called "DEV" and "PROD", and then call Ant as:

ant dev or

ant PROD If you want to stick to your current approach to using a system property to select a target, then @krock's answer seems to be a way. (But I see no advantage in this approach.)

+1
source

userproperty :

ant -f build.xml -Dprojectname=foobar

:

<project>

<echo>$${projectname} => ${projectname}</echo> 

<!-- the real work ... -->

</project>

:

[echo] ${projectname} => foobar

- EDIT -

- , ..:

ant -f build.xml -Dprojectnames=project1,project2,project3

(checkout, compile...) :

<project>

 <macrodef name="foobar">
  <attribute name="projectname"/>
   <sequential>
    <echo>Projectname : @{projectname}</echo>

    <!-- the real work -->

   </sequential>
 </macrodef>

 <script language="javascript">
 <![CDATA[
   var projects = project.getProperty('projectnames').split(',');
   for (i=0; i < projects.length; i++) {
    macro = project.createTask('foobar');
    macro.setDynamicAttribute('projectname', projects[i]);
    macro.perform();
   }
  ]]>
  </script>

</project>

:

[echo] Projectname : project1
[echo] Projectname : project2
[echo] Projectname : project3

ant macrodef.
Javascript Java >= 1.6.0_06, .
, .. xmlproperty , , xmltask (= xmldriven build), xpath.
buildscript.

0

Source: https://habr.com/ru/post/1539388/


All Articles