Ken
Ken

Reputation: 33

IntelliJ not referencing the correct Scala version on build

I'm using IntelliJ IDEA v2017.3.2 Community Edition and it seems to keep pulling the wrong repo versions for Scala plugins.

I've tried setting scalaVersion := "2.11.8" in build.sbt and idea.sbt, but it keeps trying to pull from 2.12 plugin repos.

My build.sbt is as follows:

import sbt.Keys._
import sbt._
import sbtrelease.{Version => SbtVersion}

name := "lambda-geotrellis-tile-server"

resolvers += Resolver.sonatypeRepo("public")
scalaVersion := "2.11.8"
releaseNextVersion := { ver => SbtVersion(ver).map(_.bumpMinor.string).getOrElse("Error") }

lazy val commonSettings = Seq(
  organization := "com.jisantuc",
  version := "0.0.1",
  cancelable in Global := true,
  scalaVersion := Version.scala,
  scalacOptions := Seq(
    "-deprecation",
    "-unchecked",
    "-feature",
    "-language:implicitConversions",
    "-language:reflectiveCalls",
    "-language:higherKinds",
    "-language:postfixOps",
    "-language:existentials",
    "-language:experimental.macros",
    "-feature"
  ),
  shellPrompt := { s => Project.extract(s).currentProject.id + " > " },
  addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full)
)


libraryDependencies ++= Seq(
  Dependencies.awsJavaCore,
  Dependencies.awsJavaEvents,
  Dependencies.awsJavaLog4j,
  Dependencies.commonsIo,
  Dependencies.geotrellisS3,
  Dependencies.geotrellisRaster,
  Dependencies.geotrellisSpark,
  Dependencies.circeCore,
  Dependencies.circeGeneric,
  Dependencies.circeParser
)

lazy val root = Project("root", file("."))
  .settings(resolvers += "LocationTech GeoTrellis Releases" at "https://repo.locationtech.org/content/repositories/geotrellis-releases")
  .settings(commonSettings:_*)

assemblyMergeStrategy in assembly := {
  case "reference.conf" => MergeStrategy.concat
  case "application.conf" => MergeStrategy.concat
  case n if n.endsWith(".SF") || n.endsWith(".RSA") || n.endsWith(".DSA") => MergeStrategy.discard
  case "META-INF/MANIFEST.MF" => MergeStrategy.discard
  case _ => MergeStrategy.first
}
assemblyJarName in assembly := s"lambda-geotrellis-tile-server.jar"

import S3._
s3Settings
mappings in upload := Seq((file(s"target/scala-2.11/${name.value}.jar"), s"${name.value}.jar"))
host in upload := "lambda-geotrellis-tile-server-jar.s3.amazonaws.com"
progress in upload := true
upload <<= upload dependsOn assembly

initialCommands in console := """
  |import io.circe.parser._
  |import io.circe.syntax._
  |import geotrellis.spark.io._
  |import geotrellis.spark.io.s3._
""".trim.stripMargin

It works fine when building via ./sbt assembly, but when I try to build it in IntelliJ, this happens:

[warn]   file:////home/ken/.sbt/preloaded/com/github/gseitz/sbt-release_2.12_1.0/1.0.0/sbt-release-1.0.0.pom
[warn] ==== sbt-plugin-releases: tried
[warn]   https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.github.gseitz/sbt-release/scala_2.12/sbt_1.0/1.0.0/ivys/ivy.xml
[warn]  module not found: com.eed3si9n#sbt-assembly;0.14.3
[warn] ==== typesafe-ivy-releases: tried
[warn]   https://repo.typesafe.com/typesafe/ivy-releases/com.eed3si9n/sbt-assembly/scala_2.12/sbt_1.0/0.14.3/ivys/ivy.xml
[warn] ==== sbt-plugin-releases: tried
[warn]   https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.eed3si9n/sbt-assembly/scala_2.12/sbt_1.0/0.14.3/ivys/ivy.xml
[warn] ==== local: tried
[warn]   /home/ken/.ivy2/local/com.eed3si9n/sbt-assembly/scala_2.12/sbt_1.0/0.14.3/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/com/eed3si9n/sbt-assembly_2.12_1.0/0.14.3/sbt-assembly-0.14.3.pom
[warn] ==== local-preloaded-ivy: tried
[warn]   /home/ken/.sbt/preloaded/com.eed3si9n/sbt-assembly/0.14.3/ivys/ivy.xml
[warn] ==== local-preloaded: tried
[warn]   file:////home/ken/.sbt/preloaded/com/eed3si9n/sbt-assembly_2.12_1.0/0.14.3/sbt-assembly-0.14.3.pom
[warn] ==== sbt-plugin-releases: tried
[warn]   https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.eed3si9n/sbt-assembly/scala_2.12/sbt_1.0/0.14.3/ivys/ivy.xml
[warn]  module not found: com.typesafe.sbt#sbt-s3;0.9
[warn] ==== typesafe-ivy-releases: tried
[warn]   https://repo.typesafe.com/typesafe/ivy-releases/com.typesafe.sbt/sbt-s3/scala_2.12/sbt_1.0/0.9/ivys/ivy.xml
[warn] ==== sbt-plugin-releases: tried
[warn]   https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.typesafe.sbt/sbt-s3/scala_2.12/sbt_1.0/0.9/ivys/ivy.xml
[warn] ==== local: tried
[warn]   /home/ken/.ivy2/local/com.typesafe.sbt/sbt-s3/scala_2.12/sbt_1.0/0.9/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/com/typesafe/sbt/sbt-s3_2.12_1.0/0.9/sbt-s3-0.9.pom
[warn] ==== local-preloaded-ivy: tried
[warn]   /home/ken/.sbt/preloaded/com.typesafe.sbt/sbt-s3/0.9/ivys/ivy.xml
[warn] ==== local-preloaded: tried
[warn]   file:////home/ken/.sbt/preloaded/com/typesafe/sbt/sbt-s3_2.12_1.0/0.9/sbt-s3-0.9.pom
[warn] ==== sbt-plugin-releases: tried
[warn]   https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.typesafe.sbt/sbt-s3/scala_2.12/sbt_1.0/0.9/ivys/ivy.xml
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: com.github.gseitz#sbt-release;1.0.0: not found
[warn]  :: com.eed3si9n#sbt-assembly;0.14.3: not found
[warn]  :: com.typesafe.sbt#sbt-s3;0.9: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::

..and this becomes permanent, even when trying to build with ./sbt assembly again. I tried finding where that 2.12 comes from, but I saw no configuration file specifying it.

Also, changing scalaVersion in idea.sbt results in this error:

[error] Modules were resolved with conflicting cross-version suffixes in {file:/home/ken/.sbt/1.0/plugins/}global-plugins:
[error]    org.scala-lang.modules:scala-xml _2.11, _2.12
[error]    org.scala-lang.modules:scala-parser-combinators _2.11, _2.12
[error] java.lang.RuntimeException: Conflicting cross-version suffixes in: org.scala-lang.modules:scala-xml, org.scala-lang.modules:scala-parser-combinators

I'm guessing these two modules are used by IntelliJ IDEA?

Upvotes: 1

Views: 2341

Answers (1)

stefanobaghino
stefanobaghino

Reputation: 12794

SBT and your application can (and most probably will) use two different Scala versions (and the one SBT uses is not controlled by the build definition file, but rather by the version of Scala that SBT itself uses). SBT 0.13.x was written in Scala 2.10.x (and that forced plugins to use that version as well) while SBT 1.0.x is now in Scala 2.12.

I believe that you can solve your issue either by downgrading to a version of SBT that supports the plugins you need, or upgrading to a version of the plugins you need that support Scala 2.12/SBT 1.0.x (for example, while sbt-assembly 0.14.3, 0.14.6 does).

Upvotes: 1

Related Questions