Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
8f44bd89
Commit
8f44bd89
authored
Feb 25, 2020
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Allow Gradle tasks to be executed with a custom Java home"
See gh-20179
parent
e599ed01
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
18 deletions
+23
-18
ConventionsPlugin.java
...ava/org/springframework/boot/build/ConventionsPlugin.java
+13
-18
settings.gradle
settings.gradle
+10
-0
No files found.
buildSrc/src/main/java/org/springframework/boot/build/ConventionsPlugin.java
View file @
8f44bd89
...
...
@@ -26,6 +26,7 @@ import java.nio.charset.StandardCharsets;
import
java.util.List
;
import
java.util.Map
;
import
java.util.TreeMap
;
import
java.util.function.Consumer
;
import
io.spring.javaformat.gradle.FormatTask
;
import
io.spring.javaformat.gradle.SpringJavaFormatPlugin
;
...
...
@@ -127,10 +128,11 @@ public class ConventionsPlugin implements Plugin<Project> {
project
.
setProperty
(
"sourceCompatibility"
,
"1.8"
);
project
.
getTasks
().
withType
(
JavaCompile
.
class
,
(
compile
)
->
{
compile
.
getOptions
().
setEncoding
(
"UTF-8"
);
if
(
hasCustomBuildJavaHome
(
project
))
{
String
javaExecutable
=
getCustomBuildJavaExecutable
(
project
,
"/bin/java"
);
compile
.
getOptions
().
getForkOptions
().
setJavaHome
(
new
File
(
javaExecutable
));
}
withOptionalBuildJavaHome
(
project
,
(
javaHome
)
->
{
compile
.
getOptions
().
setFork
(
true
);
compile
.
getOptions
().
getForkOptions
().
setJavaHome
(
new
File
(
javaHome
));
compile
.
getOptions
().
getForkOptions
().
setExecutable
(
javaHome
+
"/bin/javac"
);
});
List
<
String
>
args
=
compile
.
getOptions
().
getCompilerArgs
();
if
(!
args
.
contains
(
"-parameters"
))
{
args
.
add
(
"-parameters"
);
...
...
@@ -138,16 +140,10 @@ public class ConventionsPlugin implements Plugin<Project> {
});
project
.
getTasks
().
withType
(
Javadoc
.
class
,
(
javadoc
)
->
{
javadoc
.
getOptions
().
source
(
"1.8"
).
encoding
(
"UTF-8"
);
if
(
hasCustomBuildJavaHome
(
project
))
{
String
javaExecutable
=
getCustomBuildJavaExecutable
(
project
,
"/bin/javadoc"
);
javadoc
.
setExecutable
(
javaExecutable
);
}
withOptionalBuildJavaHome
(
project
,
(
javaHome
)
->
javadoc
.
setExecutable
(
javaHome
+
"/bin/javadoc"
));
});
project
.
getTasks
().
withType
(
Test
.
class
,
(
test
)
->
{
if
(
hasCustomBuildJavaHome
(
project
))
{
String
javaExecutable
=
getCustomBuildJavaExecutable
(
project
,
"/bin/java"
);
test
.
setExecutable
(
javaExecutable
);
}
withOptionalBuildJavaHome
(
project
,
(
javaHome
)
->
test
.
setExecutable
(
javaHome
+
"/bin/java"
));
test
.
useJUnitPlatform
();
test
.
setMaxHeapSize
(
"1024M"
);
});
...
...
@@ -205,12 +201,11 @@ public class ConventionsPlugin implements Plugin<Project> {
return
legalFile
;
}
private
boolean
hasCustomBuildJavaHome
(
Project
project
)
{
return
project
.
hasProperty
(
"buildJavaHome"
)
&&
!((
String
)
project
.
property
(
"buildJavaHome"
)).
isEmpty
();
}
private
String
getCustomBuildJavaExecutable
(
Project
project
,
String
executable
)
{
return
project
.
property
(
"buildJavaHome"
)
+
executable
;
private
void
withOptionalBuildJavaHome
(
Project
project
,
Consumer
<
String
>
consumer
)
{
String
buildJavaHome
=
(
String
)
project
.
findProperty
(
"buildJavaHome"
);
if
(
buildJavaHome
!=
null
&&
!
buildJavaHome
.
isEmpty
())
{
consumer
.
accept
(
buildJavaHome
);
}
}
private
void
configureSpringJavaFormat
(
Project
project
)
{
...
...
settings.gradle
View file @
8f44bd89
...
...
@@ -28,6 +28,16 @@ plugins {
rootProject
.
name
=
"spring-boot-build"
settings
.
gradle
.
projectsLoaded
{
gradleEnterprise
{
buildScan
{
if
(
settings
.
gradle
.
rootProject
.
hasProperty
(
'buildJavaHome'
))
{
value
(
'Build Java home'
,
settings
.
gradle
.
rootProject
.
getProperty
(
'buildJavaHome'
))
}
}
}
}
include
"spring-boot-project:spring-boot-dependencies"
include
"spring-boot-project:spring-boot-parent"
include
"spring-boot-project:spring-boot-tools:spring-boot-antlib"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment