diff --git a/src/main/kotlin/sh/tnn/gradle/plugins/opentelemetry/OpenTelemetryPlugin.kt b/src/main/kotlin/sh/tnn/gradle/plugins/opentelemetry/OpenTelemetryPlugin.kt index 7b9574d..67e385d 100644 --- a/src/main/kotlin/sh/tnn/gradle/plugins/opentelemetry/OpenTelemetryPlugin.kt +++ b/src/main/kotlin/sh/tnn/gradle/plugins/opentelemetry/OpenTelemetryPlugin.kt @@ -3,6 +3,7 @@ package sh.tnn.gradle.plugins.opentelemetry import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.logging.Logging +import org.gradle.process.JavaForkOptions import sh.tnn.gradle.plugins.dotenv.DotEnvPlugin import sh.tnn.gradle.plugins.java_environment.JavaEnvironmentPlugin @@ -51,7 +52,12 @@ class OpenTelemetryPlugin : Plugin { "OTEL_SERVICE_NAME" to resourceName, "OTEL_RESOURCE_ATTRIBUTES_NODE_NAME" to nodeName ) - it.append("JAVA_TOOL_OPTIONS", " -javaagent:${openTelemetryJavaAgentFile.absolutePath}") + } + + project.tasks.all { + if (it is JavaForkOptions) { + it.jvmArgs("-XX:+EnableDynamicAgentLoading", "-javaagent:${openTelemetryJavaAgentFile.absolutePath}") + } } } }