How can the classpath used for run
task be displayed under SBT 0.13?
I have found some info here https://groups.google.com/forum/#!msg/simple-build-tool/0rhVRPnjyZU/DOYAd14gh1wJ:
I was dumping my classpaths as a way to troubleshoot my build recently and maybe this task can help you too:
lazy val printClasspath = task { this.runClasspath.getPaths.foreach(println); None }
runClasspath is a PathFinder [1] instance and you can interrogate it even further. I guess building a ':'-separated list of those paths will be easy.
I don't understand where and how I should use this tip. Please advise.
Right click on My Computer and go to properties (or) Press Windows + Pause to open up System Properties. Now traverse to Advanced Tab and click on “Environment Variable”. In order to check the classpath which is set, type echo %CLASSPATH% in command prompt, it will display the CLASSPATH which is set.
Classpath is a parameter in the Java Virtual Machine or the Java compiler that specifies the location of user-defined classes and packages. The parameter may be set either on the command-line, or through an environment variable.
If I type this in the sbt shell:
inspect run
I see, among other output:
[info] Dependencies: [info] runtime:fullClasspath
So then if I type:
show runtime:fullClasspath
I get output like:
List( Attributed(/Users/tisue/Dropbox/repos/euler/target/scala-2.10/classes), Attributed(/Users/tisue/.sbt/boot/scala-2.10.3/lib/scala-library.jar))
Which is probably what you were looking for?
You can also get it in a colon-separated form suitable for use with java -classpath
on the command line:
export runtime:fullClasspath
which prints e.g.:
/Users/tisue/Dropbox/repos/euler/target/scala-2.10/classes:/Users/tisue/.sbt/boot/scala-2.10.3/lib/scala-library.jar
tl;dr Use last run
or write a custom task.
With last run
you should be presented with the entire classpath:
[info] Running main.Main [debug] Waiting for threads to exit or System.exit to be called. [debug] Classpath: [debug] /Users/jacek/work/ingrifo/dictionary-spray/target/scala-2.11/classes [debug] /Users/jacek/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.4.jar [debug] /Users/jacek/.ivy2/cache/io.spray/spray-can_2.11/bundles/spray-can_2.11-1.3.2.jar [debug] /Users/jacek/.ivy2/cache/io.spray/spray-io_2.11/bundles/spray-io_2.11-1.3.2.jar [debug] /Users/jacek/.ivy2/cache/io.spray/spray-util_2.11/bundles/spray-util_2.11-1.3.2.jar [debug] /Users/jacek/.ivy2/cache/io.spray/spray-http_2.11/bundles/spray-http_2.11-1.3.2.jar [debug] /Users/jacek/.ivy2/cache/org.parboiled/parboiled-scala_2.11/bundles/parboiled-scala_2.11-1.1.6.jar [debug] /Users/jacek/.ivy2/cache/org.parboiled/parboiled-core/bundles/parboiled-core-1.1.6.jar [debug] /Users/jacek/.ivy2/cache/io.spray/spray-routing_2.11/bundles/spray-routing_2.11-1.3.2.jar [debug] /Users/jacek/.ivy2/cache/io.spray/spray-httpx_2.11/bundles/spray-httpx_2.11-1.3.2.jar [debug] /Users/jacek/.ivy2/cache/org.scala-lang.modules/scala-xml_2.11/bundles/scala-xml_2.11-1.0.2.jar [debug] /Users/jacek/.ivy2/cache/org.jvnet.mimepull/mimepull/jars/mimepull-1.9.4.jar [debug] /Users/jacek/.ivy2/cache/com.chuusai/shapeless_2.11/jars/shapeless_2.11-1.2.4.jar [debug] /Users/jacek/.ivy2/cache/io.spray/spray-json_2.11/bundles/spray-json_2.11-1.3.1.jar [debug] /Users/jacek/.ivy2/cache/com.typesafe.akka/akka-actor_2.11/jars/akka-actor_2.11-2.3.6.jar [debug] /Users/jacek/.ivy2/cache/com.typesafe/config/bundles/config-1.2.1.jar [debug] Waiting for thread run-main-0 to terminate. [debug] Thread run-main-0 exited. [debug] Waiting for thread default-akka.actor.default-dispatcher-4 to terminate.
If you need to see what the run
task depends on, use inspect
.
[fullclasspath]> inspect run [info] Input task: Unit [info] Description: [info] Runs a main class, passing along arguments provided on the command line. [info] Provided by: [info] {file:/Users/jacek/sandbox/so/fullClasspath/}fullclasspath/compile:run [info] Defined at: [info] (sbt.Defaults) Defaults.scala:704 [info] Dependencies: [info] compile:run::streams [info] runtime:fullClasspath [info] compile:run::runner [info] compile:run::mainClass [info] Delegates: [info] compile:run [info] *:run [info] {.}/compile:run [info] {.}/*:run [info] */compile:run [info] */*:run [info] Related: [info] test:run
In Dependencies
there's the runtime:fullClasspath
setting which means that run
depends on its value.
According to SBT help
, fullClasspath
is...
[fullclasspath]> help fullClasspath The exported classpath, consisting of build products and unmanaged and managed, internal and external dependencies.
You simply need to parse the value of the runtime:fullClasspath
setting.
[fullclasspath]> show runtime:fullClasspath [info] Updating {file:/Users/jacek/sandbox/so/fullClasspath/}fullclasspath... [info] Resolving org.fusesource.jansi#jansi;1.4 ... [info] Done updating. [info] List(Attributed(/Users/jacek/sandbox/so/fullClasspath/target/scala-2.10/classes), Attributed(/Users/jacek/.sbt/boot/scala-2.10.3/lib/scala-library.jar)) [success] Total time: 0 s, completed Feb 13, 2014 1:27:38 AM
To have a more parsable output, use the following task that reads fullClasspath
as defined for the runtime
scope (Runtime
in Scala/SBT code):
lazy val printClasspath = taskKey[Unit]("Dump classpath") printClasspath := { (fullClasspath in Runtime value) foreach { e => println(e.data) } }
Unfortunatelly, the Runtime
configuration is hardcoded and think an input task to accept a configuration would make it so much better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With