17

I have sbt 0.13.2 with a Scala project in IntelliJ 13.0.2.

I just want to change my default ../.ivy2/cache path.

I tried to change following entry in ../bin/sbt file in SBT installation

-Dsbt.ivy.home=D:/IvyHome/.ivy

But no luck.

enter image description here

Even in the IDE I couldn't find the place to update SBT_HOME

What would be the solution?

enter image description here

Shabar
  • 2,617
  • 11
  • 57
  • 98

3 Answers3

26

First of all you have two SBT plugins. The version of Scala plugin you're using already supports SBT, and you don't need an extra plugin. I recommend that you start by removing the extra plugin.

Two Plugins

Remove unofficial plugin

To remove the unofficial plugin go to plugins configuration and remove the check next to the SBT plugin. This will not remove the plugin completely, but will keep it disabled.

Disable Plugin

Change the cache location

Once you have only single plugin, you can modify the location of the cache, by going to options, and searching for sbt. You should find an entry in IDE Settings.

IDE Settings

You should see the VM Parameters. Click the icon next to the input, and add -Dsbt.ivy.home=D:/IvyHome/.ivy in the last line.

Modify Settings

Click OK and restart the IDE after saving all settings.

Now you should be using the new home location (of course this is true only for the builds run from IDE, if you use SBT from console, it will still use an old home setting).

Change the cache location for SBT ran from Console

As pointed out in the paragraph above. This change will not effect SBT ran from console. This is because by default IntelliJ uses bundled SBT.

If you want to modify your Ivy home for sbt, which you run from console, you have several ways of doing that.

I think the simplest is to modify the sbtconfig.txt file in the SBT_HOME/conf/sbtconfig.txt (Windows only - on Linux you'd have to modify sbtopts).

At the end of the file add -Dsbt.ivy.home=D:/IvyHome/.ivy.

The other way would be to modify Launcher Configuration as described in the documentation

Community
  • 1
  • 1
lpiepiora
  • 13,659
  • 1
  • 35
  • 47
  • 1
    Thanks for your reply. I did what you suggest. Then after check the `Project structure>>Library` still I see the path default user profile path (attached screenshot in the question). Then I removed existing jars there and deleted the `.ivy` folder under user profile and ran `sbt gen-idea.` Same results though – Shabar May 27 '14 at 10:27
  • 1
    Have you removed the unofficial plugin? You don't have to run `sbt gen-idea`, just open the project normally from IntelliJ. If you want to use `sbt` from console, you have to configure ivy home for the console installation, for example as it is stated [here](http://www.scala-sbt.org/0.13.2/docs/Launcher/Configuration.html). If you really want to use unofficial plugin, try adding the setting I've described to the _VM Paramters_ visible on your screenshot. – lpiepiora May 27 '14 at 10:35
  • YES I did remove the unofficial plugin and add the VM Parameters as specified – Shabar May 27 '14 at 11:54
  • So how exactly do you run the mentioned `sbt gen-idea` ? – lpiepiora May 27 '14 at 11:55
  • 1
    I went to the project folder and ran `sbt gen-idea`. The reason I ran that was, because I manually deleted `.vy2` folder in default user profile path. After run that command I observed those jars downloaded to the same location despite of location change in _VM Parameters_. BTW why do you say no need of running that command? – Shabar May 27 '14 at 12:05
  • Checkout [this blog post](http://blog.jetbrains.com/scala/2013/11/18/built-in-sbt-support-in-intellij-idea-13/). I will later update the answer to state how to do it for console use of SBT - stay tuned. – lpiepiora May 27 '14 at 12:08
  • attached the screenshot that depicits path issue – Shabar May 27 '14 at 19:55
  • 2
    Do what I have stated in the edited chapter **Change the cache location for SBT ran from Console**, and then delete `.idea`, `.idea_modules` from your project. Regenerate it with `sbt gen-idea`, and open your project, you should see SBT using new locations. – lpiepiora May 27 '14 at 20:11
  • Appreciate your explanation. I am doing something wrong though. So I don't see the result what you mentioned. Few questions to clarify things further. 1. Regarding the path `D:/IvyHome/.ivy` do I need to create `.ivy` folder manually? or just creating `IvyHome` would be enough 2. Currently the folder that get created under user home (which is no the path I expected anyway) after running `sbt gen-idea` is `.ivy2` does that make difference? – Shabar May 28 '14 at 11:40
  • 1
    You should not be needing to create any folders. SBT will create them for you. Start with a simple project and test it there. Make sure you're changing it for the right sbt. In your console type `where sbt`, the `conf` must be in the same installation. The `.ivy2` under the home is the default location, so it seams the settings are not picked up by SBT. – lpiepiora May 28 '14 at 18:58
  • 1
    I tried for simple project then it did work. But for the one I tried from the beginning didn't work yet. Perhaps because of some other setting in that project. Anyway I realized the steps you pointed out. Really appreciated. – Shabar May 29 '14 at 12:15
  • I did what you said but still not working. I am using the most popular plugin named scala. sbt is still downloading packages which I already have downloaded when using sbt from console in the directory /Users/me/.ivry2. – Shady Xu Mar 11 '16 at 05:29
4

I had the same issue with IntelliJ IDEA 14 Build 139.463.4 (Play Framework 2.2.5 project).

I followed the steps below but it did not work for me. I finally fixed the issue by adding to the VM Parameters of the SBT Runner : -Duser.home=D:/Users/myName/ .

The variable user.home is used by the SBT Launcher to build ivy-home variable.

smbikina
  • 81
  • 3
1

The answer suggesting changing IDE settings essentially changed the file .idea/sbt.xml (if you made changes for the project), or C:\Users\***\.IdeaIC14\config\options\project.default.xml (if you made changes for the IDE default regardless which project).

Therefore, you may consider putting this file in source control if you need to change it frequently. (In my case I had to switch between the Spark 1.4 and Spark 1.5 libraries, making this worthwhile.)

Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102