sbt retrieveManaged doesn't pick up jars produced using publish-local - scala

Suppose I have a project in which I've used sbt publish-local to generate local copies of the jar files in ~/.ivy2/local.
Another sbt project on the same machine can successfully locate these jars to satisfy dependencies. However, if in that project I use the option retrieveManaged := true, sbt never copies the jars out of ~/.iv2/local into the lib_managed directory.
How can I make this happen? (Is this behaviour intended?)
(I'm using sbt 0.12.1.)

I am using the same setup. When I update my locally published dependencies, I remove the managed jars first and then run the update:
$ rm -r lib_managed/jars/my-package-prefix
$ sbt test:compile
(test:compile will figure out that the jars are missing and do the update by itself).
In older versions of sbt I believe there was an issue when using -SNAPSHOT versions, but I haven't seen this problem anymore with sbt 0.12.
In rare situations, something messes up with the Ivy cache and somehow you cannot enforce the updates. This is perhaps the case when corrupt Ivy meta data files have been used. Then the only solution is to wipe all occurrences of your dependency from ~/.ivy2/local and ~/.ivy2/cache, re-publish, and re-update.

Related

Why does sbt keep downloading my snapshot dependencies?

I have an SBT project that depends on two snapshot dependencies. Every time I build it, it goes off to the remote repository to fetch the dependencies. This is true even if I set offline := true.
When I look at how it is trying to resolve the local dependencies, the build is saying it is looking in "local", i.e., ~/.ivy2/local/... -- which is a nonexistent directory.
The jars are in ~/.ivy2/cache/... and this is where SBT downloads them when it pulls the dependencies from the remote server.
I have searched my .sbt and .scala build files and the string "local" does not appear in them in connection with a repository or cache.
SBT is at version 0.13.11 building against scala 2.11.8.
Why is SBT doing this, and how can I get it to see the cached jars?
If you want to prevent SBT from trying to download from official repositories you could simply create a file project/offline-repositories:
[repositories]
mirror-central: file:////nexus/central
mirror-maven-central-org: file:////nexus/maven-central-org
...
(/nexus/central and /nexus/maven-central-org should contain a (partial) mirror of what you need offline)
Then call sbt with the sbt.repository.config property configured:
-Dsbt.override.build.repos=true \
-Dsbt.repository.config=./project/offline-repositories
For Reference:
http://www.scala-sbt.org/0.13/docs/Proxy-Repositories.html
How to prevent SBT from trying to download from official repositories?
EDIT
If you want to use your ~/.m2 cache:
[repositories]
mirror-central: file:////home/XXXXX/.m2/repository
mirror-maven-central-org: file:////home/XXXXX/.m2/repository
...
This apparently is because in my Ivy cache I had a file named ~/.ivy2/cache/com.xxx/xxx-utils/ivy-2.3.2-SNAPSHOT.xml.original , which the build was trying and failing to parse. I'm not sure where this file came from; conceivably it was put there manually ages ago.

Why does sbt report "Error: Could not retrieve sbt 0.13.11"?

In a Scala project I updated the build.properties from 0.13.8 to 0.13.11. That "broke" sbt as it does not start anymore, i.e. it cannot download the 0.13.11 jars?! sbt prints a list of tried repo's, but the repo.typesafe.com was not one of them.
My local installed sbt is 0.13.8.
For some reason the scala-sbt jars are not available anymore in Typesafe's Bintray. Largest version there is 0.13.9.
I know the place to get it is https://repo.typesafe.com/typesafe/ivy-releases/, but how do I tell sbt to use this repo?
I have already tried:
adding a resolver to plugins.sbt
adding a resolver to build.sbt
adding the repo to .sbt/repositories
but I cannot get it working.
How to tell sbt where to get binaries?
Make sure that you're using sbt (launcher) that's at the same version of higher than the version used in your project.
Execute sbt about in an empty directory and find [info] This is sbt X.Y.X.
Make sure that you don't use ~/.sbt/repositories file that sets up the repositories used to resolve artifacts.
try to set your https proxy Information into http.proxyHost and http.proxyPort. This solved it for me.

intellij/activator/sbt are downloading dependencies previously downloaded by the other

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!
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
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.

SBT. Clean local repository

How I can delete my project from local repository? I previously published it using publish-local SBT command.
I want to clean all compiled and cached stuff because I don't see any changes in my project after recompiling it and redeploying on server.
If you want to retry sbt publishLocal, add your module version x.x.x-SNAPSHOT.
Run publishLocal again and note where it writes the published jars to. For me, it was ~/.ivy2/local. Removing this directory cleared the locally published repository.
There is a sbt command clean. if you need you can add additional folders to clean task in your build file
cleanFiles <+= baseDirectory { base => base / "temp" }

How to build a jar file out of github project in sbt to be used in a scala program

I am trying to use scala to access Amazon's DynamoDB and found this great package on github https://github.com/piotrga/async-dynamo
so I downloaded the code as a zip file , unzipped it and then did "sbt clean test" and getting the following error
error sbt.ResolveException: unresolved dependency: asyncdynamo#async-dynamo;1.6.0: not found
Questions : is this the correct way to generate a jar file that I can include in my Scala program or is there a better way?
thanks in advance.
EDIT:
just for the benefit of others, the SCALA SBT documentation provides lots of information regarding the build process.
Instead of generating a jar file, you can just run 'sbt publish-local' and then include the lines for the managed dependency in the other project.
Sbt/ivy will see you have the artifact that way you don't need to add the jar to the other project which is much cleaner.
Then for example if you need to update the other project you don't need to replace the jar again - just publish-local again and clean and run your other project!
You are not the only one to have problems with this it seems, see github issues page:
https://github.com/piotrga/async-dynamo/issues
The command 'sbt clean test' will run the tests sbt detects. If you want a .jar file you could use 'sbt clean package', which produces a .jar in the target/ folder.
I cloned the repo and was able to run sbt package after changing release.sbt a bit. I had to change the 'publishTo'-variable as it seemed to depend on the repository creators local environment variable, so I just commented it away.
I did not get the dependency problem, so I suppose it is correctly declared. The tests it tries to run do fail though, but sbt package compiles produces the .jar just fine.
EDIT: As Matthias Schlaipfer pointed out in the comments, the more elegant way(and much easier) would just be to add this as an depency in your build.sbt. From the readme, this is what you need to add:
resolvers += "piotrga" at
"https://github.com/piotrga/piotrga.github.com/tree/master/maven-repo"
libraryDependencies += "asyncdynamo" % "async-dynamo" % "1.6"