How to fully clean, re-resolve and rebuild a Scala sbt-managed project in IDEA?

前端 未结 10 673
一向
一向 2021-02-02 06:18

TL;DR: How can I fully reconcile all dependencies in IntelliJ when SBT file changes

I have a SBT project setup in IntelliJ. For the most part if works l

相关标签:
10条回答
  • 2021-02-02 06:30

    try following steps:

    1. close IntelliJ
    2. backup whole project folder
    3. delete .idea folder
    4. delete target folder
    5. delete project/target folder
    6. reopen IntelliJ and import as a sbt project

    Note this is only for SBT projects

    0 讨论(0)
  • 2021-02-02 06:34

    Agree, that's a PITA. Nothing helped me (I tried "Invalidate/Restart", removing files from ".idea/libraries" and restarting).

    The only way to overcome the problem for me was to manually remove project-related folders from the IntelliJIdea cache. I removed these folders from the following places (I use OSX and IntelliJ-Idea 14):

    • /Users/{UserName}/Library/Caches/IntelliJIdea14/compiler/{ProjectName}
    • /Users/{UserName}/Library/Caches/IntelliJIdea14/compile-server/{ProjectName}

    This helped me, hope it will save time for someone.

    0 讨论(0)
  • 2021-02-02 06:39

    When you save the SBT file, IntelliJ IDEA normally refreshes the project. But if it doesn't, you can do it manually.

    There is a Refresh All SBT Projects button in the SBT Panel:

    On the occasion that IDEA is still confused, not finding packages you just added:

    From the File menu:

    It's a pretty big hammer, requiring a restart of the app, and multi-minute rebuild of the IntelliSense index. But it's occasionally the only thing that will get IDEA to recognize your new SBT packages.

    0 讨论(0)
  • 2021-02-02 06:44

    IDEA 2016.2.4

    None of these solutions worked for me.

    **** BEFORE YOU TRY THE ANY OF ABOVE. MAKE A BACKUP OF THE SBT / IDEA PROJECT IN QUESTION *****

    If I updated the 'build.sbt' then the external library dependencies on the project view did not update. Moreover, the Project Structure still showed the old dependencies. No matter what I tried IDEA would not refresh.

    The only way I could get a partial restore was to copy the '.idea' folder from another machine. SBT plugin implementation is ****ed! I removed the '.idea/libraries' folder beforehand and then IDEA did not restore this folder. I tried many times importing the project again.

    Very bad :(

    ADDENDUM: I managed to get my project working. I think SBT with IDEA is no longer at fault entirely. It could be just possible that my Apache Ivy 2 cache might have been corrupted. So I executed the following commands:

    $ rm -rf ~/.ivy2/cache/org.scalatest/scalatest_2.11/*
    $ rm -rf ~/.ivy2/cache/org.scalactic/scalactic_2.11/*
    

    Restarted IDEA with invalidate cache under the file drop down menu item. This seemed to trigger some internal action in IDEA and SBT. I also tried manually adding add JARs throught the IDE, but it got massively confused. Moral of the story is to work on two different laptops machines daily and keep them updated.

    Also double check SBT from the command line works. I was using 0.13.12

    $ sbt about
    $ sbt clean
    $ sbt test
    

    Also recheck with the SBT dependencies plugin too.

    0 讨论(0)
  • 2021-02-02 06:45

    Another heavy hammer but seems to work.

    1. Close IntelliJ
    2. Delete .idea folder
    3. Import app from existing sources
    0 讨论(0)
  • 2021-02-02 06:47

    I was using different versions of sbt and scala across different proejcts and IntelJi got confused somehow. I am only able to resolve the issue by removing the sbt and ivy2 cache folders:

    rm -rf ~/.ivy2
    rm -rf ~/.sbt
    
    0 讨论(0)
提交回复
热议问题