SBT. Clean local repository - scala

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" }

Related

How to download only sbt dependencies into sbt local cache without build of jars?

is is possible to execute such command in sbt to download all jar dependencies (needed for assembly task without build actual target jar? I would like to fullfill local cache (I mean ~/.sbt, ~/.m2 and so on directories). Is there exist such command or way to do it?
The sbt update task does this. This is listed in the sbt Command Line Reference, under Project-level Tasks.

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.

How to create standalone jar file for elastic4s from sources?

I'm trying to create a standalone jar file from the elastic4s sources on github. I've used sbt compile as detailed on the github page, but I can't find the jar file.
How do I use sbt to create the jar file so I can import it into my projects as a dependency?
The compile task will only compile the project.
> help compile
Compiles sources.
If you want to create a jar file and use it as a dependency in your project, you have two ways of doing that.
Unmanaged dependency (not recommended)
Unmanaged dependency run +package, which will create a jar file for each supported scala version, which you can use in your projects as an unmanaged dependency. Copy the package-generated jar to lib folder in your project.
The jar files will be located in target/scala-2.11 and target/scala-2.10, depending on the Scala version you want to use it with.
Publish to Local Repository (recommended yet imperfect)
If you want to include your custom-built elastic4s, as a managed dependency, you have to run +publishLocal. This will do the same as above, but additionally it will publish the artifact to your local repository. Assuming you've built it with version := "1.2.1.1-SNAPSHOT", you can include it in your project by just adding:
libraryDependencies += "com.sksamuel.elastic4s" %% "elastic4s" % "1.2.1.1-SNAPSHOT"
What makes the approach imperfect is that once you shared the project on GitHub (or any other project sharing platform), people will have to do publishLocal themselves to be able to build your project. The dependency should therefore go to one of the official binary repositories so when a dependency is needed, it's downloaded from Internet. Consult Publishing.
What is the + character in front of the commands
The + in the commands is for cross-building, if you don't use it the command will be executed only using scalaVersion declared in the build.sbt of the project.

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

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.

How do I refresh updated Git dependency artifacts in SBT?

I've configured SBT (0.11.0) to pull in a GitHub project as a dependency, as per my answer on this question here.
It works fine except that I can't seem to get SBT to re-compile my Git dependency when it gets updated. In other words: if I make an update to the dependency, push to Git and reload my project's SBT and run package, then SBT does not recompile the external Git dependency when compiling my project.
I've tried creating a new branch in my Git dependency (say, forcenew) and updating the branch in my SBT project configuration to use this:
lazy val depProject = RootProject(uri("git://github.com/me/dep-project.git#forcenew"))
But even this doesn't force a refresh. I'm a bit stumped - I can't even find where SBT puts the Git project to compile it (it doesn't seem to be in ~/.sbt/ or ~/.ivy2/)...
Any help greatly appreciated!
From: https://github.com/sbt/sbt/issues/335
this should be fixed in 0.12.0, just call "sbt update"
It was fixed in 0.12.0 so sbt update is enough, but got back in 13.0 -- for now, you have to wipe dependency from ~/.sbt/staging/ manually
You likely want to clear out ~/.sbt/staging/
A quick hack you can add to your build.sbt:
def removegit = Command.command("removegit"){state =>
val home = sys.env("HOME")
val k = ("rm -rf "+ home + "/.sbt/0.13/staging/").!
state
}
commands ++= Seq(removegit)
And then sbt removegit will wipe that directory. This doesn't do anything smart like checking commits, which would be a great upgrade... The repos are being stored in ~/.sbt/0.13/staging/ on my machine, you may need to adjust that.