覆盖 Ant javac 任务中的编译器属性 [英] Override the compiler attribute in an Ant javac task
问题描述
我正在尝试通过命令行覆盖 Ant 编译器属性,以便所有javac"任务都使用我指定的编译器.我遇到的问题是,任何为编译器设置自己值的目标都会覆盖我在命令行中设置的目标.所以,即使我输入了以下命令.
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
由于该 compiler="modern" 属性,任何具有以下内容的目标都将使用现代编译器而不是 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?
推荐答案
The Ant javac
任务文档 说:
The Ant javac
task documentation says:
可以使用不同的编译器.这可以通过设置全局 build.compiler 属性来指定,这将影响整个构建过程中的所有任务,或者通过设置特定于当前任务的编译器属性.build.compiler 属性或编译器属性的有效值为:
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:
听起来好像您可以要么指定全局 build.compiler 属性或设置特定的编译器属性.
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:
从 javac 调用中删除编译器属性并允许全局 build.compiler 设置为级联
remove the compiler attribute from the javac calls and allow the global build.compiler setting to cascade down
改变编译器的值来自硬编码字符串的属性compiler="modern" 成为财产compiler="${javac.compiler}"
change the values of the compiler attribute from a hard-coded string compiler="modern" to be property compiler="${javac.compiler}"
这篇关于覆盖 Ant javac 任务中的编译器属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!