@@ -88,20 +88,30 @@ public CompilerResult performCompile(CompilerConfiguration config )
88
88
args .add ("-g:lines,source" );
89
89
}
90
90
91
- String sourceVersion = decodeVersion ( config .getSourceVersion () );
92
-
93
- if ( sourceVersion != null )
91
+ String releaseVersion = decodeVersion ( config .getReleaseVersion () );
92
+ // EcjFailureException: Failed to run the ecj compiler: option -source is not supported when --release is used
93
+ if ( releaseVersion != null )
94
94
{
95
- args .add ("-source " );
96
- args .add (sourceVersion );
95
+ args .add ("--release " );
96
+ args .add (releaseVersion );
97
97
}
98
+ else
99
+ {
100
+ String sourceVersion = decodeVersion ( config .getSourceVersion () );
101
+
102
+ if ( sourceVersion != null )
103
+ {
104
+ args .add ("-source" );
105
+ args .add (sourceVersion );
106
+ }
98
107
99
- String targetVersion = decodeVersion ( config .getTargetVersion () );
108
+ String targetVersion = decodeVersion ( config .getTargetVersion () );
100
109
101
- if ( targetVersion != null )
102
- {
103
- args .add ("-target" );
104
- args .add (targetVersion );
110
+ if ( targetVersion != null )
111
+ {
112
+ args .add ("-target" );
113
+ args .add (targetVersion );
114
+ }
105
115
}
106
116
107
117
if ( StringUtils .isNotEmpty ( config .getSourceEncoding () ) )
@@ -286,26 +296,23 @@ else if(extras.containsKey("-errorsAsWarnings"))
286
296
// ECJ JSR-199 compiles against the latest Java version it supports if no source
287
297
// version is given explicitly. BatchCompiler uses 1.3 as default. So check
288
298
// whether a source version is specified, and if not supply 1.3 explicitly.
289
- //
299
+ if (!haveSourceOrReleaseArgument (args )) {
300
+ getLogger ().debug ("ecj: no source level nor release specified, defaulting to Java 1.3" );
301
+ args .add ("-source" );
302
+ args .add ("1.3" );
303
+ }
304
+
290
305
// Also check for the encoding. Could have been set via the CompilerConfig
291
306
// above, or also via the arguments explicitly. We need the charset for the
292
307
// StandardJavaFileManager below.
293
- String srcVersion = null ;
294
308
String encoding = null ;
295
309
Iterator <String > allArgs = args .iterator ();
296
- while (( srcVersion == null || encoding == null ) && allArgs .hasNext ()) {
310
+ while (encoding == null && allArgs .hasNext ()) {
297
311
String option = allArgs .next ();
298
- if ("-source" .equals (option ) && allArgs .hasNext ()) {
299
- srcVersion = allArgs .next ();
300
- } else if ("-encoding" .equals (option ) && allArgs .hasNext ()) {
312
+ if ("-encoding" .equals (option ) && allArgs .hasNext ()) {
301
313
encoding = allArgs .next ();
302
314
}
303
315
}
304
- if (srcVersion == null ) {
305
- getLogger ().debug ("ecj: no source level specified, defaulting to Java 1.3" );
306
- args .add ("-source" );
307
- args .add ("1.3" );
308
- }
309
316
final Locale defaultLocale = Locale .getDefault ();
310
317
final List <CompilerMessage > messages = messageList ;
311
318
DiagnosticListener <? super JavaFileObject > messageCollector = new DiagnosticListener <JavaFileObject >() {
@@ -446,6 +453,17 @@ public void worked(int i, int i1) {
446
453
}
447
454
}
448
455
456
+ private static boolean haveSourceOrReleaseArgument (List <String > args ) {
457
+ Iterator <String > allArgs = args .iterator ();
458
+ while (allArgs .hasNext ()) {
459
+ String option = allArgs .next ();
460
+ if (("-source" .equals (option ) || "--release" .equals (option )) && allArgs .hasNext ()) {
461
+ return true ;
462
+ }
463
+ }
464
+ return false ;
465
+ }
466
+
449
467
private JavaCompiler getEcj () {
450
468
ServiceLoader <JavaCompiler > javaCompilerLoader = ServiceLoader .load (JavaCompiler .class ,
451
469
BatchCompiler .class .getClassLoader ());
0 commit comments