Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override the compiler attribute in an Ant javac task

Tags:

ant

I'm trying to override Ant compiler attributes via the command line so that all 'javac' tasks use my specified compiler. The problem I've run into is that any target that sets its own value for compiler overrides the one that I set at the commmand line. So, even though I'm entering the following command.

ant -Dbuild.compiler=mycompiler  

Any target that has the following is going to use the modern compiler instead of mycompiler because of that compiler="modern" attribute

<javac srcdir="."  
       destdir="${classes.dir}/core"  
       compiler="modern"  
       encoding="UTF-8">  
    <include name="org/**" />  
    <include name="com/**" />  
    <compilerarg line="${config.build.compilerarg}" />  
</javac>    

Is there any way to override this from the command line, or am I stuck editing the build file?

like image 850
Aaron Avatar asked Oct 24 '08 21:10

Aaron


People also ask

Which Ant task does the Java compiling?

Ant Javac task is used to compile Java source file. It scans source and destination directory to compile the source file. It only compiles if either . class is not present or .

What is javac task?

Description. Compiles a Java source tree. The source and destination directory will be recursively scanned for Java source files to compile.

Where does javac compile to?

By default, javac compiles each source file to a class file in the same directory as the source file. However, it is recommended to specify a separate destination directory with the -d option described in Standard Options.

What is the name of the compiler used in Java?

javac - Java programming language compiler.


1 Answers

The Ant javac task documentation says:

It is possible to use different compilers. This can be specified by either setting the global build.compiler property, which will affect all tasks throughout the build, or by setting the compiler attribute, specific to the current task. Valid values for either the build.compiler property or the compiler attribute are:

It sounds as if you can either specify the global build.compiler property or set a specific compiler attribute.

So, it looks like you will need to modify your build file and either:

  1. remove the compiler attribute from the javac calls and allow the global build.compiler setting to cascade down

  2. change the values of the compiler attribute from a hard-coded string compiler="modern" to be property compiler="${javac.compiler}"

like image 106
Mads Hansen Avatar answered Oct 06 '22 01:10

Mads Hansen