No way to set compiler arguments/options for Eclipse compiler
-------------------------------------------------------------
Key: MCOMPILER-123
URL: http://jira.codehaus.org/browse/MCOMPILER-123
Project: Maven 2.x Compiler Plugin
Issue Type: Bug
Affects Versions: 2.2
Reporter: Lóránt Pintér
I have a problem with setting compiler options for the Eclipse compiler. I
tried to do the following:
{code:xml}
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.2</version>
<configuration>
<compilerId>eclipse</compilerId>
<source>1.6</source>
<target>1.6</target>
<encoding>utf-8</encoding>
<compilerArguments>
<org.eclipse.jdt.core.compiler.problem.missingSerialVersion>ignore</org.eclipse.jdt.core.compiler.problem.missingSerialVersion>
</compilerArguments>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>1.8</version>
</dependency>
</dependencies>
</plugin>
{code}
It should be okay, as this is in EclipseJavaCompiler:
{code:java}
// compiler-specific extra options override anything else in the config
object...
Map extras = config.getCustomCompilerArguments();
if ( extras != null && !extras.isEmpty() )
{
settings.putAll( extras );
}
// ...
// ----------------------------------------------------------------------
// Compile!
// ----------------------------------------------------------------------
CompilerOptions options = new CompilerOptions( settings );
Compiler compiler = new Compiler( env, policy, options, requestor,
problemFactory );
{code}
But the problem is that all keys in the map are prefixed with "-" in
AbstractCompilerMojo:
{code:java}
Map<String, String> effectiveCompilerArguments = getCompilerArguments();
String effectiveCompilerArgument = getCompilerArgument();
if ( ( effectiveCompilerArguments != null ) || ( effectiveCompilerArgument !=
null ) )
{
LinkedHashMap<String, String> cplrArgsCopy = new LinkedHashMap<String,
String>();
if ( effectiveCompilerArguments != null )
{
for ( Map.Entry<String, String> me :
effectiveCompilerArguments.entrySet() )
{
String key = (String) me.getKey();
String value = (String) me.getValue();
if ( !key.startsWith( "-" ) )
{
key = "-" + key;
}
cplrArgsCopy.put( key, value );
}
}
if ( !StringUtils.isEmpty( effectiveCompilerArgument ) )
{
cplrArgsCopy.put( effectiveCompilerArgument, null );
}
compilerConfiguration.setCustomCompilerArguments( cplrArgsCopy );
}
{code}
So what actually gets into the Map for CompilerOptions is this:
{code}
-org.eclipse.jdt.core.compiler.problem.missingSerialVersion = ignore
{code}
Instead of:
{code}
org.eclipse.jdt.core.compiler.problem.missingSerialVersion = ignore
{code}
The incorrect setting name is then silently discarded by ECJ.
I cannot use this either:
{code:xml}
<configuration>
<compilerId>eclipse</compilerId>
<source>1.6</source>
<target>1.6</target>
<encoding>utf-8</encoding>
<compilerArgument>-warn:-serial</compilerArgument>
</configuration>
{code}
...because "-warn:-serial" is not passed as a command-line argument, but it is
also added to the Map for CompilerOptions:
{code:java}
if ( !StringUtils.isEmpty( effectiveCompilerArgument ) )
{
cplrArgsCopy.put( effectiveCompilerArgument, null );
}
compilerConfiguration.setCustomCompilerArguments( cplrArgsCopy );
{code}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira