Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download sbt plugin source jars in a common sbt project?

Tags:

scala

sbt

It's nature to download the dependencies source jars in a sbt project, using sbt gen-idea or idea's autoimport feature

but how can I download the sbt plugin source jars which I declared in project/plugins.sbt

like image 323
Zava Avatar asked Oct 20 '22 23:10

Zava


1 Answers

IDEA

IDEA should already do this*.

When you import a project and have Download sbt sources checked in Preferences > Build, Execution, Deployment > Build Tools > sbt then it will run the updateSbtClassifiers sbt task.

* Read the Troubleshooting section as there are several known issues with this.


sbt

As mentioned above, you can run the following sbt task:

sbt> updateSbtClassifiers

This command is somewhat special in that it knows to resolve the classifiers for the plugins. It also uses settings that are scoped to that task. See the caveat about sbt/sbt#3432.


Longer way

It is important to understand that sbt is recursive.

Dependencies declared in build.sbt will be for the proper build.

Dependencies declared in project/plugins.sbt will be for the meta-build.

When you just run updateSbtClassifiers it is running this on the proper build, however the dependencies are actually for the meta-build. That is why I said that this task is a little special.

Another way (which can achieve different results) is to run the updateClassifiers task directly on the meta-build.

First switch over to the meta-build:

sbt> reload plugins

Now that you are in the meta-build run:

sbt:project> updateClassifiers

This will retrieve the src and doc for your dependencies (it may not actually do this for some plugins). Run libraryDependencies to see the dependencies of the meta-build.

To get back to the proper

sbt:project> reload return build run:

Troubleshooting

Download failed

You may see in the sbt logs that it failed to download either the src or doc. For example:

[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::              FAILED DOWNLOADS            ::
[warn]  :: ^ see resolution messages for details  ^ ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: rocks.muki#sbt-graphql;0.5.0!sbt-graphql.jar(doc)
[warn]  :: rocks.muki#sbt-graphql;0.5.0!sbt-graphql.jar(src)
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::

If you look just above you will see all the resolvers that it tried. You should see one for sbt-plugin-releases which is where most sbt plugins are published to. See predefined resolvers for more details.

If you do not see that it tried sbt-plugin-releases then chances are you have encountered sbt/sbt#3432.

updateSbtClassifiers does not use the correct resolvers. Add the following to your build.sbt file:

updateSbtClassifiers / dependencyResolution := IvyDependencyResolution((updateSbtClassifiers / ivyConfiguration).value)

Sources not attaching

Even if the updateSbtClassifiers successfully downloads and resolves the src and doc IDEA may not attach them.

This seems to be a bug in the sbt-structure plugin. See SCL-13619 for details.

No attempt at downloading

If for some reason this doesn't download the sources (there is no failed download message) then have a look in your .ivy2/exclude_classifiers file. I'm not entirely sure what this file is for but I do know that sbt will exclude anything that is in here.

In my case it had a whole lot of things that I didn't want excluded so I deleted it and then it worked. Delete at your own risk.

like image 94
steinybot Avatar answered Oct 29 '22 04:10

steinybot