Slackbot
11/28/2023, 12:35 PMReuben Firmin
11/28/2023, 12:35 PMsourceSets {
...
val jvmMain by getting {
dependencies {
...
implementation("org.hotswapagent:hotswap-agent-core:1.4.0")Reuben Firmin
11/28/2023, 12:36 PMapplication {
mainClass.set("ah.MainKt")
tasks.named<JavaExec>("run") {
doFirst {
val hotswapAgentJar = project.configurations
.matching { it.name == "jvmMainImplementation" }
.flatMap { it.files }
.find { it.name.startsWith("hotswap-agent-core") }
if (hotswapAgentJar != null) {
jvmArgs(
"-javaagent:${hotswapAgentJar.absolutePath}",
)
println("Added to jvm args: ${hotswapAgentJar.absolutePath}")
} else {
throw IllegalStateException("Hotswap Agent Core dependency not found in the 'implementation' configuration.")
}
}
val main by sourceSets.getting
args = main.output.asPath.split(":")
}
}Reuben Firmin
11/28/2023, 12:37 PMval hotswapAgentCore = configurations.getByName("jvmMainImplementation")
.dependencies
.find { it.name.startsWith("hotswap-agent-core") }
...but I couldn't figure out how to turn this into a file pathVampire
11/28/2023, 12:54 PMjvmMainRuntimeClasspath, assuming it follows the usual standard. But actually you should probably not add it to implementation at all anyway. Better declare a custom configuration for that.Reuben Firmin
11/28/2023, 12:56 PMVampire
11/28/2023, 12:59 PMI don't understand why it's complaining though - why the limitation?Configurations have different roles. The role of the
implementation configuration is only to be a bucket on which to declare dependencies, but not to resolve them.
There are also configurations that are meant to be consumed by downstream projects, and there are configuration that are meant to resolve configurations.
It is explained in detail at https://docs.gradle.org/current/userguide/declaring_dependencies.html and that also shows how to use custom configurations like you should do here.Reuben Firmin
11/28/2023, 1:03 PMVampire
11/28/2023, 1:05 PMval hotswapAgent = configurations.dependencyScope("hotswapAgent").get()
val hotswapAgentClasspath = configurations.resolvable("hotswapAgentClasspath") {
extendsFrom(hotswapAgent)
}
dependencies {
hotswapAgent("foo:bar:+")
}
println(hotswapAgentClasspath.get().files)