Override the compiler attribute in an Ant javac task

我只是一个虾纸丫 提交于 2019-12-18 04:54:09

问题


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?


回答1:


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}"



来源:https://stackoverflow.com/questions/235363/override-the-compiler-attribute-in-an-ant-javac-task

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!