java.lang.NoSuchMethodError: sbt.package$.Zero()Lsbt/Global$; - sbt

When using Scala.js 0.6.20 (addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.20") in project/plugins.sbt), the following error happens when trying to sbt import the project using sbt 0.13.15:
java.lang.NoSuchMethodError: sbt.package$.Zero()Lsbt/Global$;
at org.scalajs.sbtplugin.ScalaJSPluginInternal$.org$scalajs$sbtplugin$ScalaJSPluginInternal$$scalaJSStageSettings(ScalaJSPluginInternal.scala:254)
at org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$22.apply(ScalaJSPluginInternal.scala:446)
at org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$22.apply(ScalaJSPluginInternal.scala:446)
at scala.Function2$$anonfun$tupled$1.apply(Function2.scala:54)
at scala.Function2$$anonfun$tupled$1.apply(Function2.scala:53)
Similar problem: https://gitter.im/scala-js/scala-js?at=59b53890b59d55b823db1dcd

As the release notes mention, Scala.js 0.6.20 requires sbt 0.13.16 or above. To achieve this, the project/build.properties file should be modified to set:
sbt.version=0.13.16
(or something compatible)

Alternative: downgrade scala.js to 0.6.19 (say, for Coursera course capstone)
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.19") >> project/plugins.sbt

Related

Sbt, local sbt plugin, using jooq code generation plugin

I'm trying to use jooq-sbt-plugin to generate some code.
I downloaded the code, compiled it and copied jar into lib directory, but on sbt load i get this error:
[warn] Note: Some unresolved dependencies have extra attributes. Check that th
ese dependencies exist with the requested attributes.
[warn] sean8223:jooq-sbt-plugin:1.4 (sbtVersion=0.13, scalaVersion=2.10
)
in project/plugins.sbt i have this
resolvers += Resolver.file("lib-repo", file("lib")) transactional()
addSbtPlugin("lib-repo" %% "jooq-sbt-plugin" % "1.4")
Is this plugin "detected" and cannot be loaded or sbt does't see it?
P.S.
By default plugin does not work because it depends on jooq-3.2.1 which is not available on maven and I get error - unresolved dependencies. According to plugin readme i could set jooqVersion in build.sbt to other version, but this doesn't seem to work.
In my project/plugins.sbt:
resolvers += "sean8223 Releases" at "https://github.com/sean8223/repository/raw/master/releases"
addSbtPlugin("sean8223" %% "jooq-sbt-plugin" % "1.3")
In my build.sbt:
seq(jooqSettings:_*)
jooqVersion := "3.3.1"
And everything is successfully resolved. I didn't run any tasks, but since you say that the problem is in resolving jooq, show your build.sbt if it still doesn't work for you.

Set up sbt to fetch dependency for another version of Scala than the project's?

My project uses Scala 2.9.3, and I want to use Spire for 2.9.2. What do I specify in my sbt build file to get Spire for 2.9.2?
I tried
"org.spire-math" %% "spire" % "0.6.0"
but it fails looking for Scala 2.9.3.
One has to append the corresponding library name with an underscore and required scala version and verify the appropriate version number of the library(in my case, 0.3.0)
"org.spire-math" % "spire_2.9.2" % "0.3.0"

Not specifying version in addSbtPlugin possible?

If I want to include a plugin for sbt I use addSbtPlugin() in plugins.sbt. So to add the gen-idea plugin I would use the following line:
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.0")
Alas, I've to explicitly specify the version 1.5.0. What if I want to use the latest available version when it becomes available?
When I omit the third parameter I'm getting the following error:
C:\Users\JDearing\Documents\deleteme\LearningScala>sbt gen-idea
C:\Users\JDearing\.sbt\0.13\plugins\build.sbt:1: error: type mismatch;
found : sbt.impl.GroupArtifactID
required: sbt.ModuleID
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" )
^
[error] Type error in expression
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? q
Is it possible to avoid specifying the version in addSbtPlugin()?
sbt plugin is just another library for your build
https://github.com/sbt/sbt/blob/0.13/main/src/main/scala/sbt/Defaults.scala#L1513
And for a library you have Ivy resolution rules
Ivy revisions
The revision in groupID % artifactID % revision does
not have to be a single fixed version. Ivy can select the latest
revision of a module according to constraints you specify. Instead of
a fixed revision like "1.6.1", you specify "latest.integration",
"2.9.+", or "[1.0,)". See the Ivy revisions documentation for details.
from
http://www.scala-sbt.org/release/docs/Getting-Started/Library-Dependencies.html#ivy-revisions
tl;dr No. There's no way to leave the version off. It's part of sbt.ModuleID.
You can however use latest.integration or latest.milestone to avoid specifying the version explicitly. Ivy and hence SBT will take care of "selecting the latest version being either a milestone or a release".
You may also consult my answer to a similar question about the sbt-idea plugin.

IllegalStateException: impossible to get artifacts when data has not been loaded for Guava 12.0?

In a Java Play 2.1.1 app I get the following error:
[myproject] $ update
[info] Updating {file:/C:/path/myproject/}myproject...
[info] Resolving ...
[error] impossible to get artifacts when data has not been loaded. IvyNode = com.google.guava#guava;12.0
[error] (*:update) java.lang.IllegalStateException: impossible to get artifacts when data has not been loaded. IvyNode = com.google.guava#guava;12.0
[error] Total time: 230 s, completed 17.05.2013 19:16:41
Build.scala
"com.google.guava" % "guava" % "14.0.1",
"org.mydependency" % "mydependency" % "1.0-SNAPSHOT" changing() exclude("org.jboss.netty","netty") exclude("com.google.guava", "guava") exclude("log4j", "log4j"),
The thing that causes this error (it all worked fine before) is a dependency change within mydependency:
old:
<dependency>
<groupId>com.thinkaurelius.titan</groupId>
<artifactId>titan-berkeleyje</artifactId>
<version>0.3.1</version>
</dependency>
new:
<dependency>
<groupId>com.thinkaurelius.titan</groupId>
<artifactId>titan-cassandra</artifactId>
<version>0.3.1</version>
</dependency>
I don't want guava 12.0 anyway and it is and was excluded.
Can I tell Play 2.1.1 to use a newer Ivy?
In plugins.sbt I have:
addSbtPlugin("play" % "sbt-plugin" % "2.1.1")
Temporary fix
As someone mentioned here Apache IVY error message? : impossible to get artifacts when data has not been loaded manually adding the dependency solves it: I've added
"com.google.guava" % "guava" % "12.0"
and the problem is gone.
Apparently more people had and have this issue, so I'm putting my solution as an answer:
Temporary fix
As someone mentioned here Apache IVY error message? : impossible to get artifacts when data has not been loaded manually adding the dependency solves it: I've added
"com.google.guava" % "guava" % "12.0"
and the problem is gone.
Instead of using a lower version, you could try adding this line to .sbt file:
dependencyOverrides += "com.google.guava" % "guava" % "14.0.1"
Play 2.1.x uses sbt 0.12, which uses Ivy 2.3.0-rc1, but looks like this is still an issue.
If you can come up with a reproduction steps using publicly available libraries, please open a Github issue with a link to this comment.

How do you do develop an SBT project, itself?

Background: I've got a Play 2.0 project, and I am trying to add something to do aspectj weaving using aspects in a jar on some of my classes (Java). (sbt-aspectj doesn't seem to do it, or I can't see how). So I need to add a custom task, and have it depend on compile. I've sort of figured out the dependency part. However, because I don't know exactly what I'm doing, yet, I want to develop this using the IDE (I'm using Scala-IDE). Since sbt projects (and therefore Play projects) are recursively defined, I assumed I could:
Add the eclipse plugin to the myplay/project/project/plugins.sbt
Add the sbt main jar (and aspectj jar) to myplay/project/project/build.sbt:
libraryDependencies ++= Seq(
"org.scala-sbt" % "main" % "0.12.2",
"aspectj" % "aspectj-tools" % "1.0.6"
)
Drop into the myplay/project
Run sbt, run the eclipse task, then import the project into eclipse as a separate project.
I can do this, though the build.scala (and other scala files) aren't initially considered source, and I have to fiddle with the build path a bit. However, even though I've got the sbt main defined for the project, both eclipse IDE and the compile task give errors:
> compile
[error] .../myplay/project/Build.scala:2: not found: object keys
[error] import keys.Keys._
[error] ^
[error] .../myplay/project/SbtAspectJ.scala:2: object Configurations is not a member of package sbt
[error] import sbt.Configurations.Compile
[error] ^
[error] .../myplay/project/SbtAspectJ.scala:3: object Keys is not a member of package sbt
[error] import sbt.Keys._
[error] ^
[error] three errors found
The eclipse project shows neither main nor aspectj-tools in its referenced-libraries. However, if I give it a bogus version (e.g. 0.12.4), reload fails, so it appears to be using
the dependency.
So,...
First: Is this the proper way to do this?
Second: If so, why aren't the libs getting added.
(Third: please don't let this be something dumb that I missed.)
If you are getting the object Keys is not a member of package sbt error, then you should check that you are running sbt from the base directory, and not the /project directory.
sbt-aspectj
sbt-aspectj doesn't seem to do it, or I can't see how.
I think this is the real issue. There's a plugin already that does the work, so try making it work instead of fiddling with the build. Using plugins from build.scala is a bit tricky.
Luckily there are sample projects on github:
import sbt._
import sbt.Keys._
import com.typesafe.sbt.SbtAspectj.{ Aspectj, aspectjSettings, compiledClasses }
import com.typesafe.sbt.SbtAspectj.AspectjKeys.{ binaries, compileOnly, inputs, lintProperties }
object SampleBuild extends Build {
....
// precompiled aspects
lazy val tracer = Project(
"tracer",
file("tracer"),
settings = buildSettings ++ aspectjSettings ++ Seq(
// stop after compiling the aspects (no weaving)
compileOnly in Aspectj := true,
// ignore warnings (we don't have the sample classes)
lintProperties in Aspectj += "invalidAbsoluteTypeName = ignore",
// replace regular products with compiled aspects
products in Compile <<= products in Aspectj
)
)
}
How do you do develop an SBT project, itself?
If you're interested in hacking on the build still the first place to go is the Getting Started guide. Specifically, your question should be answered in .scala Build Definition page.
I think you want your build to utilize "aspectj" % "aspectj-tools" % "1.0.6". If so it should be included in myplay/project/plugins.sbt, and your code should go into myplay/project/common.scala or something. If you want to use IDE, you have have better luck with building it as a sbt plugin. That way your code would go into src/main/scala. Check out sbt/sbt-aspectj or sbt/sbt-assembly on example of sbt plugin structure.

Resources