1
1
/*
2
- * Copyright (c) 2020-2021 VMware Inc. or its affiliates, All Rights Reserved.
2
+ * Copyright (c) 2020-2024 VMware Inc. or its affiliates, All Rights Reserved.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
20
20
import java .util .Arrays ;
21
21
import java .util .List ;
22
22
23
- import org .gradle .api .JavaVersion ;
24
23
import org .gradle .api .Plugin ;
25
24
import org .gradle .api .Project ;
26
25
import org .gradle .api .plugins .JavaPlugin ;
27
26
import org .gradle .api .plugins .JavaPluginExtension ;
28
27
import org .gradle .api .tasks .compile .JavaCompile ;
28
+ import org .gradle .jvm .toolchain .JavaLanguageVersion ;
29
29
30
30
/**
31
31
* @author Simon Baslé
@@ -38,15 +38,22 @@ public void apply(Project project) {
38
38
}
39
39
40
40
private void applyJavaConvention (Project project ) {
41
- JavaPluginExtension java = project .getExtensions ().getByType (JavaPluginExtension .class );
42
- java . setSourceCompatibility ( JavaVersion . VERSION_1_8 );
43
- java . setTargetCompatibility ( JavaVersion . VERSION_1_8 );
41
+ project .getExtensions ().getByType (JavaPluginExtension .class ). toolchain ( toolchain -> {
42
+ toolchain . getLanguageVersion (). set ( JavaLanguageVersion . of ( 8 ) );
43
+ } );
44
44
45
45
project .getTasks ()
46
46
.withType (JavaCompile .class )
47
47
.forEach (compileTask -> {
48
48
compileTask .getOptions ().setEncoding ("UTF-8" );
49
- compileTask .getOptions ().setCompilerArgs (Arrays .asList (
49
+
50
+ List <String > compilerArgs = new ArrayList <>(
51
+ compileTask .getOptions ().getCompilerArgs ());
52
+
53
+ if (compileTask .getName ().endsWith ("TestJava" )) {
54
+ compilerArgs .add ("-parameters" );
55
+ }
56
+ compilerArgs .addAll (Arrays .asList (
50
57
"-Xlint:-varargs" , // intentionally disabled
51
58
"-Xlint:cast" ,
52
59
"-Xlint:classfile" ,
@@ -67,17 +74,8 @@ private void applyJavaConvention(Project project) {
67
74
"-Xmaxerrs" , "500" ,
68
75
"-Xmaxwarns" , "1000"
69
76
));
70
- });
71
77
72
- if (JavaVersion .current ().isJava8Compatible ()) {
73
- project .getTasks ().withType (JavaCompile .class , t -> {
74
- if (t .getName ().endsWith ("TestJava" )) {
75
- List <String > args = new ArrayList <>(t .getOptions ().getCompilerArgs ());
76
- args .add ("-parameters" );
77
- t .getOptions ().setCompilerArgs (args );
78
- }
78
+ compileTask .getOptions ().setCompilerArgs (compilerArgs );
79
79
});
80
- }
81
-
82
80
}
83
81
}
0 commit comments