scala - Using IntelliJ, how to add dependency in an sbt project
问题描述
I'm new to sbt and I wanted to learn it with a small Scala project in IntelliJ.
I started with the official sbt Getting Started guide, to learn the sbt basics on the console (https://www.scala-sbt.org/1.x/docs/sbt-by-example.html). Following the guide, everything compiles fine.
Then I created an sbt project in IntelliJ, trying to do the same thing there. When I add the org.scalatest depenpency to the build.sbt file the project can no longer compile. The error message is:
module not found: org.scalatest#scalatest_2.13;3.0.5
When I created the fresh sbt project in IntelliJ, first the build.sbt looked something like this:
name := "sbtTest"
version := "1.0"
scalaVersion := "2.13.0"
Then I added the dependency:
name := "sbtTest"
version := "1.0"
scalaVersion := "2.13.0"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % Test
After reloading the build file and getting the error when compiling, I tried to change the biuld.sbt according to the code which already worked in the sbt Getting Started guide:
ThisBuild / scalaVersion := "2.13.0"
ThisBuild / organization := "me"
ThisBuild / version := "1.0"
lazy val sbtTest = (project in file("."))
.settings(
name := "sbtTest",
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % Test
)
This has again the same error after reloading and compiling.
My sbt version is 1.2.8.
Is something wrong with my build.sbt? Or is the sbt version too new for IntelliJ? Is IntelliJ probably not the recommended IDE to create Sala sbt projects?
解决方案
你的两个结构都可以build.sbt
。这件事似乎在版本中。
Scalatest 3.0.5 目前不适用于 Scala 2.13.0。它适用于 Scala 2.13.0-M2。
Scalatest 3.0.8可用于 Scala 2.13.0。
https://mvnrepository.com/artifact/org.scalatest/scalatest
build.sbt
在弹出窗口中重新导入 IntelliJ 项目中修复版本后
或在 sbt 工具窗口中
或在 sbt 外壳中
推荐阅读
- r - %dopar% 在 foreach 循环中写入 csv 的安全方式
- git - 如何更正 git review 标头中的电子邮件 ID?
- angular - Angular ngx-swiper-wrapper 给出错误 TS2339 属性 'x' 在类型 'y' 上不存在
- node.js - 两个内部 Cloud Run node.js 微服务如何通过 gRPC 成功通信?
- chatbot - 用于邮件机器人/聊天机器人的方法
- android - android studio中的“实际参数列表和形式参数列表长度不同”错误
- wpf - WPF DataGrid - 空白行问题
- javascript - 更新所有 Chart.js 实例以应用更改的默认值?
- python - 如果列表通过,UnboundLocalError 已解决,为什么?
- java - 更改码头 URL