Community
Participate
Working Groups
If you launch an Ant compilation with -Dbuild.compiler=org.eclipse.jdt.core.JDTCompilerAdapter or with a build.compiler target, the compilation is done without using user's preferences of Eclipse. If you want to not see all "unused imports" warning, you go in Eclipse->window->preference->java->compiler. In Eclipse, it will compile without warning. But with Ant launch by Eclipse with JDTCompilerAdapter, it will show all warnings. I search inside the source code itself of Eclipse project. And I think I found a bug for JDTCompilerAdapter. See at : http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jdt.core/antadapter/org/eclipse/jdt/core/JDTCompilerAdapter.java?rev=1.20&content-type=text/vnd.viewcvs-markup I can see : /* * Handle the nowarn option. If none, then we generate all warnings. */ if (attributes.getNowarn()) { if (deprecation) { cmd.createArgument().setValue("-warn:allDeprecation"); //$NON-NLS-1$ } else { cmd.createArgument().setValue("-nowarn"); //$NON-NLS-1$ } } else { /* * deprecation option. */ if (deprecation) { cmd.createArgument().setValue( "-warn:allDeprecation,constructorName,packageDefaultMethod,maskedCatchBlocks,unusedImports,staticReceiver"); //$NON-NLS-1$ } else { cmd.createArgument().setValue( "-warn:constructorName,packageDefaultMethod,maskedCatchBlocks,unusedImports,staticReceiver"); //$NON-NLS-1$ } } As you can see, when getNoWarn is false, every warning level are written INSIDE the code (hard coding). It doesn't use user's preferences.
The Ant task isn't using any Eclipse setting, nor does it actually need an Eclipse instance to run.
When I speak about Ant task, I speak about build.compiler specified INSIDE the build.xml itself (instead of using -Dbuild.compiler). With something like : <condition property="build_compiler" value="modern"> <not> <isset property="eclipse.running"/> </not> </condition> <condition property="build_compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"> <isset property="eclipse.running"/> </condition> <echo message="build compiler : ${build_compiler}"/> <property name="build.compiler" value="${build_compiler}"/>
This is not a bug in the JDTCompiler adapter. This is simply an adapter for the javac ant task. This task doesn't allow you to use a custom level of warnings. If you don't want any warning, please update the build.xml file adding nowarn="on" inside your javac ant task. By default this is off. There is no way to give Eclipse warnings to the ant task. Ant javac task uses specific options and it doesn't allow us to reuse Eclipse settings. Like Philippe said, Eclipse might not run and you can still use this ant javac adapter. Ok to close?
I don't want to change the build.xml to add level of warnings. I know that Ant doesn't support it. But I think the goal of an adapter is to call Ant and to have a return to the adapter to use some Eclipse's specific features. JDTCompilerAdapter can detect if Eclipse is running : - if no, it compile as today, with default parameters - if yes, it uses user's preferences. It doesn't need any modification of Ant or build.xml. What is the goal of JDTCompilerAdapter if it doesn't use the power of Eclipse compiler ? As I already say, I don't want to turn nowarn to on, because : - I work on a big project, with more than 100 developers, I can change preference of all users with changing global build.xml - I want some standard warnings (deprecation, bad import, ...) but not too much (unused variables or import ...) - I would like to use fine granularity of warnings level of Eclipse. You do something very good, I would be too bad to don't use it.
Close as duplicate of bug 25510. We will definitely investigate it. Here is what we'd like to achieve. If the ant script is used inside Eclipse, then Eclipse settings are used. Otherwise use default options (actual options). *** This bug has been marked as a duplicate of 25510 ***
Change milestone.