Pavan
Pavan

Reputation: 9

Set a default value for fork in javac ant

I have a requirement of using fork=true through out my build. i am looking at setting it globally and use it across my build machine. Help appreciated.

Upvotes: 1

Views: 867

Answers (2)

Chad Nouis
Chad Nouis

Reputation: 7041

Ant's <presetdef> declares new tasks based on existing tasks.

The following fragment defines a <javac> task with the fork attribute set:

<presetdef name="my-javac">
   <javac fork="yes"/>
</presetdef>

<my-javac> can be called with any of <javac>'s attributes:

<my-javac srcdir="${my.src}" deprecation="no"/>

A word of warning: Specifying the fork attribute in a call to <my-javac> will override the fork attribute specified in the <presetdef>:

<!-- Overrides my-javac's default fork attribute -->
<my-javac srcdir="${my.src}" deprecation="no" fork="no"/>

<presetdef> is only useful for setting defaults, not for enforcing requirements.

Upvotes: 4

Dante WWWW
Dante WWWW

Reputation: 2739

No. There is no such kind of global switch.

If you have many javac in your build file, consider:

Solution 1:

<property name="fork" value="yes" />

and then, in any place that you call javac,

<javac ... fork="${fork}" ....>

Solution 2:

The automatically generated ant build file of Netbeans project uses this: wrap javac using a macrodef, and then use this macrodef in the build file.

You can check any Netbeans project, for build-impl.xml in the nbproject folder.

Upvotes: 1

Related Questions