I have a project/Generate.scala that generates some Scala code destined for sourceManaged. Generate.scala has its own dependencies. From the sbt documentation, it seems that those dependencies should go into project/build.sbt. When I tried that, sbt stops resolving my plugins declared in project/plugins.sbt.
What's the right way to declare these dependencies? And how should I think about the meta-build conceptually? It looks like I misunderstand "sbt is recursive."
project/build.sbt:
scalaVersion in ThisBuild:= "2.12.2"
resolvers += Resolver.sonatypeRepo("releases")
resolvers += Resolver.bintrayRepo("scalameta", "maven")
libraryDependencies += "org.scalameta" %% "scalameta" % "1.7.0"
project/plugins.sbt:
addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "3.0.1")
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-M15")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.16")
addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.6" exclude ("com.trueaccord.scalapb", "protoc-bridge_2.10"))
libraryDependencies += "com.trueaccord.scalapb" %% "compilerplugin-shaded" % "0.6.0-pre3"
Related
My sbt file looks as follows
organization := "scala"
name := "MyProject"
version := "1.0"
scalaVersion := "2.12.1"
libraryDependencies += "com.github.nscala-time" %% "nscala-time" % "2.20.0"
libraryDependencies += "commons-net" % "commons-net" % "3.6"
libraryDependencies += "commons-validator" % "commons-validator" % "1.6.0"
When I run sbt compile I get this
sbt.librarymanagement.ResolveException: unresolved dependency: commons-validator#commons-validator;1.6.0: not found
However when I change scala version to 2.11.7, sbt compiles fine. What am I missing? How can I make it work for 2.12.1?
According to mvnrepo (https://mvnrepository.com/artifact/commons-validator/commons-validator)
use libraryDependencies += "commons-validator" % "commons-validator" % "1.6"
With sbt 0.13.8 and Scala 2.10.5, which dependencies are required in build.sbt and plugins.sbt to install Cucumber ?
SBT does not resolve info.cukes dependencies below.
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-library" % "2.10.5",
"junit" % "junit" % "4.11" % "test",
"org.scala-lang" % "scala-compiler" % "2.10.5",
"org.scala-lang" % "scala-reflect" % "2.10.5",
"info.cukes" % "cucumber-scala" % "1.1.6",
"info.cukes" % "cucumber-core" % "1.1.6"
)
There is a different build of cucumber-scala for each version of Scala. So, you have to mention the desired Scala version. You can provide it in the name of artifact, for example:
libraryDependencies += "info.cukes" % "cucumber-scala_2.12" % "1.2.4"
or you can use the SBT shortcut "%%" which will substitute the correct Scala version for you:
libraryDependencies += "info.cukes" %% "cucumber-scala" % "1.2.4"
I have a list of JARs and I want to download the JARs via SBT into destination directory specified. Is there a way/command to do this?
What I am trying is to have a list of jars in classpath for an external system like spark.
By default spark adds some jars to classpath and
I also have some jars that my app depends on in addition to spark classpath jars.
I don't want to build a fat jar.
And I need to package the dependent jars along with my jar in a tar ball.
My build.sbt
name := "app-jar"
scalaVersion := "2.10.5"
dependencyOverrides += "org.scala-lang" % "scala-library" % scalaVersion.value
scalacOptions ++= Seq("-unchecked", "-deprecation")
libraryDependencies += "org.apache.spark" %% "spark-streaming" % "1.4.1"
libraryDependencies += "org.apache.spark" %% "spark-core" % "1.4.1"
libraryDependencies += "org.apache.spark" %% "spark-streaming-kafka" % "1.4.1"
// I want these jars from here
libraryDependencies += "com.datastax.spark" %% "spark-cassandra-connector" % "1.4.0-M3"
libraryDependencies += "com.datastax.spark" %% "spark-cassandra-connector-java" % "1.4.0-M3"
libraryDependencies += "com.google.protobuf" % "protobuf-java" % "2.6.1"
...
// To here in my tar ball
So far I have achieved this using a shell script.
I want to know if there is a way to do the same with sbt .
Add sbt-pack to your project/plugins.sbt (or create it):
addSbtPlugin("org.xerial.sbt" % "sbt-pack" % "0.7.9")
Add packAutoSettings to your build.sbt and then run:
sbt pack
In target/pack/lib you will find all jars (with dependencies).
Update
Add new task to sbt:
val libraries = Seq(
"com.datastax.spark" %% "spark-cassandra-connector" % "1.4.0-M3",
"com.datastax.spark" %% "spark-cassandra-connector-java" % "1.4.0-M3",
"com.google.protobuf" % "protobuf-java" % "2.6.1"
)
libraryDependencies ++= libraries
lazy val removeNotNeeded = taskKey[Unit]("Remove not needed jars")
removeNotNeeded := {
val fileSet = libraries.map(l => s"${l.name}-${l.revision}.jar").toSet
println(s"$fileSet")
val ver = scalaVersion.value.split("\\.").take(2).mkString(".")
println(s"$ver")
file("target/pack/lib").listFiles.foreach{
file =>
val without = file.getName.replace(s"_$ver","")
println(s"$without")
if(!fileSet.contains(without)){
println(s"${file.getName} removed")
sbt.IO.delete(file)
}
}
}
After calling sbt pack call sbt removeNotNeeded. You will received only needed jar files.
I would like to use the phantom cassandra wrapper in my scala project, but when I try to update my sbt build I get a dependency error.
My build.sbt:
version := "1.0"
scalaVersion := "2.11.2"
seq(lsSettings :_*)
libraryDependencies ++= Seq(
"org.clapper" %% "grizzled-scala" % "1.2",
"commons-io" % "commons-io" % "2.4",
"org.rauschig" % "jarchivelib" % "0.6.0",
"com.google.code.findbugs" % "jsr305" % "3.0.0",
"org.scalatest" % "scalatest_2.11" % "2.2.0" % "test",
"com.github.nscala-time" %% "nscala-time" % "1.2.0",
"org.json4s" %% "json4s-native" % "3.2.10",
"org.scala-lang" % "scala-library" % "2.11.2",
"com.websudos" % "phantom-dsl_2.10" % "1.2.0"
)
resolvers += "grizzled-scala-resolver-0" at "https://oss.sonatype.org/content/repositories/releases"
resolvers += "Typesafe repository releases" at "http://repo.typesafe.com/typesafe/releases/"
I get the following error:
[warn] Note: Some unresolved dependencies have extra attributes. Check that these dependencies exist with the requested attributes.
[warn] com.typesafe.sbt:sbt-pgp:0.8.1 (sbtVersion=0.13, scalaVersion=2.10)
Don't know what I have to do...
edit:
Answer from https://github.com/websudosuk/phantom/issues/119
error is on the pom side, new version 1.2.1 coming soon...
Answer from https://github.com/websudosuk/phantom/issues/119
error is on the pom side, new version 1.2.1 coming soon...
I'm new to sbt and I will generate a web application with jsf 2.0 mojarra and icefaces, but i don't know how to build the build.sbt. I try things like this:
libraryDependencies += "org.icefaces" % "icefaces" % "2.0.2"
libraryDependencies += "net.java" % "jsf-api" % "2.1.2"
libraryDependencies += "net.java" % "jsf-impl" % "2.1.2"
Maybe is this horrible wrong and sbt can't find the module:
module not found: com.sun.faces#jsf-impl:2.1.1-b04/ivys/ivy.xml
resolvers += "java.net maven 2 repo" at "http://download.java.net/maven/2"
libraryDependencies += "org.icefaces" % "icefaces" % "2.0.2"
libraryDependencies += "com.sun.faces" % "jsf-api" % "2.1.2"
libraryDependencies += "com.sun.faces" % "jsf-impl" % "2.1.2"
This will only work with sbt 0.10+. Make sure you keep the blank lines between expressions.