Skip to content

Agent in scope Test is added to sbt-native-packager scripts #36

@gaeljw

Description

@gaeljw

Actual result

Unlike what the documentation states (or my understanding of it at least :) ), using the Test scope does not prevent a java agent to be added to distributed scripts built with sbt-native-packager.

build.sbt:

lazy val root = (project in file("."))
  .enablePlugins(PlayScala)
  .enablePlugins(JavaAgent)
  .settings(
    javaAgents += "io.opentelemetry.javaagent" % "opentelemetry-javaagent" % "2.18.1",
    javaAgents += "org.mockito" % "mockito-core" % "5.18.0" % Test,
  )

Both agents are added in the start script:

...
addJava "-javaagent:${app_home}/../opentelemetry-javaagent/opentelemetry-javaagent-2.18.1.jar" 
addJava "-javaagent:${app_home}/../mockito-core/mockito-core-5.18.0.jar" 
...

And both JARs are copied in the distribution package as well.

Expected result

I expected to only have the OpenTelemetry agent. The Mockito one should not.

Other attempts

I also tried the following but the setting is reported as unused by sbt and indeed it has no effect:

Test / javaAgents += "org.mockito" % "mockito-core" % "5.18.0" % Test,

Other

This is quite important as Mockito should be used through its java agent starting Java 21 and it will be mandatory in Java 24+. And obviously, it doesn't make sense at production runtime to have it.

I can provide a minimal reproducible example if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions