I want to add "org.kohsuke" % "file-leak-detector" % "1.13"
java agent to my sbt configuration.
//plugins.sbt
addSbtPlugin("com.lightbend.sbt" % "sbt-javaagent" % "0.1.5")
//build.sbt
enablePlugins(SbtWeb, PlayScala, DebianPlugin, JavaAgent)
javaAgents += "org.kohsuke" % "file-leak-detector" % "1.13"
but this failed at runtime.
Failed to find Premain-Class manifest attribute in /usr/share/someApp/bin/../file-leak-detector/file-leak-detector-1.13.jar
Error occurred during initialization of VM
agent library failed to init: instrument
I've found that i need jar with dependencies to run it as javaAgent but event if I theoretically could download it from https://repo1.maven.org/maven2/org/kohsuke/file-leak-detector/1.13/
I don't know how to use it with sbt-javaagent
plugin.
I have tried also:
javaAgents += ("org.kohsuke" % "file-leak-detector" % "1.13") from "https://repo1.maven.org/maven2/org/kohsuke/file-leak-detector/1.13/file-leak-detector-1.13-jar-with-dependencies.jar"
but without luck. Any ideas how to force sbt-javaagent plugin to use file-leak-detector-1.13-jar-with-dependencies.jar
instead of file-leak-detector-1.13-jar
?
I think you are doing the right thing using from
to provide explicit URL
If your project requires a dependency that is not present in a repository, a direct URL to its jar can be specified as follows:
libraryDependencies += "slinky" % "slinky" % "2.1" from "https://slinky2.googlecode.com/svn/artifacts/2.1/slinky.jar"
It seems to work on my machine when I provide explicit scope like so
javaAgents += JavaAgent(
"org.kohsuke" % "file-leak-detector-1.13-jar-with-dependencies" % "1.13" % Runtime from "https://repo1.maven.org/maven2/org/kohsuke/file-leak-detector/1.13/file-leak-detector-1.13-jar-with-dependencies.jar",
arguments = "help"
)
Note % Runtime
. I think it works because arguments = "help"
is honoured and sbt run
outputs
sbt:sbt-javaagents-leka> run
[info] running (fork) example.Hello
[error] File leak detector arguments (to specify multiple values, separate them by ',':
[error] help - show the help screen.
[error] trace - log every open/close operation to stderr.
[error] trace=FILE - log every open/close operation to the given file.
[error] error=FILE - if 'too many open files' error is detected, send the dump here.
[error] by default it goes to stderr.
[error] threshold=N - instead of waiting until 'too many open files', dump once
[error] we have N descriptors open.
[error] http=PORT - Run a mini HTTP server that you can access to get stats on demand
[error] Specify 0 to choose random available port, -1 to disable, which is default.
[error] strong - Don't let GC auto-close leaking file descriptors
[error] listener=S - Specify the fully qualified name of ActivityListener class to activate from beginning
[error] dumpatshutdown- Dump open file handles at shutdown
[error] excludes=FILE - Ignore files opened directly/indirectly in specific methods.
[error] File lists 'some.pkg.ClassName.methodName' patterns.
Also if I set arguments = "threshold=1"
it outputs
[info] running (fork) example.Hello
[error] File leak detector installed
[error] 2 descriptors are open
[error] #1 /private/var/folders/y7/33z7gnqn1nl2vwzn26j59xy9rwcgwx/T/sbt_412c7765/target/edca7f33/f7a642d3/scala-library-2.13.1.jar by thread:main on Mon Apr 20 11:51:20 BST 2020
...