Skip to content

Commit

Permalink
Handle requiring versioned java home during execution
Browse files Browse the repository at this point in the history
Currently bwc builds require different java home environment variables
depending on the version of elasticsearch being built. The java home
version checks are run at the end of gradle configuration, when the task
graph is ready. However, we do not know which versions are needed for
bwc builds until execution time, when we have finished checking out the
version of elasticsearch to be built. This commit accounts for late java
home checks, checking immediately instead of delaying the check.

closes elastic#37586
  • Loading branch information
rjernst committed Jan 18, 2019
1 parent 978c818 commit 035b305
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ class BuildPlugin implements Plugin<Project> {
rootProject.rootProject.ext.requiredJavaVersions = [:].withDefault{key -> return []}
rootProject.gradle.taskGraph.whenReady { TaskExecutionGraph taskGraph ->
List<String> messages = []
println("Checking for java versions: " + rootProject.requiredJavaVersions.keySet())
for (entry in rootProject.requiredJavaVersions) {
if (rootProject.javaVersions.get(entry.key) != null) {
continue
Expand All @@ -407,9 +408,16 @@ class BuildPlugin implements Plugin<Project> {
if (messages.isEmpty() == false) {
throw new GradleException(messages.join('\n'))
}
rootProject.rootProject.ext.requiredJavaVersions = null // reset to null to indicate the pre-execution checks have executed
}
} else if (rootProject.rootProject.requiredJavaVersions == null) {
// check directly if the version is present since we are already executing
if (rootProject.javaVersions.get(version) == null) {
throw new GradleException("JAVA${version}_HOME required to run task:\n${task}")
}
} else {
rootProject.requiredJavaVersions.get(version).add(task)
}
rootProject.requiredJavaVersions.get(version).add(task)
}

/** A convenience method for getting java home for a version of java and requiring that version for the given task to execute */
Expand Down

0 comments on commit 035b305

Please sign in to comment.