title: Conditional JavaAgent Command for SBT Native Packager
body: <p>I'm using scala, sbt, sbt-native-package, and potentially sbt-java-agent to conditionally activate a datadog java agent at runtime w/ kubernetes.</p>
  <p>By adding the <code>dd-java-agent</code> as a dependency and adding a script snippet, I'm able to activate datadog only when a specific env. variable is set, but this is also adding the dd-java-agent to the classpath, which I'm trying to avoid:</p>
  <pre class="lang-scala prettyprint-override"><code>val DataDogAgentVersion = &quot;0.70.0&quot;
  
  libraryDependencies += &quot;com.datadoghq&quot; % &quot;dd-java-agent&quot; % DataDogAgentVersion % &quot;runtime&quot;
  
  bashScriptExtraDefines += &quot;&quot;&quot;if [ &quot;$DD_PROFILING_ENABLED&quot; = &quot;true&quot; ]; then addJava &quot;-javaagent:${app_home}/../lib/dd-java-agent-&quot;&quot;&quot; + DataDogAgentVersion + &quot;&quot;&quot;.jar&quot;; fi&quot;&quot;&quot;&quot;
  </code></pre>
  <p>Is there a way to have sbt manage the downloading of dd-java-agent.jar, include this jar in the <code>lib</code> directory (or a different directory if that's what it takes), but exclude from classpath?</p>
  <p>I've tried using <code>sbt-java-agent</code> which puts the jar in a <code>dd-java-agent</code> directory and excludes the jar from the classpath, but I can not figure out how to wrap the <code>addJava</code> statement in an <code>if</code> check when using that plugin.</p>
  <p>Thanks for any help you can provide!</p>