Fixed error handling when Java version can't be determined (#118)
* Fixed error handling when Java version can't be determined * Made build getJavaExecutableVersion more resilient to output variations
This commit is contained in:
parent
37b314fa0c
commit
bec7775d56
|
@ -234,15 +234,20 @@ JavaVersion getJavaExecutableVersion(String path) {
|
||||||
commandLine = [path, "-version"]
|
commandLine = [path, "-version"]
|
||||||
errorOutput = stream
|
errorOutput = stream
|
||||||
}
|
}
|
||||||
def matcher = stream.toString() =~ /^(?:java|openjdk) version "([^"]+)"/
|
def output = stream.toString()
|
||||||
|
for (def line : output.split('\n')) {
|
||||||
|
line = line.trim()
|
||||||
|
def matcher = line =~ /^(?:java|openjdk) version "([^"]+)"/
|
||||||
if (matcher) {
|
if (matcher) {
|
||||||
def version = JavaVersion.toVersion(matcher.group(1))
|
def version = JavaVersion.toVersion(matcher.group(1))
|
||||||
cache.put(path, version)
|
cache.put(path, version)
|
||||||
return version
|
return version
|
||||||
} else {
|
|
||||||
throw new GradleScriptException("Cannot determine java version: ${stream.toString}")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Getting here means we didn't find a line matching the version pattern.
|
||||||
|
throw new GradleScriptException("Cannot determine java version. Executable: ${path}, output: ${output}", null)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
|
|
Loading…
Reference in New Issue