views:

43

answers:

2

I never quite understood this, since the name attribute appears to support spaces, but every example uses the harder to read period to name targets.

Why do this:

<target name="some.target.name">
<!-- target child nodes -->
</target>

When you can do this:

<target name="Some Target Name">
<!-- target child nodes -->
</target>

Was there some reason for this, or is it a technical constraint? The same goes for build properties. They're always using some dot notation.

+4  A: 

if you have spaces in your target name, you will need to wrap them in quotes from the command line or the processor will handle them like multiple targets.

Try this: build.xml:

<project name="MyProject" default="some target name" basedir=".">
  <target name="some target name">
    <echo>reached some target name with spaces</echo>
  </target>
  <target name="some">
    <echo>reached some</echo>
  </target>
  <target name="target">
    <echo>reached target </echo>
  </target>
  <target name="name">
    <echo>reached name</echo>
  </target>
</project>

running ant some target name with spaces, you get the following:

Buildfile: build.xml

some:
     [echo] reached some

target:
     [echo] reached target 

name:
     [echo] reached name

BUILD SUCCESSFUL
Total time: 0 seconds

but with quotes, it is handled differently: ant "some target name"

Buildfile: build.xml

some target name:
     [echo] reached some target name with spaces
akf
+7  A: 

One reason might be that it's easier to specify a build target on a command line if it doesn't have spaces. With spaces, you'd have to put quotes around the whole target name.

Greg Hewgill
I also use this to split my build scripts into different ones, having a master (`build.xml`) and several children. The rule is that all the children scripts have their targets starting with the filename. For example, `test.execute` is the target named `execute` in the file `test.xml`.I find it easier to manage and find where the targets are located.
Vladimir