Giter VIP home page Giter VIP logo

sbt-javaagent's Introduction

sbt-javaagent

This sbt plugin adds Java agents to projects in a general way. It can enable agents in sbt-native-packager dists, as compile-time dependencies, in forked run, or in forked tests.

Plugin dependency

Add the plugin to your project/plugins.sbt:

addSbtPlugin("com.lightbend.sbt" % "sbt-javaagent" % versionNumber)

See sbt-javaagent releases for a list of released versions.

Java agent

To add a Java agent to an sbt-native-packager distribution, enable the JavaAgent plugin on a project that also has JavaAppPackaging enabled, and then add the agent dependency using the javaAgents setting. For example:

lazy val distProject = project
  .in(file("somewhere"))
  .enablePlugins(JavaAgent, JavaAppPackaging)
  .settings(
    javaAgents += "com.example" % "agent" % "1.2.3"
  )

This will automatically resolve the agent module, bundle the agent artifact in the distribution, and add a -javaagent option to the start script.

Note: sbt-javaagent has a dynamic dependency on sbt-native-packager. You need to add sbt-native-packager separately.

Scopes

By default, sbt-javaagent will only add an agent to distributions. Agents can be optionally enabled for compile, run, or test.

The following scopes are supported:

  • dist — bundle the agent in production distributions and add a -javaagent option to start scripts
  • compile — add the agent as a provided dependency so that it's available on the compile classpath
  • runtime — automatically fork the run and add a -javaagent option
  • test — automatically fork tests and add a -javaagent option

The plugin can derive these scopes from module configurations.

For example, to add an agent to compile, to build against an API provided by an agent, use the compile or provided configuration:

javaAgents += "com.example" % "agent" % "1.2.3" % "compile"

Marking a dependency for compile will also automatically enable the agent for run as well.

To enable for run or tests, use the runtime or test configurations.

Multiple configurations can be specified. For example, the following will enable both compile and test (and implicitly run):

javaAgents += "com.example" % "agent" % "1.2.3" % "compile;test"

Note that in this case, the agent dependency is actually added under the provided configuration, so that a project can compile against the agent and then have the agent provided at runtime using a -javaagent option.

If the compile scope is not enabled, then the agent dependency is put under a special javaagent configuration so that it doesn't appear as a regular library dependency or on build classpaths.

Agent arguments

A Java agent can have an extra argument string added to it that is provided to the premain method in the agent. To add an argument string simply provide it to the JavaAgent constructor.

javaAgents += JavaAgent("com.example" % "agent" % "1.2.3" % "compile;test", arguments = "java_agent_argument_string")

sbt-javaagent's People

Contributors

pvlugter avatar bantonsson avatar dwijnand avatar stuffandthings avatar wsargent avatar ygree avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.