[2.x] test: Add javaagent test (#9164)

This commit is contained in:
kenji yoshida 2026-05-01 13:29:16 +09:00 committed by GitHub
parent 4a02167fa4
commit 71a5ad6448
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,9 @@
package example;
import java.lang.instrument.Instrumentation;
public class JavaAgentMain {
public static void premain(String agentArgs, Instrumentation instrumentation) {
new example.A();
}
}

View File

@ -0,0 +1,29 @@
scalaVersion := "2.13.18"
lazy val core = project
.settings(
libraryDependencies += "org.scalatest" %% "scalatest-funspec" % "3.2.20" % Test,
Test / fork := true,
Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Raw,
Test / javaOptions += {
val agentJar = fileConverter.value.toPath(
(agent / Compile / packageBin).value
).toFile.getCanonicalPath
s"-javaagent:${agentJar}"
}
)
.dependsOn(agent)
lazy val agent = project
.settings(
autoScalaLibrary := false,
packageOptions += Package.ManifestAttributes(
"Premain-Class" -> "example.JavaAgentMain"
)
)
.dependsOn(lib)
lazy val lib = project
.settings(
autoScalaLibrary := false
)

View File

@ -0,0 +1,5 @@
package example
import org.scalatest.funspec.AnyFunSpec
class Test extends AnyFunSpec

View File

@ -0,0 +1,3 @@
package example;
public class A {}

View File

@ -0,0 +1 @@
> testFull