@@ -127,14 +127,27 @@ private void applyJavaConventions(Project project) {
127
127
project .setProperty ("sourceCompatibility" , "1.8" );
128
128
project .getTasks ().withType (JavaCompile .class , (compile ) -> {
129
129
compile .getOptions ().setEncoding ("UTF-8" );
130
+ if (hasCustomBuildJavaHome (project )) {
131
+ String javaExecutable = getCustomBuildJavaExecutable (project , "/bin/java" );
132
+ compile .getOptions ().getForkOptions ().setJavaHome (new File (javaExecutable ));
133
+ }
130
134
List <String > args = compile .getOptions ().getCompilerArgs ();
131
135
if (!args .contains ("-parameters" )) {
132
136
args .add ("-parameters" );
133
137
}
134
138
});
135
- project .getTasks ().withType (Javadoc .class ,
136
- (javadoc ) -> javadoc .getOptions ().source ("1.8" ).encoding ("UTF-8" ));
139
+ project .getTasks ().withType (Javadoc .class , (javadoc ) -> {
140
+ javadoc .getOptions ().source ("1.8" ).encoding ("UTF-8" );
141
+ if (hasCustomBuildJavaHome (project )) {
142
+ String javaExecutable = getCustomBuildJavaExecutable (project , "/bin/javadoc" );
143
+ javadoc .setExecutable (javaExecutable );
144
+ }
145
+ });
137
146
project .getTasks ().withType (Test .class , (test ) -> {
147
+ if (hasCustomBuildJavaHome (project )) {
148
+ String javaExecutable = getCustomBuildJavaExecutable (project , "/bin/java" );
149
+ test .setExecutable (javaExecutable );
150
+ }
138
151
test .useJUnitPlatform ();
139
152
test .setMaxHeapSize ("1024M" );
140
153
});
@@ -192,6 +205,14 @@ private File createLegalFile(File source, String filename) {
192
205
return legalFile ;
193
206
}
194
207
208
+ private boolean hasCustomBuildJavaHome (Project project ) {
209
+ return project .hasProperty ("buildJavaHome" ) && !((String ) project .property ("buildJavaHome" )).isEmpty ();
210
+ }
211
+
212
+ private String getCustomBuildJavaExecutable (Project project , String executable ) {
213
+ return project .property ("buildJavaHome" ) + executable ;
214
+ }
215
+
195
216
private void configureSpringJavaFormat (Project project ) {
196
217
project .getPlugins ().apply (SpringJavaFormatPlugin .class );
197
218
project .getTasks ().withType (FormatTask .class , (formatTask ) -> formatTask .setEncoding ("UTF-8" ));
0 commit comments