Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloading source jars in sbt?

Tags:

sbt

I pulled down the sources and build/published it locally. I want to debug into sources jars. When I publish it locally, I clearly see it also publishes source jars.

[info]  published securesocial-testkit_2.10 to local\ws.securesocial\securesocial-testkit_2.10\master-SNAPSHOT\srcs\securesocial-testkit_2.10-sources.jar

I don't know how to reference this jar.

Changing "ws.securesocial" %% "securesocial" % "master-SNAPSHOT" to "ws.securesocial" %% "securesocial" % "master-SNAPSHOT-sources" doesn't work.

like image 487
zinking Avatar asked Apr 23 '14 14:04

zinking


People also ask

Where are SBT jars?

All new SBT versions (after 0.7. x ) by default put the downloaded JARS into the . ivy2 directory in your home directory. If you are using Linux, this is usually /home/<username>/.

Where are SBT dependencies?

Solution. You can use both managed and unmanaged dependencies in your SBT projects. If you have JAR files (unmanaged dependencies) that you want to use in your project, simply copy them to the lib folder in the root directory of your SBT project, and SBT will find them automatically.

What is source jar?

That sources jar is a jar that contains only the source code (the . java files) corresponding to the compiled artifact. It is useful to add it as a source attachment in your IDE, to publish the sources, etc. As it only contains sources, not compiled classes (. class files), it is of no use as a library dependency.


2 Answers

Add withSources() to the dependency definition.

From Download Sources in the official documentation of sbt:

Downloading source and API documentation jars is usually handled by an IDE plugin. These plugins use the updateClassifiers and updateSbtClassifiers tasks, which produce an Update Report referencing these jars.

To have sbt download the dependency's sources without using an IDE plugin, add withSources() to the dependency definition. For API jars, add withJavadoc(). For example:

libraryDependencies += "org.apache.felix" % "org.apache.felix.framework" % "1.8.0" withSources() withJavadoc()

Note that this is not transitive. Use the update-*classifiers tasks for that.

like image 71
Jacek Laskowski Avatar answered Oct 04 '22 18:10

Jacek Laskowski


You can also run sbt update-classifiers to download sources and javadoc jars for all project dependencies at once

For sbt 1.0, command is sbt updateClassifiers

like image 39
anthavio Avatar answered Oct 04 '22 19:10

anthavio