Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SBT project refresh failed [IntelliJ, Scala, SBT]

Whenever I try to enable auto-import in IntelliJ it always gives me this error:

SBT 'Example' project refresh failed

Error while importing SBT project:
...
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/org/scalatest/scalatest_2.12/2.2.6/scalatest_2.12-2.2.6.pom
[info] Resolving org.scala-lang#scala-compiler;2.12.0 ...
[info] Resolving org.scala-lang#scala-reflect;2.12.0 ...
[info] Resolving org.scala-lang.modules#scala-xml_2.12;1.0.5 ...
[info] Resolving jline#jline;2.14.1 ...
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: org.scalatest#scalatest_2.12;2.2.6: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn] 
[warn]  Note: Unresolved dependencies path:
[warn]      org.scalatest:scalatest_2.12:2.2.6 (/Users/sarahbaka/Desktop/Scala/Example/build.sbt#L7-8)
[warn]        +- default:example_2.12:1.0
[trace] Stack trace suppressed: run 'last *:update' for the full output.
[trace] Stack trace suppressed: run 'last *:ssExtractDependencies' for the full output.
[error] (*:update) sbt.ResolveException: unresolved dependency: org.scalatest#scalatest_2.12;2.2.6: not found
[error] (*:ssExtractDependencies) sbt.ResolveException: unresolved dependency: org.scalatest#scalatest_2.12;2.2.6: not found
[error] Total time: 4 s, completed 08-Nov-2016 22:24:34</pre><br/>

I already installed the JetBrains Scala plugin, then opened a directory with an SBT build and reset/restarted my cache (File -> Invalidate Caches / Restart). But it still doesn't work! Does anyone know why?

like image 646
sarah Avatar asked Nov 08 '16 22:11

sarah


People also ask

How do I change the version of SBT in a project?

You can override the sbt version in your project's build.properties file. Create or open your sbt project. In the Project tool window, in the source root directory, locate the build.properties file and open it in the editor. In the editor explicitly specify the version of sbt that you want to use in the project.

How do I reload all projects in SBT?

To reload all sbt projects, click on the toolbar, in the sbt tool window. In the Settings/Preferences dialog Ctrl+Alt+S, go to Build, Execution, Deployment | Build Tools. Alternatively, In the sbt tool window, click and select the Auto-Reload Settings option.

How do I add SBT dependencies to my project?

You can add sbt dependencies via the build.sbt file or you can use the import statement in your .scala file. Open a .scala file in the editor. Specify a library you want to import. Put the caret at the unresolved package and press Alt+Enter.

What is SBT file in IntelliJ IDEA?

When you work with sbt projects you use the build.sbt file to make main changes to your project since IntelliJ IDEA considers the sbt configuration as a single source of truth. Every time you manually change build.sbt in the editor, you need to load the changes.


1 Answers

Your scalatest dependency is misconfigured. You want scalatest version 2.6 published for Scala 2.12. There is no such combination, hence your build fails. If you have a look at which version of scalatest is available for Scala 2.12, here's the link. As you can see, it's only version 3.0.0. So, you have 3 options (those are changes in your build.sbt file you need to make):

  1. Update your scalatest version to 3.0.0: libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.0" % Test
  2. Downgrade your Scala version to 2.11: scalaVersion := "2.11.8"
  3. Both of the above

I'd say it's a bit too early to use Scala 2.12, since it was only released a couple of days ago, and not all of the dependencies are published for it yet. Scala major versions (2.11 vs 2.12 is a major version upgrade for Scala) are not binary compatible, so you can't use a library compiled with one Scala version in a project that uses the other.

At the same time, I'd go with scalatest 3.0.0 version, since it's the stable one. So all in all, I'd go for option 3 at the moment, even though options 1 and 2 will fix this particular problem, in different ways.

like image 182
Haspemulator Avatar answered Sep 29 '22 22:09

Haspemulator