Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force sbt to redownload dependencies when ivy cache corrupted

Tags:

sbt

when ivy cache is corrupted I got the following error from sbt

[error] unresolved dependency: commons-codec#commons-codec;1.10: configuration not found in commons-codec#commons-codec; 1.10: 'master(compile)'. Missing configuration: 'compile'. It was required from com.typesafe.play#play_2.11;2.4.3 compile

if I delete the folder commons-codec in ivy cache and run sbt update, sbt will re-download the dependencies and everything will be fine.

Is there a way to tell sbt to delete the folder and re-download dependencies automatically?

like image 488
ACO Avatar asked Oct 30 '15 11:10

ACO


People also ask

How do you clean Ivy cache?

Clearing the Ivy cache The Ivy cache can become corrupted, especially when using the http type in the repositories section of conf/dependencies. yml . If this happens, and dependency resolution does not work, you can clear the cache with the --clearcache option. This is equivalent to rm -r ~/.

Where are SBT dependencies stored?

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

What does SBT update do?

update resolves dependencies according to the settings in a build file, such as libraryDependencies and resolvers . Other tasks use the output of update (an UpdateReport ) to form various classpaths. Tasks that in turn use these classpaths, such as compile or run , thus indirectly depend on update .


2 Answers

It's pretty easy, just

rm -fr ~/.ivy2/cache # Or mv ~/.ivy2/cache ~/.ivy2/cache_bk
sbt update

Finally if you are in Intellij, File -> Invalidate Caches / Restart.

I just did the same thing 20 minutes ago. Probably not a bad thing either. I just saved a pretty big chunk of space on my mac.

Atom:~ me$ du -skh ./.iv*
349M    ./.ivy2
1.0G    ./.ivy2_bak

[Added 6-May-2021]

If you remove ~/.ivy2 and all your stuff still assembles, cleans, tests, etc. without re-downloading, you might be using another tool, like sdkman, that puts cached files in a different place. Wipe that cache like so.

pwd
~/Library/Caches/Coursier/v1/https/repo1.maven.org
mv ./maven2/ ./_maven2-backup 

As a word of caution, it is probably best backup your cache files rather than just wiping them. There are cases, like internally developed bad packages, that you might need to copy over from the backup to the new download. Back it up, rebuild your project, then rm -fr the backup.

like image 146
Tony Fraser Avatar answered Sep 20 '22 06:09

Tony Fraser


  # empty the ivy cache if you have good network
  # rm -rfv ~/.ivy2/cache/*

  # or even better just backup it to sync it later on ...
  # mv ~/.ivy2/cache ~/.ivy2/cache.`date "+%Y%m%d_%H%M%S`.bak


  # remove all sbt lock files
  find ~/.sbt ~/.ivy2 -name "*.lock" -print -delete
  find ~/.sbt ~/.ivy2 -name "ivydata-*.properties" -print -delete


  # remove all the class files
  rm -fvr ~/.sbt/1.0/plugins/target
  rm -fvr ~/.sbt/1.0/plugins/project/target
  rm -fvr ~/.sbt/1.0/target
  rm -fvr ~/.sbt/0.13/plugins/target
  rm -fvr ~/.sbt/0.13/plugins/project/target
  rm -fvr ~/.sbt/0.13/target
  rm -fvr ./project/target
  rm -fvr ./project/project/target

  sbt clean update
like image 35
Yordan Georgiev Avatar answered Sep 22 '22 06:09

Yordan Georgiev