diff --git a/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java b/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java index 836df4b2..34516851 100644 --- a/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java +++ b/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java @@ -88,20 +88,30 @@ public CompilerResult performCompile(CompilerConfiguration config ) args.add("-g:lines,source"); } - String sourceVersion = decodeVersion( config.getSourceVersion() ); - - if ( sourceVersion != null ) + String releaseVersion = decodeVersion( config.getReleaseVersion() ); + // EcjFailureException: Failed to run the ecj compiler: option -source is not supported when --release is used + if ( releaseVersion != null ) { - args.add("-source"); - args.add(sourceVersion); + args.add("--release"); + args.add(releaseVersion); } + else + { + String sourceVersion = decodeVersion( config.getSourceVersion() ); + + if ( sourceVersion != null ) + { + args.add("-source"); + args.add(sourceVersion); + } - String targetVersion = decodeVersion( config.getTargetVersion() ); + String targetVersion = decodeVersion( config.getTargetVersion() ); - if ( targetVersion != null ) - { - args.add("-target"); - args.add(targetVersion); + if ( targetVersion != null ) + { + args.add("-target"); + args.add(targetVersion); + } } if ( StringUtils.isNotEmpty( config.getSourceEncoding() ) ) @@ -286,26 +296,23 @@ else if(extras.containsKey("-errorsAsWarnings")) // ECJ JSR-199 compiles against the latest Java version it supports if no source // version is given explicitly. BatchCompiler uses 1.3 as default. So check // whether a source version is specified, and if not supply 1.3 explicitly. - // + if (!haveSourceOrReleaseArgument(args)) { + getLogger().debug("ecj: no source level nor release specified, defaulting to Java 1.3"); + args.add("-source"); + args.add("1.3"); + } + // Also check for the encoding. Could have been set via the CompilerConfig // above, or also via the arguments explicitly. We need the charset for the // StandardJavaFileManager below. - String srcVersion = null; String encoding = null; Iterator allArgs = args.iterator(); - while ((srcVersion == null || encoding == null) && allArgs.hasNext()) { + while (encoding == null && allArgs.hasNext()) { String option = allArgs.next(); - if ("-source".equals(option) && allArgs.hasNext()) { - srcVersion = allArgs.next(); - } else if ("-encoding".equals(option) && allArgs.hasNext()) { + if ("-encoding".equals(option) && allArgs.hasNext()) { encoding = allArgs.next(); } } - if (srcVersion == null) { - getLogger().debug("ecj: no source level specified, defaulting to Java 1.3"); - args.add("-source"); - args.add("1.3"); - } final Locale defaultLocale = Locale.getDefault(); final List messages = messageList; DiagnosticListener messageCollector = new DiagnosticListener() { @@ -446,6 +453,17 @@ public void worked(int i, int i1) { } } + private static boolean haveSourceOrReleaseArgument(List args) { + Iterator allArgs = args.iterator(); + while (allArgs.hasNext()) { + String option = allArgs.next(); + if (("-source".equals(option) || "--release".equals(option)) && allArgs.hasNext()) { + return true; + } + } + return false; + } + private JavaCompiler getEcj() { ServiceLoader javaCompilerLoader = ServiceLoader.load(JavaCompiler.class, BatchCompiler.class.getClassLoader());