Skip to content

Commit 98bc8b6

Browse files
committed
chore: fix configuration cache issues
1 parent 5d03663 commit 98bc8b6

File tree

4 files changed

+28
-22
lines changed

4 files changed

+28
-22
lines changed

plugins/project/src/main/kotlin/common/ProjectExtns.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -621,25 +621,23 @@ fun Project.appRunCmd(binary: Path, args: List<String>): String {
621621

622622
/** Returns the JDK install path provided by the [JavaToolchainService] */
623623
val Project.javaToolchainPath
624-
get(): Path {
624+
get(): Provider<Path> {
625625
val defToolchain = extensions.findByType(JavaPluginExtension::class)?.toolchain
626626
val javaToolchainSvc = extensions.findByType(JavaToolchainService::class)
627-
// val jvm: JavaVersion? = org.gradle.internal.jvm.Jvm.current().javaVersion
628627

629628
val jLauncher =
630629
when (defToolchain != null) {
631630
true -> javaToolchainSvc?.launcherFor(defToolchain)
632-
else -> javaToolchainSvc?.launcherFor { configureJvmToolchain(project) }
633-
}?.orNull
634-
635-
return jLauncher?.metadata?.installationPath?.asFile?.toPath()
636-
?: error("Requested JDK version ($javaVersion) is not available.")
631+
else -> javaToolchainSvc?.launcherFor { languageVersion = toolchainVersion }
632+
}
633+
return jLauncher?.map { it.metadata?.installationPath?.asFile?.toPath() }
634+
?: error("Unable to find the JDK toolchain installation path")
637635
}
638636

639637
/** Return incubator modules of the tool chain JDK */
640638
val Project.incubatorModules
641639
get(): String {
642-
val javaCmd = project.javaToolchainPath.resolve("bin").resolve("java")
640+
val javaCmd = project.javaToolchainPath.get().resolve("bin").resolve("java")
643641
val bos = ByteArrayOutputStream()
644642
val execResult =
645643
providers.exec {

plugins/project/src/main/kotlin/dev.suresh.plugin.kotlin.jvm.gradle.kts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ tasks {
157157
description = "Print Java Platform Module dependencies of the application."
158158
group = LifecycleBasePlugin.BUILD_GROUP
159159

160-
val shadowJar = named<ShadowJar>("shadowJar")
161-
doLast {
162-
val jarFile = shadowJar.get().archiveFile.get().asFile
160+
val shadowJarFile = tasks.named<ShadowJar>("shadowJar").flatMap { it.archiveFile }
161+
val release = project.javaRelease.get()
163162

163+
doLast {
164164
val jdeps =
165165
ToolProvider.findFirst("jdeps").orElseGet { error("jdeps tool is missing in the JDK!") }
166166
val out = StringWriter()
@@ -172,26 +172,29 @@ tasks {
172172
"-R",
173173
"--print-module-deps",
174174
"--ignore-missing-deps",
175-
"--multi-release=${javaRelease.get()}",
176-
jarFile.absolutePath,
175+
"--multi-release=$release",
176+
shadowJarFile.get().asFile.absolutePath,
177177
)
178178

179179
val modules = out.toString()
180180
logger.quiet(
181181
"""
182-
|Application modules for OpenJDK-${javaRelease.get()} are,
183-
|${modules.split(",").mapIndexed { i, module -> " ${(i + 1).toString()
184-
.padStart(2)}) $module" }.joinToString(System.lineSeparator())}
182+
|Application modules for OpenJDK-$release are,
183+
|${modules.split(",")
184+
.mapIndexed { i, module -> " ${(i + 1).toString()
185+
.padStart(2)}) $module" }
186+
.joinToString(System.lineSeparator())}
185187
"""
186188
.trimMargin()
187189
)
188190
}
189-
dependsOn(shadowJar)
191+
dependsOn("shadowJar")
190192
}
191193

192194
val jdepExtn = extensions.create<JdeprscanExtension>("jdeprscan")
193195
register<Jdeprscan>("jdeprscan", jdepExtn).configure {
194196
jarFile = named<ShadowJar>("shadowJar").flatMap { it.archiveFile }
197+
javaHome = project.javaToolchainPath
195198
}
196199
}
197200

plugins/project/src/main/kotlin/plugins/DepReportsPlugin.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class DepReportsPlugin : Plugin<Project> {
2222
override fun apply(target: Project) =
2323
with(target) {
2424
pluginManager.withPlugin("java-base") {
25+
val projectLayout = project.layout
2526
val listResolvedArtifacts by
2627
tasks.registering(ListResolvedArtifacts::class) {
2728
// Get the runtime-resolved artifacts
@@ -35,16 +36,17 @@ class DepReportsPlugin : Plugin<Project> {
3536
artifactFiles =
3637
resolvedArtifacts.map {
3738
it.map { resolvedArtifactResult ->
38-
layout.projectDirectory.file(resolvedArtifactResult.file.absolutePath)
39+
projectLayout.projectDirectory.file(
40+
resolvedArtifactResult.file.absolutePath
41+
)
3942
}
4043
}
41-
outputFile.convention(layout.buildDirectory.file("resolved-artifacts.txt"))
44+
outputFile.convention(projectLayout.buildDirectory.file("resolved-artifacts.txt"))
4245
}
4346
}
4447
}
4548
}
4649

47-
@CacheableTask
4850
abstract class ListResolvedArtifacts : DefaultTask() {
4951

5052
@get:Input abstract val artifactIds: ListProperty<ComponentArtifactIdentifier>

plugins/project/src/main/kotlin/tasks/Jdeprscan.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tasks
22

33
import common.*
44
import java.io.*
5+
import java.nio.file.Path
56
import javax.inject.*
67
import org.gradle.api.*
78
import org.gradle.api.file.*
@@ -30,6 +31,8 @@ constructor(
3031
@get:[Input Optional]
3132
val classPath = objects.listProperty<File>()
3233

34+
@get:Input abstract val javaHome: Property<Path>
35+
3336
@get:Internal internal val projectName = project.name
3437

3538
init {
@@ -62,8 +65,8 @@ constructor(
6265
add(jarFile.get().asFile.absolutePath)
6366
}
6467

65-
// java bin directory
66-
val jdeprscan = project.javaToolchainPath.resolve("bin").resolve("jdeprscan")
68+
// jdeprscan binary path
69+
val jdeprscan = javaHome.get().resolve("bin").resolve("jdeprscan")
6770
val bos = ByteArrayOutputStream()
6871
val execResult =
6972
execOps.exec {

0 commit comments

Comments
 (0)