When using a managed dependency, I can tell sbt to download the javadocs and sources:
"mygroup" % "mymodule" % "myversion" withJavadoc() withSources()
But these jars don't seem to be on the runtime classpath?
What I would like to do, is access the javadocs and sources from my application. Can I make these jars appear as managed resources, such that I could do
ClassLoader.getSystemClassLoader.getResource("/my/package/MyDependency.scala")
?
SBT dependency tree If we need to solve the previous problem, we’ll need to inspect the dependencies and transitive dependencies. The solution now depends on our SBT version: For SBT 1.3.x, we need to include the sbt-dependency-graph plugin by adding the following to the project/plugins.sbt file:
This page discusses how sbt builds up classpaths for different actions, like compile, run, and test and how to override or augment these classpaths. In sbt, the classpath includes the Scala library and (when declared as a dependency) the Scala compiler. Classpath-related settings and tasks typically provide a value of type Classpath.
You can exclude source files by name ( butler.scala in the example below) like: Classpaths are also divided into internal and external dependencies. The internal dependencies are inter-project dependencies.
The solution now depends on our SBT version: For SBT 1.3.x, we need to include the sbt-dependency-graph plugin by adding the following to the project/plugins.sbt file: addSbtPlugin ( "net.virtual-void" % "sbt-dependency-graph" % "0.10.0-RC1") For SBT >= 1.4 has built-in support for this plugin, so we just need to add to project/plugins.sbt:
You can do this by adding a classifier.
For a given library dependency, add a javadoc
or sources
classifer
:
libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.0.6" classifier "javadoc"
libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.0.6" classifier "sources"
Then, access its contents from the classpath:
val docStream = getClass.getResourceAsStream("""/scalaz/Monad$.html""")
val doc = io.Source.fromInputStream(docStream).mkString
println(doc)
Here's a working example: https://earldouglas.com/ext/stackoverflow.com/questions/22160701/
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