I'm playing around with the scala-forklift library and wanted to test an idea by modifying the code in the library and example project.
This is how the project is structured:
/build.sbt -> Contains definition of scala-forklift-slick project (including its dependencies) in the form of:
lazy val slickMigrationProject =
Project("scala-forklift-slick", file(...))
.dependsOn(...)
.settings(...)
...
/example/build.sbt -> References scala-forklift-slick via its Maven package.
My goal is to replace the scala-forklift-slick Maven package reference with a reference to the code in the parent directory, perhaps via .dependsOn(slickMigrationProject)?
Attempts:
According to the documentation:
Any .sbt files in foo, say foo/build.sbt, will be merged with the build definition for the entire build, but scoped to the hello-foo project.
But this does not seem to apply to lazy val values, as I can't access slickMigrationProject from the parent project directly.
I have been successful copying the entire contents of /example/build.sbt into /build.sbt and tweaking things a bit, but I was wondering if there was a better "one-liner" kind of solution instead.
Here is what my combined /build.sbt file looks like:
val repoKind = SettingKey[String]("repo-kind",
"Maven repository kind (\"snapshots\" or \"releases\")")
lazy val slickVersion = "3.3.3"
lazy val scala212 = "2.12.11"
lazy val scala213 = "2.13.1"
lazy val supportedScalaVersions = List(scala212, scala213)
lazy val coreDependencies = libraryDependencies ++= List(
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
"com.typesafe" % "config" % "1.3.2",
"org.eclipse.jgit" % "org.eclipse.jgit" % "4.0.1.201506240215-r"
)
lazy val slickDependencies = List(
"com.typesafe.slick" %% "slick" % slickVersion,
"com.typesafe.slick" %% "slick-codegen" % slickVersion,
"io.github.nafg" %% "slick-migration-api" % "0.7.0",
"org.scala-lang.modules" %% "scala-collection-compat" % "2.0.0"
)
lazy val slickDependenciesWithTests = slickDependencies ++ List(
"org.scalatest" %% "scalatest" % "3.1.0",
"com.lihaoyi" %% "ammonite-ops" % "2.0.4",
"commons-io" % "commons-io" % "2.6",
"com.typesafe.slick" %% "slick-hikaricp" % slickVersion,
"com.h2database" % "h2" % "1.4.200",
"org.xerial" % "sqlite-jdbc" % "3.8.11.2",// 3.30.1 crashes SQLiteCommandTests
"mysql" % "mysql-connector-java" % "5.1.38",
"org.postgresql" % "postgresql" % "42.2.9",
"org.hsqldb" % "hsqldb" % "2.5.0",
"org.apache.derby" % "derby" % "10.14.2.0",
"ch.qos.logback" % "logback-classic" % "1.2.3"
).map(_ % "test")
lazy val commonSettings = Seq(
organization := "com.liyaos",
licenses := Seq("Apache 2.0" ->
url("https://github.com/lastland/scala-forklift/blob/master/LICENSE")),
homepage := Some(url("https://github.com/lastland/scala-forklift")),
scalaVersion := scala213,
scalacOptions += "-deprecation",
scalacOptions += "-feature",
resolvers += Resolver.jcenterRepo,
publishMavenStyle := true,
publishArtifact in Test := false,
repoKind := { if (version.value.trim.endsWith("SNAPSHOT")) "snapshots"
else "releases" },
publishTo := { repoKind.value match {
case "snapshots" => Some("snapshots" at
"https://oss.sonatype.org/content/repositories/snapshots")
case "releases" => Some("releases" at
"https://oss.sonatype.org/service/local/staging/deploy/maven2")
}},
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials"),
pomExtra := (
<scm>
<url>git#github.com:lastland/scala-forklift.git</url>
<connection>scm:git:git#github.com:lastland/scala-forklift.git</connection>
</scm>
<developers>
<developer>
<id>lastland</id>
<name>Yao Li</name>
</developer>
</developers>))
// Derby is running is secured mode since version 10.12.1.1, so security manager must be disabled for tests
// https://stackoverflow.com/questions/48008343/sbt-test-does-not-work-for-spark-test
// https://issues.apache.org/jira/browse/DERBY-6648
Test / testOptions += Tests.Setup(() => System.setSecurityManager(null))
lazy val root = Project(
"scala-forklift", file(".")).settings(
crossScalaVersions := Nil,
publishArtifact := false).aggregate(
coreProject, slickMigrationProject, plainMigrationProject, gitToolProject, example)
lazy val coreProject = Project(
"scala-forklift-core", file("core")).settings(
commonSettings:_*).settings {Seq(
crossScalaVersions := supportedScalaVersions,
coreDependencies
)}
lazy val slickMigrationProject = Project(
"scala-forklift-slick", file("migrations/slick")).dependsOn(
coreProject).settings(commonSettings:_*).settings { Seq(
crossScalaVersions := supportedScalaVersions,
libraryDependencies ++= slickDependenciesWithTests
)}
lazy val plainMigrationProject = Project(
"scala-forklift-plain", file("migrations/plain")).dependsOn(
coreProject).settings(commonSettings:_*).settings(crossScalaVersions := supportedScalaVersions)
lazy val gitToolProject = Project(
"scala-forklift-git-tools", file("tools/git")).dependsOn(
coreProject).settings(commonSettings:_*).settings(crossScalaVersions := supportedScalaVersions)
///////////////////////////////////////////////
name := "forklift-slick-example"
addCommandAlias("mgm", "example/migration_manager/run")
addCommandAlias("mg", "example/migrations/run")
lazy val exampleCommonSettings = Seq(
organization := "com.liyaos",
version := "2.0",
scalaVersion := "2.13.1",
scalacOptions += "-deprecation",
scalacOptions += "-feature",
resolvers += Resolver.sonatypeRepo("snapshots"),
resolvers += Resolver.jcenterRepo,
)
lazy val loggingDependencies = List(
"org.slf4j" % "slf4j-nop" % "1.6.4" // <- disables logging
)
lazy val exampleSlickDependencies = List(
"com.typesafe.slick" %% "slick" % slickVersion
)
lazy val dbDependencies = List(
"com.typesafe.slick" %% "slick-hikaricp" % slickVersion
,"com.h2database" % "h2" % "1.4.200"
)
lazy val forkliftDependencies = List(
// "com.liyaos" %% "scala-forklift-slick" % forkliftVersion
)
lazy val appDependencies = dbDependencies ++ loggingDependencies
lazy val migrationsDependencies =
dbDependencies ++ forkliftDependencies ++ loggingDependencies
lazy val migrationManagerDependencies = dbDependencies ++ forkliftDependencies
lazy val example = Project("example", file("example")).aggregate(
app, migrations, migrationManager, generatedCode, tools).settings(
exampleCommonSettings:_*)
lazy val app = Project("app", file("example/app"))
.dependsOn(generatedCode)
.settings(exampleCommonSettings:_*)
.settings {libraryDependencies ++= appDependencies}
lazy val migrationManager = Project("migration_manager", file("example/migration_manager"))
.dependsOn(slickMigrationProject)
.settings(exampleCommonSettings:_*)
.settings {libraryDependencies ++= migrationManagerDependencies}
lazy val migrations = Project("migrations", file("example/migrations"))
.dependsOn(generatedCode, migrationManager, slickMigrationProject)
.settings(exampleCommonSettings:_*)
.settings {libraryDependencies ++= migrationsDependencies}
lazy val tools = Project("git-tools", file("example/tools/git"))
.dependsOn(slickMigrationProject, gitToolProject)
.settings(commonSettings:_*)
.settings {
libraryDependencies ++= forkliftDependencies ++ List(
// "com.liyaos" %% "scala-forklift-git-tools" % forkliftVersion,
"com.typesafe" % "config" % "1.3.0",
"org.eclipse.jgit" % "org.eclipse.jgit" % "4.0.1.201506240215-r"
)
}
lazy val generatedCode = Project("generate_code", file("example/generated_code"))
.settings(exampleCommonSettings:_*)
.settings {libraryDependencies ++= exampleSlickDependencies}
Question:
Is there a simple way I can replace the scala-forklift-slick Maven package reference in /example/build.sbt with a link to the existing scala-forklift-slick project definition in the parent directory's build.sbt so I can use .dependsOn(...) instead?
Or maybe it's better to do something like build scala-forklift-slick and use a local disk package resolver?
Luis Miguel Mejía Suárez's comment worked perfectly and was the easier approach.
In the context of this project, all I had to do was:
Append -SNAPSHOT to the version in /version.sbt (should not be needed normally but for this project I had to do this)
Run sbt publishLocal in the parent project.
After this, the example project (which already targets the -SNAPSHOT version) is able to pick up the locally built package.
Related
I am working on designing a multi module project in SBT.
The idea is to build two subprojects in SBT with one subproject having Apache spark 2.3 dependency and
the other one with Apache Spark 2.4 dependency. Each sub project should be capable of building individual
jars. I am pasting the build.sbt. While I try to run sbt assembly on each of these sub projects.
I am getting the below error.I tried removing the cache folder in .ivy2 and tried
recreating the project structure.
Error message(included relevant logs only)
[IJ]> multi2/assembly
[info] Including from cache: jackson-xc-1.9.13.jar
[info] Including from cache: minlog-1.3.0.jar
[warn] Merging 'META-INF\ASL2.0' with strategy 'discard'
[warn] Merging 'META-INF\DEPENDENCIES' with strategy 'discard'
[error] C:\Users\user_home\.ivy2\cache\org.apache.spark\spark-core_2.11\jars\spark-core_2.11-2.4.3.jar:org/apache/spark/unused/UnusedStubClass.class
[error] C:\Users\user_home\.ivy2\cache\org.apache.spark\spark-launcher_2.11\jars\spark-launcher_2.11-2.4.3.jar:org/apache/spark/unused/UnusedStubClass.class
[error] C:\Users\user_home\.ivy2\cache\org.apache.spark\spark-tags_2.11\jars\spark-tags_2.11-2.4.3.jar:org/apache/spark/unused/UnusedStubClass.class
[error] C:\Users\user_home\.ivy2\cache\org.spark-project.spark\unused\jars\unused-1.0.0.jar:org/apache/spark/unused/UnusedStubClass.class
Likewise there are other classes that cause errors as above..
Please suggest, and let me know for any additional information.
name := "testrepo"
organization in ThisBuild := "com.yt"
scalaVersion in ThisBuild := "2.11.8"
scalaBinaryVersion := "2.11"
lazy val common = (project in file("common"))
.settings(
name := "common",
commonSettings,
dependencyOverrides += "com.fasterxml.jackson.core" % "jackson-core" % "2.8.7",
dependencyOverrides += "com.fasterxml.jackson.core" % "jackson-databind" % "2.8.7",
dependencyOverrides += "com.fasterxml.jackson.module" %% "jackson-module-scala" %
dependencyOverrides += "io.netty" % "netty" % "3.9.9.Final",
dependencyOverrides += "commons-net" % "commons-net" % "2.2",
dependencyOverrides += "com.google.guava" % "guava" % "11.0.2",
dependencyOverrides += "com.google.code.findbugs" % "jsr305" % "1.3.9",
libraryDependencies ++= commonDependencies
)
.disablePlugins(AssemblyPlugin)
lazy val multi1 = (project in file("multi1"))
.settings(
name := "multi1",
commonSettings,
assemblySettings,
libraryDependencies ++= commonDependencies ++ Seq(
dependencies.spark23
)
)
.dependsOn(
common
)
lazy val multi2 = (project in file("multi2"))
.settings(
name := "multi2",
commonSettings,
assemblySettings,
libraryDependencies ++= commonDependencies ++ Seq(
dependencies.spark24
)
)
.dependsOn(
common
)
/*val overrides = Seq("com.fasterxml.jackson.core" % "jackson-core" % "2.8.7",
"com.fasterxml.jackson.core" % "jackson-databind" % "2.8.7",
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.8.7") */
// DEPENDENCIES
lazy val dependencies =
new {
val hivejdbc="org.apache.hive" % "hive-jdbc" % "0.13.0" % "provided"
val spark23V = "2.3.0.cloudera3"
val spark24V="2.4.3"
val spark23="org.apache.spark" %% "spark-core" % spark23V
val spark24="org.apache.spark" %% "spark-core" % spark24V
}
lazy val commonDependencies = Seq(
dependencies.hivejdbc
)
lazy val compilerOptions = Seq(
"-unchecked",
"-feature",
"-language:existentials",
"-language:higherKinds",
"-language:implicitConversions",
"-language:postfixOps",
"-deprecation",
"-encoding",
"utf8"
)
lazy val commonSettings = Seq(
scalacOptions ++= compilerOptions,
resolvers ++= Seq(
"Local Maven Repository" at "file://" + Path.userHome.absolutePath + "/.m2/repository",
Resolver.sonatypeRepo("releases"),
Resolver.sonatypeRepo("snapshots")
)
)
lazy val assemblySettings = Seq(
assemblyJarName in assembly := name.value + ".jar",
assemblyMergeStrategy in assembly := {
case PathList("org.apache.spark", "spark-core_2.11", xs # _*) => MergeStrategy.last
case PathList("META-INF", xs # _*) => MergeStrategy.discard
case "application.conf" => MergeStrategy.concat
case x =>
val oldStrategy = (assemblyMergeStrategy in assembly).value
oldStrategy(x)
}
)
I've split my app into sub-projects for better organization, however. My core sub-module which is a play app can't import play.api.libs.json.Json
Here is my build.sbt
# project/Common.scala
import sbt._
import sbt.Keys._
object Common {
val settings = Seq(
organization := "com.company.app",
scalaVersion := "2.12.5"
)
val dependencies = new {
val macwireVersion = "2.3.0"
val reactiveMongoVersion = "0.13.0-play26"
val slickVersion = "3.0.3"
val postgresVersion = "42.2.2"
val scalatestPlayVersion = "3.1.2"
val macwire = "com.softwaremill.macwire" %% "macros" % macwireVersion % "provided"
val reactivemongo = "org.reactivemongo" %% "play2-reactivemongo" % reactiveMongoVersion
val slick = "com.typesafe.play" %% "play-slick" % slickVersion
val slickEvolutions = "com.typesafe.play" %% "play-slick-evolutions" % slickVersion
val postgresql = "org.postgresql" % "postgresql" % postgresVersion
val scalatestPlay = "org.scalatestplus.play" %% "scalatestplus-play" % scalatestPlayVersion % Test
}
lazy val commonDependencies = Seq(
dependencies.macwire,
dependencies.reactivemongo,
dependencies.slick,
dependencies.slickEvolutions,
dependencies.postgresql,
dependencies.scalatestPlay
)
}
# build.sbt
lazy val core = (project in file("modules/core"))
.enablePlugins(PlayScala)
.settings(
name := "app-core",
libraryDependencies ++= Common.commonDependencies ++ Seq(
),
Common.settings
)
lazy val cms = (project in file("modules/cms"))
.enablePlugins(PlayScala)
.settings(
name := "app-cms",
libraryDependencies ++= Common.commonDependencies,
Common.settings
)
.dependsOn(core % "test->test;compile->compile")
.aggregate(core)
lazy val api = (project in file("modules/api"))
.enablePlugins(PlayScala)
.settings(
name := "app-api",
libraryDependencies ++= Common.commonDependencies,
Common.settings
)
.dependsOn(core % "test->test;compile->compile")
.aggregate(core)
lazy val reporting = (project in file("modules/reporting"))
.enablePlugins(PlayScala)
.settings(
name := "app-reporting",
libraryDependencies ++= Common.commonDependencies,
Common.settings
)
.dependsOn(core % "test->test;compile->compile")
.aggregate(core)
lazy val backend = (project in file("."))
.enablePlugins(PlayScala)
.settings(
name := "app-backend",
libraryDependencies ++= Common.commonDependencies
)
.dependsOn(
core % "test->test;compile->compile",
cms,
api,
reporting
)
.aggregate(cms, api, reporting)
I can't add an implicit Json format for My model User in the core module.
For the backend app, I can import w/o issues, is there something I'm missing here in the submodule part?
Thanks,
Double check if you are actually importing the play-json library because in Play 2.6 it is a standalone library:
libraryDependencies += "com.typesafe.play" %% "play-json" % playVersion
I have sbt multi projects and try to set the envVars in the build.sbt for subprojects as following:
envVars in Test := Map("KAFKA_SERVER" -> "localhost:9092")
the test abort with following message:
[info] java.util.NoSuchElementException: None.get
[info] at scala.None$.get(Option.scala:349)
[info] at scala.None$.get(Option.scala:347)
[info] at io.khinkali.auth.AppSpec.<init>(AppSpec.scala:23)
[info] at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
In the test file, I tried to get the value as following:
sys.env.get("KAFKA_SERVER").get
Intellj provides the set the environment variable as following:
How to set an environment variable in sbt for subprojects also?
Update
The root build.sbt looks as following:
name := "bary"
scalacOptions += "-Ypartial-unification"
scalacOptions += "-feature"
addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full)
val Cats = "1.0.0"
val Shiro = "1.4.0"
val Logback = "1.2.3"
val CatsEffect = "0.5"
val Kafka = "1.0.0"
val Bean = "1.9.3"
val Circe = "0.9.0-M3"
val Log4j = "1.7.25"
val ScalaCheck = "1.13.4"
val Scalactic = "3.0.4"
val Scalatest = "3.0.4"
val JavaJwt = "3.3.0"
val Simulacrum = "0.11.0"
val Http4s = "0.18.0-M7"
lazy val commonSettings = Seq(
organization := "io.khinkali",
version := "0.1.0-SNAPSHOT",
scalaVersion := "2.12.4",
envVars in Test := Map("KAFKA_SERVER" -> "localhost:9092"),
fork in Test := true,
libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-simple" % Log4j,
"ch.qos.logback" % "logback-core" % Logback,
"org.apache.shiro" % "shiro-all" % Shiro,
"org.typelevel" %% "cats-core" % Cats,
"org.typelevel" %% "cats-effect" % CatsEffect,
"org.apache.kafka" % "kafka-streams" % Kafka,
"org.apache.kafka" % "kafka-clients" % Kafka,
"commons-beanutils" % "commons-beanutils" % Bean,
"io.circe" %% "circe-core" % Circe,
"io.circe" %% "circe-generic" % Circe,
"io.circe" %% "circe-parser" % Circe,
"io.circe" %% "circe-literal" % Circe,
"com.github.mpilquist" %% "simulacrum" % Simulacrum,
"org.scalactic" %% "scalactic" % Scalactic,
"org.scalatest" %% "scalatest" % Scalatest % "test",
"org.scalacheck" %% "scalacheck" % ScalaCheck % "test",
),
resolvers ++= Seq(
"Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
),
fork in run := true,
)
lazy val root = (project in file("."))
.settings(commonSettings)
.settings(
name := "bary",
organization := "io.khinkali",
moduleName := "bary"
).
aggregate(
kafka_api,
auth_stream,
rest)
lazy val kafka_api = (project in file("kafka-api")).
settings(commonSettings).
settings(
name := "kafka-api",
moduleName := "kafka-api"
)
lazy val auth_stream = (project in file("auth-stream")).
settings(commonSettings).
settings(
name := "auth-stream",
moduleName := "auth-stream",
libraryDependencies ++= Seq(
"com.auth0" % "java-jwt" % JavaJwt,
)
).dependsOn(kafka_api)
lazy val rest = (project in file("rest")).
settings(commonSettings).
settings(
name := "rest",
moduleName := "rest",
libraryDependencies ++= Seq(
"org.http4s" %% "http4s-dsl" % Http4s,
"org.http4s" %% "http4s-blaze-server" % Http4s,
"org.http4s" %% "http4s-blaze-client" % Http4s,
"org.http4s" %% "http4s-circe" % Http4s,
)
).dependsOn(kafka_api, auth_stream)
I still got the exception.
Any setting you want to apply to a subproject can either be specified just for that subproject or in commonSettings, as shown in build.sbt below.
You did not show your multiproject definitions, so here is a short example. There are many ways of setting up these types of projects, and I am not going to elaborate on the possible ways; this is a complicated topic, and it has evolved a lot over the years, especially recently.
lazy val commonSettings = Seq(
envVars in Test := Map("KAFKA_SERVER" -> "localhost:9092"),
fork in Test := true, // required for envVars task to work
javacOptions ++= Seq(
"-Xlint:deprecation",
"-Xlint:unchecked",
"-source", "1.8",
"-target", "1.8",
"-g:vars"
),
licenses += ("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0.html")),
version := "0.5.0"
)
lazy val demo = project
.settings(commonSettings:_*)
.settings(
name := "demo"
).dependsOn(root)
lazy val root = (project in file("root"))
.settings(commonSettings:_*)
.settings(
name := "root"
)
One more important fact: The environment setting for test will not be respected when run with the IntelliJ IDEA test runner. As a workaround, you can set environment variables in the Run/Debug Configurations -> Environment variables window. When you run sbt test, however, the environment variable specified in build.sbt will be set.
Normally, the only way to apply an environment variable to a process is to start the process with that environment variable. If you want SBT to run your program in an environment with a certain environment variable, it will need to be launched in a new environment. This is called forking.
I am trying to create a new project, this time with sbt 1.0.2 instead of 0.13.x which I used for quite some time now.
There I had a multi-project setup comparable to https://github.com/vmunier/akka-http-with-scalajs-example/blob/master/build.sbt
My problem now is that I always get [error] (projectname/compile:bgRun) No main class detected. when I try to run sbt run
Here is my current build.sbt file:
lazy val generalSettings = Seq(
name := "awesomeproject.tld",
version := "0.1",
scalaVersion := "2.12.3"
)
lazy val client = (project in file("modules/client"))
.settings(generalSettings: _*)
.settings(
name := "client",
libraryDependencies ++= Seq(
"com.lihaoyi" %%% "scalatags" % "0.6.5",
"org.scala-js" %%% "scalajs-dom" % "0.9.2"
)
, scalaJSUseMainModuleInitializer := true
)
.enablePlugins(ScalaJSPlugin, ScalaJSWeb)
.dependsOn(sharedJS)
lazy val server = (project in file("modules/server"))
.settings(generalSettings: _*)
.settings(
name := "server",
scalaJSProjects := Seq(client),
pipelineStages in Assets := Seq(scalaJSPipeline),
// triggers scalaJSPipeline when using compile or continuous compilation
//compile in Compile := ((compile in Compile) dependsOn scalaJSPipeline).value,
WebKeys.packagePrefix in Assets := "public/",
//managedClasspath in Runtime += (packageBin in Assets).value,
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.5.4",
"com.typesafe.akka" %% "akka-testkit" % "2.5.4" % Test,
"com.typesafe.akka" %% "akka-stream" % "2.5.4",
"com.typesafe.akka" %% "akka-stream-testkit" % "2.5.4" % Test,
"com.typesafe.akka" %% "akka-http" % "10.0.10",
"com.typesafe.akka" %% "akka-http-testkit" % "10.0.10" % Test,
"ch.qos.logback" % "logback-classic" % "1.2.3",
"com.typesafe.scala-logging" %% "scala-logging" % "3.7.2",
"com.lihaoyi" %% "scalatags" % "0.6.5",
"com.vmunier" %% "scalajs-scripts" % "1.1.0"
)
, mainClass := Some("tld.awesomeproject.Main")
)
.dependsOn(sharedJVM)
lazy val shared = (crossProject.crossType(CrossType.Pure) in file("modules/shared"))
.settings(generalSettings: _*)
.settings(
name := "shared"
)
lazy val sharedJS = shared.js
lazy val sharedJVM = shared.jvm
As you can see I tried to solve the problem with setting it explicitly with mainClass := Some("tld.awesomeproject.Main") in the subproject. I also tried to set a root project explicitly, make it dependOn the server but no luck.
I guess the real problem here is, that
onLoad in Global := (Command.command("project server", _: State)) compose (onLoad in Global) does not work in sbt 1.0.2 anymore.
I checked the Command class, but I am not wiser after. There simply is no more method that gives back a state.
Can anyone shed like on this? What I want is to run a server that sends some javascript to the client... that shouldn't be black magic, in fact everything worked like a charm in my 0.13. project.
This should work:
onLoad in Global ~= (_ andThen ("project server" :: _))
Reference: https://github.com/sbt/sbt/issues/1224#issuecomment-331840364
I'm trying to set up scala web project with sbt. I've following settings.
scala 2.9.0-1
sbt 0.11.0
xsbt-web-plugin 0.2.1
project/plugins.sbt
libraryDependencies <+= sbtVersion(v => "com.github.siasia" %% "xsbt-web-plugin" % (v+"-0.2.1"))
project/TaskTrackerBuild.scala
import sbt._
import com.github.siasia._
import WebPlugin._
import PluginKeys._
import Keys._
/**
* Main sbt build file for the task-tracker project.
*
*/
object TicketingCoreProject extends Build {
val ticketingVersion = "1.0.0-SNAPSHOT"
val Organization = "org.sansoft"
val ScalaVersion = "2.9.0-1"
val jodaTime = "joda-time" % "joda-time" % "1.6"
val scalaTime = "org.scala-tools.time" % "time_2.8.0" % "0.2"
val casbah = "com.mongodb.casbah" % "casbah_2.9.0-1" % "2.1.5.0"
val Slf4jLog4jDep = "org.slf4j" % "slf4j-log4j12" % "1.6.1"
val ScalaCheckDep = "org.scala-tools.testing" %% "scalacheck" % "1.9" % "test"
val JUnitDep = "junit" % "junit" % "4.8.2" % "test"
val scalaTesting = "org.scala-tools.testing" %% "specs" % "1.6.8" % "test"
//val scctSbt = "ch.craven" %% "scct-plugin" % "0.2"
val vaadin = "com.vaadin" % "vaadin" % "6.7.0"
val jettyWebApp = "org.eclipse.jetty" % "jetty-webapp" % "7.3.0.v20110203" % "container"
val jettyPlus = "org.eclipse.jetty" % "jetty-plus" % "7.3.0.v20110203" % "container"
val repositories = Seq(
ScalaToolsSnapshots,
"typesafe releases" at "http://repo.typesafe.com/typesafe/releases",
"typesafe snapshots" at "http://repo.typesafe.com/typesafe/snapshots",
"scct-repo" at "http://mtkopone.github.com/scct/maven-repo")
def publishToRepository = Some(Resolver.file("Local Maven Repository", Path.userHome / ".m2" / "repository" asFile))
lazy val baseSettings = Defaults.defaultSettings ++ Seq(
version := ticketingVersion,
organization := Organization,
scalaVersion := ScalaVersion,
publishMavenStyle := true,
publishTo := publishToRepository,
resolvers ++= repositories,
checksums := Nil
)
lazy val parent = Project("taskTrackerParent", file("."),
settings = baseSettings ++ Seq(
name := "task-tracker-parent"
))
lazy val core = Project("core", file("core"),
settings = baseSettings ++ Seq(
name := "core",
libraryDependencies ++= Seq(
jodaTime,
scalaTime,
scalaTesting,
ScalaCheckDep,
casbah,
jodaTime,
scalaTime)))
lazy val web = Project("web", file("web"),
settings = baseSettings ++ webSettings ++ Seq(
name := "web",
libraryDependencies ++= Seq(
jodaTime,
scalaTime,
scalaTesting,
ScalaCheckDep,
casbah,
jodaTime,
scalaTime,
vaadin,
jettyWebApp,
jettyPlus))) dependsOn(core)
}
When I try to start sbt with this build file I get following error.
[error] Error getting ScopedKey(Scope(This,Select(ConfigKey(container)),This,This),full-classpath)
[error] Use 'last' for the full log.
If I remove the configuration webSettings from the web project sbt project compiles fine.
What have I done wrong in this???
Thanks in advance.
I had exactly the same issue when I tried to use webSettings.
Today I found a solution on project-doc:
https://github.com/siasia/xsbt-web-plugin/wiki/Deployment-scenarios
The plugin works when I change from webSettings to webAppSettings.