Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SBT Resolvers work in build.sbt, not working in Build.scala

Tags:

scala

sbt

Once upon a time, in a far off land, there existed a project with a little project/build.sbt file that looks like this:

resolvers += Resolver.url("scala-js-snapshots",
  url("http://repo.scala-js.org/repo/snapshots/")
)(Resolver.ivyStylePatterns)

addSbtPlugin("org.scala-lang.modules.scalajs" % "scalajs-sbt-plugin" % "0.2-SNAPSHOT")

At project load time, things looked great, and there was peace in the land:

[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] downloading http://repo.scalajs.org/repo/snapshots/org.scalalang.modules.scalajs/scalajs-sbtplugin/scala_2.10/sbt_0.13/0.2-SNAPSHOT/jars/scalajs-sbt-plugin.jar ...
[info]  [SUCCESSFUL ] org.scala-lang.modules.scalajs#scalajs-sbt-plugin;0.2SNAPSHOT!scalajs-sbt-plugin.jar (1936ms)
[info] Done updating.

One day, another project was created. Unlike the first project, this project was big and complicated, and so it has a project/project/Build.scala which looks like this:

import sbt._
import Keys._
object Build extends sbt.Build {
  import sbt._

  override lazy val projects = Seq(root)
  lazy val root =
    Project("plugins", file("."))
      .settings(
        resolvers += Resolver.url("scala-js-snapshots",
          url("http://repo.scala-js.org/repo/snapshots/")
        )(Resolver.ivyStylePatterns),
        addSbtPlugin("org.scala-lang.modules.scalajs" % "scalajs-sbt-plugin" % "0.2-SNAPSHOT")
      )
      .dependsOn(uri("../../scala-js-resource/plugin"))
      .dependsOn(uri("../../scala-js-workbench"))
}

It seemed to me that this should set up the SBT plugin in an identical way to the earlier arrangement. After all, what is a build.sbt but a bunch of settings? The only difference was that it depended on some other local projects and thus couldn't be a plain .sbt file.

But at load time, something terrible happened:

[warn]  module not found: org.scala-lang.modules.scalajs#scalajs-sbt-plugin;0.2-SNAPSHOT
[warn] ==== typesafe-ivy-releases: tried
[warn]   http://repo.typesafe.com/typesafe/ivy-releases/org.scalalang.modules.scalajs/scalajs-sbt-plugin/scala_2.10/sbt_0.13/0.2-SNAPSHOT/ivys/ivy.xml
[warn] ==== sbt-plugin-releases: tried
[warn]   http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/org.scalalang.modules.scalajs/scalajs-sbt-plugin/scala_2.10/sbt_0.13/0.2-SNAPSHOT/ivys/ivy.xml
[warn] ==== local: tried
[warn]   C:\Users\Haoyi\.ivy2\local\org.scala-lang.modules.scalajs\scalajs-sbt-plugin\scala_2.10\sbt_0.13\0.2-SNAPSHOT\ivys\ivy.xml
[warn] ==== public: tried
[warn]   http://repo1.maven.org/maven2/org/scala-lang/modules/scalajs/scalajs-sbt-plugin_2.10_0.13/0.2-SNAPSHOT/scalajs-sbt-plugin-0.2-SNAPSHOT.pom

Stupid Build.scala, you didn't even try the resolver I gave you! I even told you where to look for the damn module, why did you give up without even trying? Your little brother the build.sbt found it perfectly fine.

Anyone know what gives, and how I can make the Build.scala work like I want it to?

like image 406
Li Haoyi Avatar asked Dec 26 '13 07:12

Li Haoyi


People also ask

What are resolvers in sbt?

sbt resolver is the configuration for repository that contains jars and their dependencies. for example the below is a resolver definition for a repository called Sonatype and it points at snapshot releases (dev versions) resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"

What is build sbt in Scala?

sbt is a popular tool for compiling, running, and testing Scala projects of any size. Using a build tool such as sbt (or Maven/Gradle) becomes essential once you create projects with dependencies or more than one code file.

What is the difference between sbt and Scala?

SBT is tied to a specific project defined by a build. sbt file in a way that $ sbt console will load up the same REPL environment as $ scala but with the addition of all of the project code and dependencies defined in the build available for import. Also, it will use the version of Scala defined by build.


1 Answers

project/build.sbt is not the little brother of project/Build.scala. The former defines sbt plugins, whereas the latter is the actual build file. Its little brother, if you want, would be <root-dir>/build.sbt.

You should leave the plugin definitions in project/build.sbt. There is nothing wrong with having both files.

Your project definition (along with the dependsOn) should either be in project/Build.scala, or you use <root-dir>/build.sbt where in sbt 0.13 you can basically do everything that was formerly restricted to Build.scala, so my advise is to only use .sbt files these days.


So leave project/build.sbt, or better rename it to project/plugins.sbt so there is less confusion, and use this as ./build.sbt:

lazy val root = Project("plugins", file("."))
  .dependsOn(uri("../scala-js-resource/plugin"))
  .dependsOn(uri("../scala-js-workbench"))
like image 69
0__ Avatar answered Oct 21 '22 11:10

0__