ScalaJS Project: SBT dependency on Leaflet not resolved - intellij-idea

I have a ScalaJS project built in IntelliJ with SBT in which I'd like to include a slippy map based on the Leaflet library.
I'm using ScalaJS version 0.6.19 and SBT version 0.13.7
My build.sbt is the following:
import com.lihaoyi.workbench.Plugin.{bootSnippet, updateBrowsers}
enablePlugins(ScalaJSPlugin)
workbenchSettings
name := "WeatherReport"
version := "0.1-SNAPSHOT"
scalaVersion := "2.11.11"
libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % "0.9.1"
,"org.scala-js" %%% "scalajs-java-time" % "0.2.2"
,"com.lihaoyi" %%% "scalatags" % "0.6.5"
,"org.webjars.npm" %%% "leaflet" % "0.7.7"
)
bootSnippet := "com.sap.demo.WeatherReport().main(document.getElementById('weatherDiv'));"
updateBrowsers <<= updateBrowsers.triggeredBy(fastOptJS in Compile)
This was all working fine until I added the last dependency on leaflet. Now SBT complains:
Error:Error while importing SBT project:
...
[info] Resolving org.eclipse.jetty#jetty-util;8.1.16.v20140903 ...
[info] Resolving org.eclipse.jetty#jetty-io;8.1.16.v20140903 ...
[info] Resolving org.eclipse.jetty#jetty-http;8.1.16.v20140903 ...
[info] Resolving org.eclipse.jetty#jetty-server;8.1.16.v20140903 ...
[info] Resolving org.eclipse.jetty.orbit#javax.servlet;3.0.0.v201112011016 ...
[info] Resolving org.eclipse.jetty#jetty-continuation;8.1.16.v20140903 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: org.webjars.npm#leaflet_sjs0.6_2.11;0.7.7: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn] Note: Unresolved dependencies path:
[warn] org.webjars.npm:leaflet_sjs0.6_2.11:0.7.7 (/Developer/Scala/weather-report/build.sbt#L13-19)
[warn] +- weatherreport:weatherreport_sjs0.6_2.11:0.1-SNAPSHOT
[trace] Stack trace suppressed: run 'last *:ssExtractDependencies' for the full output.
[trace] Stack trace suppressed: run 'last *:update' for the full output.
[error] (*:ssExtractDependencies) sbt.ResolveException: unresolved dependency: org.webjars.npm#leaflet_sjs0.6_2.11;0.7.7: not found
[error] (*:update) sbt.ResolveException: unresolved dependency: org.webjars.npm#leaflet_sjs0.6_2.11;0.7.7: not found
[error] Total time: 1 s, completed 31-Aug-2017 10:26:54
As fas a I can tell from the leaflet entry on the WebJars website, I've got the group/artifact/version information correct.
I'm not clear on why the error message has added "_sjs0.6_2.11" to the library name. Is this because there needs to be some version of leaflet specific to ScalaJS?
Thanks
Chris W

Your are confusing Webjars, which are .jars containing .js libraries published on Maven, with Scala.js libraries, which also .jars published on Maven, but containing Scala.js' .sjsir files.
Depending on the JS libraries in Webjars is typically done with jsDependencies in a Scala.js sbt build, not with libraryDependencies. Therefore, they should also use % instead of %%%. For example:
jsDependencies += "org.webjars.npm" % "leaflet" % "0.7.7" / "dist/leaflet.js"
Now you will probably also want Scala.js facades to talk to Leaflet using static types. Fortunately for you, such a facade library already exists. Since a facade library is a Scala.js library (as opposed to a JS library in a Webjar), that would be specified in libraryDependencies, with %%%. However it seems that that particular library is not (yet) published on Maven Central, so you might have to locally publish it yourself.

Related

Intellij IDEA + SBT: skip download errors for non-existing Sources/Javadocs

In Intellij IDEA (2016), with Download: Sources and Javadocs enabled, (can't insert image inline due to lack of reputation)
SBT will attempt to download Sources and Javadocs for all dependencies, whether or not they exist.
Problem is, when a dependency (or worse, nested dependency) does not have a Source/Javadoc, the build will fail.
Is there any way to configure IDEA/SBT to check and skip downloading Sources/Javadocs if it does not exist, or ignore errors when downloading Sources/Javadocs, without having to append
withSources() withJavadoc()
to every dependency?
For example, a dependency relying on Antlr 2.7.7, which does not have Javadocs (antlr-2.7.7-javadoc.jar) in Maven Central (https://repo1.maven.org/maven2/antlr/antlr/2.7.7/), with Download: Javadoc enabled, will return error:
SBT project import
[warn] [FAILED ] antlr#antlr;2.7.7!antlr.jar(doc): (0ms)
[warn] ==== local: tried
[warn] C:\Users\Daniel\.ivy2\local\antlr\antlr\2.7.7\docs\antlr-javadoc.jar
[warn] ==== public: tried
[warn] https://repo1.maven.org/maven2/antlr/antlr/2.7.7/antlr-2.7.7-javadoc.jar
[warn] ==== activator-launcher-local: tried
[warn] C:\Users\Daniel\.activator\repository\antlr\antlr\2.7.7\docs\antlr-javadoc.jar
[warn] ==== activator-local: tried
In Idea Settings > Build ... > Build Tools > sbt: uncheck Download Library sources and sbt sources

Junit not working on SBT in Play! Framework project on Intellij 14

i'm having some troubles with tests in Intellij, i created a new project with
activator new my-project
then opened that projected with intellij, i marked all boxes for SBT to auto-download and create empty folders, etc.
Well after the project is opened and loaded all SBT stuff i have some errors.
First with versions:
SBT project import
[warn] Multiple dependencies with the same organization/name but different versions. To avoid conflict, pick one version:
[warn] * org.apache.httpcomponents:httpclient:(4.0.1, 4.3.4)
[warn] * com.google.guava:guava:(18.0, 16.0.1)
[warn] * junit:junit:(4.12, 4.11)
[warn] * org.apache.httpcomponents:httpcore:(4.0.1, 4.3.2)
[warn] * commons-logging:commons-logging:(1.1.1, 1.1.3)
[warn] * org.scala-lang.modules:scala-parser-combinators_2.11:(1.0.1, 1.0.3)
[warn] * org.scala-lang.modules:scala-xml_2.11:(1.0.1, 1.0.3)
then with the junit
i looked up and there is some solutions to the vesion problem, but they didn't work for me and i have nothing about the junit thing.
Tests work on terminal but i can't have markdown in intellij
There are indeed some conflicting dependencies with some of the libraries.
To work around the JUnit conflict, you can add:
"junit" % "junit" % "4.12" % "test"
to the libraryDependencies in build.sbt.

Why does building Spark sources give "object sbt is not a member of package com.typesafe"?

I tried to compile the https://github.com/apache/spark project using IntelliJ IDEA with the sbt plugin on Windows.
I'm facing an error about sbt. Since I'm not familiar with sbt, I don't know how to fix it.
The error messages are as follows:
[info] Loading project definition from F:\codeReading\sbtt\spark-master\project
[info] Compiling 3 Scala sources to F:\codeReading\sbtt\spark-master\project\target\scala-2.10\sbt-0.13\classes...
[error] F:\codeReading\sbtt\spark-master\project\SparkBuild.scala:26: object sbt is not a member of package com.typesafe
[error] import com.typesafe.sbt.pom.{PomBuild, SbtPomKeys}
[error] ^
[error] F:\codeReading\sbtt\spark-master\project\SparkBuild.scala:51: not found: type PomBuild
[error] object SparkBuild extends PomBuild {
[error] ^
[error] F:\codeReading\sbtt\spark-master\project\SparkBuild.scala:118: not found: value SbtPomKeys
[error] otherResolvers <<= SbtPomKeys.mvnLocalRepository(dotM2 => Seq(Resolver.file("dotM2", dotM2))),
[error] ^
[error] F:\codeReading\sbtt\spark-master\project\SparkBuild.scala:178: value projectDefinitions is not a member of AnyRef
[error] super.projectDefinitions(baseDirectory).map { x =>
[error] ^
[error] four errors found
[error] (plugins/compile:compile) Compilation failed
Spark is built with Maven. The SBT build is only a convenience. You will have far better results importing it as a Maven project.
It looks like IDEA doesn't like project references to git projects that the Spark build definition uses for sbt-pom-reader.
It's showed up when I ran sbt within the cloned project:
➜ spark git:(master) ✗ xsbt
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Loading project definition from /Users/jacek/oss/spark/project/project
[info] Loading project definition from /Users/jacek/.sbt/0.13/staging/ec3aa8f39111944cc5f2/sbt-pom-reader/project
[warn] Multiple resolvers having different access mechanism configured with same name 'sbt-plugin-releases'. To avoid conflict, Remove duplicate project resolvers (`resolvers`) or rename publishing resolver (`publishTo`).
[info] Loading project definition from /Users/jacek/oss/spark/project
[info] Set current project to spark-parent (in build file:/Users/jacek/oss/spark/)
>
You can see the project reference to the git project of sbt-pom-reader when accessing the plugins project for which the reference is defined:
> reload plugins
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Loading project definition from /Users/jacek/oss/spark/project/project
[info] Updating {file:/Users/jacek/oss/spark/project/project/}project-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Loading project definition from /Users/jacek/.sbt/0.13/staging/ec3aa8f39111944cc5f2/sbt-pom-reader/project
[warn] Multiple resolvers having different access mechanism configured with same name 'sbt-plugin-releases'. To avoid conflict, Remove duplicate project resolvers (`resolvers`) or rename publishing resolver (`publishTo`).
[info] Updating {file:/Users/jacek/.sbt/0.13/staging/ec3aa8f39111944cc5f2/sbt-pom-reader/project/}sbt-pom-reader-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Loading project definition from /Users/jacek/oss/spark/project
> projects
[info] In file:/Users/jacek/oss/spark/project/
[info] * plugins
[info] spark-style
[info] In https://github.com/ScrapCodes/sbt-pom-reader.git
[info] sbt-pom-reader
A solution could be executing sbt gen-idea to generate the project files for IDEA. It's just a guess, though.

Unresolved dependencies reported by sbt 0.13 in IntelliJ IDEA CE 12

I'm using IntelliJ IDEA CE 12 for Scala development. I have installed SBT plugin. Currently my ~/.sbt/0.13/plugins/build.sbt looks like this:
resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.7.0-SNAPSHOT")
My project was imported to IDEA without auto-import.
I noticed that my Scala classes are not able to find some imports, but I'm able to compile the project and run - so it works.
Developing with missing imports is quit hard ;) so I ran successfully gen-idea and tried to import my project once more with auto-import on. Unfortunately, I got the following error:
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: com.typesafe.slick#slick_2.9.2;2.0.0: not found
[warn] :: io.spray#spray-json_2.9.2;1.2.5: not found
[warn] :: com.typesafe.akka#akka-actor_2.9.2;2.2.0-RC1: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
The project's built.sbt is as follows:
resolvers ++= List(
"spray repo" at "http://repo.spray.io/",
"Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
)
libraryDependencies ++= List(
"com.typesafe.slick" %% "slick" % "2.0.0",
"postgresql" % "postgresql" % "8.4-701.jdbc4",
"org.xerial" % "sqlite-jdbc" % "3.6.20",
"io.spray" % "spray-can" % "1.2-M8",
"io.spray" % "spray-routing" % "1.2-M8",
"io.spray" %% "spray-json" % "1.2.5",
"com.typesafe.akka" %% "akka-actor" % "2.2.0-RC1",
"org.slf4j" % "slf4j-api" % "1.7.1"
)
How can I resolve the dependencies in IDEA? Thanks in advance!
UNRESOLVED DEPENDENCIES are always about the small bits in dependencies that make sbt unable to find them in the available repositories.
You should always inspect the resolvers and libraryDependencies settings (as you did), but please note %% to construct a dependency.
From Getting the right Scala version with %%:
If you use groupID %% artifactID % revision rather than groupID % artifactID % revision (the difference is the double %% after the
groupID), sbt will add your project's Scala version to the artifact
name. This is just a shortcut.
So, the combination of resolvers, libraryDependencies and %% (and scalaVersion) are usually causing many troubles to people new to sbt (and in fact, the other build tools as they too have to find the dependencies a developer sets in their project build files).
Use http://mvnrepository.com/ to check out whether your dependency is actually downloadable.
Let's pick, "com.typesafe.slick" %% "slick" % "2.0.0". Given no scalaVersion specified in your build.sbt file (or any other build files), the %% was resolved to the default Scala version of the sbt launcher you use -- it could be 2.9.1 or 2.10.3 or something else. Somehow (I can't explain why given the information you provided) it picked 2.9.2. There's no Slick at http://mvnrepository.com/artifact/com.typesafe.slick for the Scala version. You need to use the following (note the single %):
"com.typesafe.slick" % "slick_2.10" % "2.0.0"
or set scalaVersion to 2.10.3 which is currently the latest released version of Scala as follows:
scalaVersion := "2.10.3"
Repeat for the other %% dependencies.
It could be that there are available resolvers that could offer such artifacts, but you'd have to be told about it explicitly as searching Internet and private repositories is usually a pain.
[warn] :: com.typesafe.akka#akka-actor_2.9.2;2.2.0-RC1: not found
SBT is trying to resolve those dependencies for Scala version 2.9.2, you should add
scalaVersion := "2.10.3"
(actually, any 2.10.x should do) to your build.sbt.

Scala: SBT Eclipse plugin fails to build Breeze from scalanlp.org

I am new to Breeze (http://www.scalanlp.org/) and Scala in general. Please help to generate
Eclipse project for Breeze with sbt. I have Eclipse plugin for sbt installed.
When I try sbt eclipse it fails with the following errors. What is
wrong?
Thanks!
> ~/Distrib/Scala/breeze-master>sbt
[info] Loading global plugins from /home/an/.sbt/plugins
[info] Loading project definition from /home/an/Distrib/Scala/breeze-
master/project
[info] Set current project to breeze (in build file:/home/an/Distrib/
Scala/breeze-master/)
> eclipse
[info] About to create Eclipse project files for your project(s).
[error] java.util.NoSuchElementException: None.get
[error] Use 'last' for the full log.
> last
...
...
[debug] Project dependencies for configuration 'compile':
Success(List(breeze-math))
[debug] Project dependencies for configuration 'test': Success(List())
java.util.NoSuchElementException: None.get
at scala.None$.get(Option.scala:274)
at scala.None$.get(Option.scala:272)
at com.typesafe.sbteclipse.core.Eclipse$.relativize(Eclipse.scala:
498)
at com.typesafe.sbteclipse.core.Eclipse$$anonfun$srcEntry
$1.apply(Eclipse.scala:252)
at com.typesafe.sbteclipse.core.Eclipse$$anonfun$srcEntry
$1.apply(Eclipse.scala:249)
at scalaz.effects.IO$$anon$3$$anonfun$pure$1$$anonfun$apply
$23.apply(IO.scala:118)
at scalaz.effects.IO$$anon$3$$anonfun$pure$1$$anonfun$apply
$23.apply(IO.scala:118)
at scalaz.FreeFunctions$$anonfun$return_$1.apply(Free.scala:181)
at scalaz.FreeFunctions$$anonfun$return_$1.apply(Free.scala:181)
at scalaz.Pure$$anon$19$$anon$2.apply(Pure.scala:76)
at scalaz.Functor$$anon$15$$anon$45.apply(Functor.scala:84)
at scalaz.Free$class.go$1(Free.scala:73)
at scalaz.Free$class.run(Free.scala:76)
at scalaz.Free$Gosub.run(Free.scala:18)
at scalaz.effects.IO$class.unsafePerformIO(IO.scala:13)
at scalaz.effects.IO$$anon$2.unsafePerformIO(IO.scala:113)
at com.typesafe.sbteclipse.core.Eclipse$.onSuccess(Eclipse.scala:149)
at com.typesafe.sbteclipse.core.Eclipse$$anonfun$action
$4.apply(Eclipse.scala:105)
at com.typesafe.sbteclipse.core.Eclipse$$anonfun$action
$4.apply(Eclipse.scala:105)
at scalaz.Validation$class.fold(Validation.scala:7)
at scalaz.Success.fold(Validation.scala:82)
at com.typesafe.sbteclipse.core.Eclipse$.action(Eclipse.scala:105)
at com.typesafe.sbteclipse.core.Eclipse$$anonfun$eclipseCommand
$2.apply(Eclipse.scala:81)
at com.typesafe.sbteclipse.core.Eclipse$$anonfun$eclipseCommand
$2.apply(Eclipse.scala:81)
at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply
$2.apply(Command.scala:60)
at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply
$2.apply(Command.scala:60)
at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply
$3.apply(Command.scala:62)
at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply
$3.apply(Command.scala:62)
at sbt.Command$.process(Command.scala:90)
at sbt.MainLoop$$anonfun$next$1$$anonfun$apply$1.apply(MainLoop.scala:
71)
at sbt.MainLoop$$anonfun$next$1$$anonfun$apply$1.apply(MainLoop.scala:
71)
at sbt.State$$anon$2.process(State.scala:170)
at sbt.MainLoop$$anonfun$next$1.apply(MainLoop.scala:71)
at sbt.MainLoop$$anonfun$next$1.apply(MainLoop.scala:71)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
at sbt.MainLoop$.next(MainLoop.scala:71)
at sbt.MainLoop$.run(MainLoop.scala:64)
at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:53)
at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:50)
at sbt.Using.apply(Using.scala:25)
at sbt.MainLoop$.runWithNewLog(MainLoop.scala:50)
at sbt.MainLoop$.runAndClearLast(MainLoop.scala:33)
at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:17)
at sbt.MainLoop$.runLogged(MainLoop.scala:13)
at sbt.xMain.run(Main.scala:26)
at xsbt.boot.Launch$.run(Launch.scala:55)
at xsbt.boot.Launch$$anonfun$explicit$1.apply(Launch.scala:45)
at xsbt.boot.Launch$.launch(Launch.scala:69)
at xsbt.boot.Launch$.apply(Launch.scala:16)
at xsbt.boot.Boot$.runImpl(Boot.scala:31)
at xsbt.boot.Boot$.main(Boot.scala:20)
at xsbt.boot.Boot.main(Boot.scala)
[error] java.util.NoSuchElementException: None.get
[error] Use 'last' for the full log.
>
This is a known bug in sbteclipse: https://github.com/typesafehub/sbteclipse/issues/128
You can try commenting out the "doc" project in the Project.scala definition and see if that helps. Otherwise, I think this is a bug in sbteclipse that has to get resolved first.