16
votes

I'm not an expert with sbt so probably my question is a bit noob, but I've notice than when I create a project and download its dependencies with sbt, if I open the project with intellij, all the dependencies are redownloaded again, the same happen in the inverse orden intellij->sbt and also activator..

my (poor) knowledge about sbt is than this use ivy and the dependencies are downloaded in ~/.ivy2/ folder...that is where sbt is downloading my deps, but seems than intellij is using other folder.

personally I don't use so much activator, but I would like configure sbt and intellij for use the same ivy path...

2)recently I publish finagle-postgre to my local ivy using sbt +publishLocal, I can check in my ivy folder

 /home/yo/.ivy2/local/com.twitter/finagle-postgres_2.11/0.1.0-SNAPSHOT

but unfortunately intellij is unable to resolve this dependency, I try adding this line to my build

 resolvers += Resolver.file("Local", file( Path.userHome.absolutePath + "/.ivy2/local"))(Resolver.ivyStylePatterns)

but seems not works

3) the path where is downloaded the dependencies is related to which sbt-launch.jar file is used? How can I know what sbt-lauch.jar file is using sbt right now...

thanks guys!

2
You can set the path to your local ivy repo under a project local .sbtopts file... The default is ~/.ivy2 but if you have it set to ~/.ivy2/local you'll need to update that for your build ~ See DefaultEdward J Beckett

2 Answers

5
votes

If we're talking about IntelliJ appearing to download artifacts after they've already been downloaded by SBT/Activator, then it turns out that it's probably just that IntelliJ is downloading the sources - it's not redownloading the binary artifacts, just the source artifacts that accompany them.

This isn't readily apparent when you're looking at the Refreshing SBT project task in the Background Tasks popup, because the full download path is truncated, so you see something like this:

[info] downloading https://repo1.maven.org/maven2/org/apache/httpcompo...

..it's natural to assume that this is the same binary artifact you already saw SBT download on the console, but you can see the full story if you check the full log (go Help -> Show Log in files and open sbt.last.log in the file browser).

You'll see that the only artifacts getting downloaded end with -sources.jar:

$ grep repo1.maven.org /home/roberto/.IntelliJIdea2016.3/system/log/sbt.last.log 
[info] downloading https://repo1.maven.org/maven2/org/apache/httpcomponents/httpclient/4.3.6/httpclient-4.3.6-sources.jar ...
[info] downloading https://repo1.maven.org/maven2/com/googlecode/javaewah/JavaEWAH/0.7.9/JavaEWAH-0.7.9-sources.jar ...
[info] downloading https://repo1.maven.org/maven2/org/pegdown/pegdown/1.2.1/pegdown-1.2.1-sources.jar ...
[info] downloading https://repo1.maven.org/maven2/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3-sources.jar ...

```

If you don't have the Sources checkbox checked when you're doing Import project, these source downloads won't happen.

tested using IntelliJ 2016.3.5 and Scala plugin v2016.3.9

2
votes

First, the activator is just a launcher for SBT itself, so there should be no difference in behaviour.

Second, IntelliJ also uses the files in ~/.ivy2 by default if you have not told it otherwise (by setting SBT_OPTS environment variable for example, but that depends on your IntelliJ version).

A difference might result if you're using different scala versions (e.g. 2.10.x vs. 2.11.x) when you do not have set the scalaVersion in your project explicitly. Then, each tool would download the corresponding libraries for the appropriate scala version it has configured by default.

Another thing is that IntelliJ will download source and javadoc jars for each dependency if you have enabled that in your settings which might look like it downloads the dependencies again.

Note, I'm wildly guessing here because you have not included any output of the programs you're using, so it's hard to say what the real problem is.