|
1 | 1 | import org.gradle.api.internal.provider.PropertyFactory |
2 | 2 | import org.gradle.jvm.toolchain.internal.SpecificInstallationToolchainSpec |
3 | 3 |
|
| 4 | +import java.nio.file.Files |
| 5 | +import java.nio.file.Paths |
| 6 | + |
4 | 7 | apply plugin: 'java-library' |
5 | 8 |
|
6 | 9 | apply from: "$rootDir/gradle/codenarc.gradle" |
@@ -164,17 +167,22 @@ project.afterEvaluate { |
164 | 167 | testJvm = javaVersions.max().toString() |
165 | 168 | } |
166 | 169 | if (testJvm) { |
167 | | - def matcher = testJvm =~ /([a-zA-Z]*)([0-9]+)/ |
168 | | - if (!matcher.matches()) { |
169 | | - throw new GradleException("Unable to find launcher for Java '$testJvm'. It needs to match '([a-zA-Z]*)([0-9]+)'.") |
170 | | - } |
171 | | - def testJvmLanguageVersion = matcher.group(2) as Integer |
172 | | - def testJvmEnv = "JAVA_${testJvm}_HOME" |
173 | | - def testJvmHome = System.getenv(testJvmEnv) |
174 | | - if (!testJvmHome) { |
175 | | - throw new GradleException("Unable to find launcher for Java '$testJvm'. Have you set '$testJvmEnv'?") |
| 170 | + def testJvmHomePath |
| 171 | + if (Files.exists(Paths.get(testJvm))) { |
| 172 | + testJvmHomePath = getJavaHomePath(testJvm) |
| 173 | + } else { |
| 174 | + def matcher = testJvm =~ /([a-zA-Z]*)([0-9]+)/ |
| 175 | + if (!matcher.matches()) { |
| 176 | + throw new GradleException("Unable to find launcher for Java '$testJvm'. It needs to match '([a-zA-Z]*)([0-9]+)'.") |
| 177 | + } |
| 178 | + def testJvmLanguageVersion = matcher.group(2) as Integer |
| 179 | + def testJvmEnv = "JAVA_${testJvm}_HOME" |
| 180 | + def testJvmHome = System.getenv(testJvmEnv) |
| 181 | + if (!testJvmHome) { |
| 182 | + throw new GradleException("Unable to find launcher for Java '$testJvm'. Have you set '$testJvmEnv'?") |
| 183 | + } |
| 184 | + testJvmHomePath = getJavaHomePath(testJvmHome) |
176 | 185 | } |
177 | | - def testJvmHomePath = getJavaHomePath(testJvmHome) |
178 | 186 | // Only change test JVM if it's not the one we are running the gradle build with |
179 | 187 | if (currentJavaHomePath != testJvmHomePath) { |
180 | 188 | def jvmSpec = new SpecificInstallationToolchainSpec(project.services.get(PropertyFactory), file(testJvmHomePath)) |
|
0 commit comments