Skip to content

Commit

Permalink
Store resolved toolchain info as custom values in build scan
Browse files Browse the repository at this point in the history
Prior to this commit, we registered custom values in the build scan for
the main and test toolchains based on input values provided via the
mainToolchain and testToolchain project properties.

Beginning with this commit, the custom values we register are based on
the available metadata for the resolved JDK/JVM for each toolchain.

For example, instead of registering the following custom value...

Test toolchain : JDK11

... we now register the following which includes the vendor, version,
and installation path of the JDK/JVM.

Test toolchain : AdoptOpenJDK 11 (/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home)

Once Gradle's JavaInstallationMetadata includes the exact version, we
will likely use that instead of the installation path.

See spring-projectsgh-25787
  • Loading branch information
sbrannen authored and lxbzmy committed Mar 26, 2022
1 parent 7459729 commit 34f81d8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
23 changes: 21 additions & 2 deletions gradle/toolchains.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* }
*
* @author Brian Clozel
* @author Sam Brannen
*/

def mainToolchainConfigured() {
Expand Down Expand Up @@ -129,7 +130,7 @@ pluginManager.withPlugin("kotlin") {
}
}
}

if (testToolchainConfigured()) {
def testLanguageVersion = testToolchainLanguageVersion()
def compiler = javaToolchains.compilerFor {
Expand Down Expand Up @@ -160,4 +161,22 @@ pluginManager.withPlugin("me.champeau.jmh") {
}
}
}
}
}

// Store resolved Toolchain JVM information as custom values in the build scan.
rootProject.ext {
resolvedMainToolchain = false
resolvedTestToolchain = false
}
gradle.taskGraph.afterTask { Task task, TaskState state ->
if (mainToolchainConfigured() && !resolvedMainToolchain && task instanceof JavaCompile && task.javaCompiler.isPresent()) {
def metadata = task.javaCompiler.get().metadata
task.project.buildScan.value('Main toolchain', "$metadata.vendor $metadata.languageVersion ($metadata.installationPath)")
resolvedMainToolchain = true
}
if (testToolchainConfigured() && !resolvedTestToolchain && task instanceof Test && task.javaLauncher.isPresent()) {
def metadata = task.javaLauncher.get().metadata
task.project.buildScan.value('Test toolchain', "$metadata.vendor $metadata.languageVersion ($metadata.installationPath)")
resolvedTestToolchain = true
}
}
6 changes: 0 additions & 6 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ rootProject.children.each {project ->
settings.gradle.projectsLoaded {
gradleEnterprise {
buildScan {
if (settings.gradle.rootProject.hasProperty('mainToolchain') && settings.gradle.rootProject.getProperty('mainToolchain')) {
value("Main toolchain", 'JDK' + settings.gradle.rootProject.getProperty('mainToolchain'))
}
if (settings.gradle.rootProject.hasProperty('testToolchain') && settings.gradle.rootProject.getProperty('testToolchain')) {
value("Test toolchain", 'JDK' + settings.gradle.rootProject.getProperty('testToolchain'))
}
File buildDir = settings.gradle.rootProject.getBuildDir()
buildDir.mkdirs()
new File(buildDir, "build-scan-uri.txt").text = "(build scan not generated)"
Expand Down

0 comments on commit 34f81d8

Please sign in to comment.