SBT - Adding custom resolver is not working - scala

I am trying to import redshift JDBC into my project . Based on this link
https://docs.aws.amazon.com/redshift/latest/mgmt/configure-jdbc-connection-with-maven.html
My sbt build doesnt seem to pick this resolver . What am i doing wrong
Below is my sbt settings
lazy val commonSettings = Seq(
scalacOptions ++= compilerOptions,
logLevel := Level.Debug,
resolvers ++= Seq(
"Redshift" at "http://redshift-maven-repository.s3-website-us-east-1.amazonaws.com/release"
)
)

It works for me:
lazy val root = (project in file("."))
scalaVersion in ThisBuild:= "2.12.7"
resolvers += "redshift" at "http://redshift-maven-repository.s3-website-us-east-1.amazonaws.com/release"
libraryDependencies += "com.amazon.redshift" % "redshift-jdbc41" % "1.2.10.1009"

Related

Can't resolve docker related sbt tags

I'm trying to add sbt-docker to my sbt build of my play website but I'm running into an issue. For some reason none of the docker related stuff on the bottom can resolve.
project/plugins.sbt
logLevel := Level.Warn
resolvers ++= Seq(
"Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
)
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.9")
build.sbt
name := "personal_site"
version := "1.1"
lazy val `personal_site` = (project in file(".")).enablePlugins(PlayScala,DockerPlugin)
scalaVersion := "2.11.7"
libraryDependencies ++= Seq( jdbc , cache , ws , specs2 % Test )
unmanagedResourceDirectories in Test <+= baseDirectory ( _ /"target/web/public/test" )
resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases"
dockerfile in docker := {
val targetDir = "/usr/src"
new Dockerfile {
from("flurdy/activator")
//More goes here
}
}
imageNames in docker := Seq(
// Sets the latest tag
ImageName(s"${name.value}:latest"),
// Sets a name with a tag that contains the project version
ImageName(
namespace = None,
repository = name.value,
tag = Some("v" + version.value)
)
)
Here's an image of what it looks like in IntelliJ
I've also tried adding addSbtPlugin("se.marcuslonnberg" % "sbt-docker" % "1.4.0") to my project/plugins.sbt but I get this error about DockerPlugin being imported twice.
~/Sync/Projects/Programming/Personal_Site (master ✘)✹ ᐅ sbt clean
[info] Loading project definition from /home/ryan/Sync/Projects/Programming/Personal_Site/project
/home/ryan/Sync/Projects/Programming/Personal_Site/build.sbt:5: error: reference to DockerPlugin is ambiguous;
it is imported twice in the same scope by
import _root_.sbtdocker.DockerPlugin
and import _root_.com.typesafe.sbt.packager.docker.DockerPlugin
lazy val `personal_site` = (project in file(".")).enablePlugins(PlayScala,DockerPlugin)
Try changing your build.sbt config to this.
lazy val root = (project in file(".")).enablePlugins(sbtdocker.DockerPlugin, PlayScala)
It removes the ambiguity by using the full name to DockerPlugin, since sbt-native-packager uses the same name for its Docker plugin I believe.
Maybe worth raising a Github issue with the author's repo so they can document it in the project docs.

Adding module dependency information in sbt's build.sbt file

I have a multi module project in IntelliJ, as in this screen capture shows, contexProcessor module depends on contextSummary module.
IntelliJ takes care of everything once I setup the dependencies in Project Structure.
However, when I run sbt test with the following setup in build.sbt, I got an error complaining that it can't find the packages in contextSummary module.
name := "contextProcessor"
version := "1.0"
scalaVersion := "2.11.7"
libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.2" % "test"
How to teach sbt that the missing modules are found?
I could use the build.sbt file in the main root directory.
lazy val root = (project in file(".")).aggregate(contextSummary, contextProcessor)
lazy val contextSummary = project
lazy val contextProcessor = project.dependsOn(contextSummary)
Reference: http://www.scala-sbt.org/0.13.5/docs/Getting-Started/Multi-Project.html
For testing only one project, I can use project command in sbt.
> sbt
[info] Set current project to root (in build file:/Users/smcho/Desktop/code/ContextSharingSimulation/)
> project contextProcessor
[info] Set current project to contextProcessor (in build file:/Users/smcho/Desktop/code/ContextSharingSimulation/)
> test
For batch mode as in How to pass command line args to program in SBT 0.13.1?
sbt "project contextProcessor" test
I think a simple build.sbt might not be enough for that.
You would need to create a more sophisticated project/Build.scala like that:
import sbt._
import sbt.Keys._
object Build extends Build {
lazy val root = Project(
id = "root",
base = file("."),
aggregate = Seq(module1, module2)
)
lazy val module1 = Project(
id = "module1",
base = file("module1-folder"),
settings = Seq(
name := "Module 1",
version := "1.0",
scalaVersion := "2.11.7",
libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.2" % "test"
lazy val module2 = Project(
id = "module2",
base = file("module2-folder"),
dependencies = Seq(module1),
settings = Seq(
name := "Module 2",
version := "1.0",
scalaVersion := "2.11.7",
libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.2" % "test"
}

Factoring libraryDependencies in multi project Build.sbt

I'm trying to write a concise multi project Build.sbt, so I tried to put all library dependencies in root project and then make others depends on it. My Build.sbt looks like the following:
object KataBuild extends Build {
lazy val fizzBuzz = Project(
id = "fizzBuzz",
base = file("fizzBuzz"),
settings = Project.defaultSettings ++ Seq(
name := "fizzBuzz",
version := "1.0",
scalaVersion := "2.10.3"
)
)
lazy val kata = Project(
id = "scala-kata",
base = file("."),
settings = Project.defaultSettings ++ Seq(
name := "scala-kata",
version := "1.0",
scalaVersion := "2.10.3",
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "2.1.0" % "test"
)
)
) aggregate(fizzBuzz)
fizzBuzz dependsOn(kata)
}
But running test from the main project (scala-kata) fails to build test for fizzBuzz. What am I missing?
Your question is similar to this one. In short, fizzBuzz.dependsOn(kata) means that its compile configuration depends on the kata's compile configuration, but you want to link the test configurations.
The 'Per-configuration classpath dependencies' section of the sbt docs show you how you can make a test->test dependency instead.
However, if you are not going to use kata's test sources but are just looking for a way to include Scala-Test in fizzBuzz, just add it explicitly to fizzBuzz's library dependencies, too. You can define a helper value
lazy val scalaTest = "org.scalatest" %% "scalatest" % "2.1.0" % "test"
Then you can add it to be sub project's library dependencies (libraryDependencies += scalaTest).

Play sub-projects: how to convert to build.sbt

I've a working multi-module Play 2.2 application which is organized like this...
myApp
+ app
+ conf
+ project
+ build.properties
+ Build.scala
+ plugin.sbt
... where Build.scala contains the following statements:
import sbt._
import Keys._
import play.Project._
object ApplicationBuild extends Build {
val appName = "myApp"
val appVersion = "1.0-SNAPSHOT"
val authDependencies = Seq(
"se.radley" %% "play-plugins-salat" % "1.3.0"
)
val mainDependencies = Seq(
"se.radley" %% "play-plugins-salat" % "1.3.0"
)
lazy val auth = play.Project(
appName + "-auth",
appVersion,
authDependencies,
path = file("modules/auth")).settings(
lessEntryPoints <<= baseDirectory(customLessEntryPoints),
routesImport += "se.radley.plugin.salat.Binders._",
templatesImport += "org.bson.types.ObjectId",
testOptions in Test := Nil,
resolvers ++= Seq(Resolvers.sonatype, Resolvers.scalaSbt)
)
lazy val main = play.Project(
appName,
appVersion,
mainDependencies).settings(
scalacOptions += "-language:reflectiveCalls",
routesImport += "se.radley.plugin.salat.Binders._",
templatesImport += "org.bson.types.ObjectId",
testOptions in Test := Nil,
lessEntryPoints <<= baseDirectory(customLessEntryPoints),
resolvers ++= Seq(Resolvers.sonatype, Resolvers.scalaSbt)
).dependsOn(auth).aggregate(auth)
def customLessEntryPoints(base: File): PathFinder = {
(base / "app" / "assets" / "stylesheets" / "bootstrap" * "bootstrap.less") +++
(base / "app" / "assets" / "stylesheets" * "*.less")
}
}
object Resolvers {
val scalaSbt = Resolver.url("Scala Sbt", url("http://repo.scala-sbt.org/scalasbt/sbt-plugin-snapshots"))(Resolver.ivyStylePatterns)
val sonatype = Resolver.sonatypeRepo("snapshots")
}
Now reading the Play 2.2 documentation it looks like I should convert my project to build.sbt:
The following example uses a build.scala file to declare a play.Project. This approach was the way Play applications were defined prior to version 2.2. The approach is retained in order to support backward compatibility. We recommend that you convert to the build.sbt based approach or, if using a build.scala, you use sbt’s Project type and project macro.
Is there any working example that describes how to replace project/build.scala with build.sbt? I read some short articles here and there... but I was unable to get a working Play project.
There is no urgent need to convert your build to build.sbt. build.sbt is simpler, but basically just gets compiled into Build.scala.
The other answer to this question will work, but is perhaps a little verbose. Start with the SBT documentation:
http://www.scala-sbt.org/0.13.0/docs/Getting-Started/Multi-Project.html
Now, create specify your main project and sub projects, and put your main project settings into your main build.sbt file:
lazy val auth = project.in(file("modules/auth"))
lazy val main = project.in(file(".")).dependsOn(auth).aggregate(auth)
playScalaSettings
name := "myApp"
version := "1.0-SNAPSHOT"
libraryDependencies += "se.radley" %% "play-plugins-salat" % "1.3.0"
scalacOptions += "-language:reflectiveCalls"
routesImport += "se.radley.plugin.salat.Binders._"
templatesImport += "org.bson.types.ObjectId"
testOptions in Test := Nil
lessEntryPoints <<= baseDirectory(customLessEntryPoints)
resolvers ++= Seq(Resolvers.sonatype, Resolvers.scalaSbt)
object Resolvers {
val scalaSbt = Resolver.url("Scala Sbt", url("http://repo.scala-sbt.org/scalasbt/sbt-plugin-snapshots"))(Resolver.ivyStylePatterns)
val sonatype = Resolver.sonatypeRepo("snapshots")
}
And now, in modules/auth/build.sbt, put your settings for the auth module:
name := "myApp-auth"
lessEntryPoints <<= baseDirectory(customLessEntryPoints)
routesImport += "se.radley.plugin.salat.Binders._"
templatesImport += "org.bson.types.ObjectId"
testOptions in Test := Nil
resolvers ++= Seq(Resolvers.sonatype, Resolvers.scalaSbt)
Anyway, it might need a bit of tweaking, but hopefully you get the point.
if using a build.scala, you use sbt’s Project type and project macro
Replace play.Project with Project and fix the arguments according to the ScalaDoc, it should be something like
lazy val auth = Project(
appName + "-auth",
file("modules/auth")).settings(
version := appVersion,
libraryDependencies ++= authDependencies,
lessEntryPoints <<= baseDirectory(customLessEntryPoints),
routesImport += "se.radley.plugin.salat.Binders._",
templatesImport += "org.bson.types.ObjectId",
testOptions in Test := Nil,
resolvers ++= Seq(Resolvers.sonatype, Resolvers.scalaSbt)
)
lazy val main = Project(
appName,
file("app")).settings(
version := appVersion,
libraryDependencies ++= mainDependencies,
scalacOptions += "-language:reflectiveCalls",
routesImport += "se.radley.plugin.salat.Binders._",
templatesImport += "org.bson.types.ObjectId",
testOptions in Test := Nil,
lessEntryPoints <<= baseDirectory(customLessEntryPoints),
resolvers ++= Seq(Resolvers.sonatype, Resolvers.scalaSbt)
).dependsOn(auth).aggregate(auth)
Same definitions can be used in build.sbt instead. I would also extract common settings:
val commonSettings = Seq(
version := appVersion,
routesImport += "se.radley.plugin.salat.Binders._",
templatesImport += "org.bson.types.ObjectId",
testOptions in Test := Nil,
lessEntryPoints <<= baseDirectory(customLessEntryPoints),
resolvers ++= Seq(Resolvers.sonatype, Resolvers.scalaSbt)
)
lazy val auth = Project(
appName + "-auth",
file("modules/auth")).settings(commonSettings: _*).settings(
libraryDependencies ++= authDependencies
)
lazy val main = Project(
appName,
file("app")).settings(commonSettings: _*).settings(
libraryDependencies ++= mainDependencies,
scalacOptions += "-language:reflectiveCalls"
).dependsOn(auth).aggregate(auth)

What is the proper play-mini project setup for a proper production deployment

Play mini doesn't work like a play project at all really unless i am missing something. it runs within sbt and you cannot use play commands.
https://github.com/typesafehub/play2-mini
So how do you deploy this stuff to production? I've tried one-jar and assembly too and it just doesn't work for me
Ive stried the start-script/stage approach but it cannto seem to find my mainclass:
sbt
>add-start-script-tasks
>stage
[info] Wrote start script for mainClass := None to /Users/rmedlin/rtbv2/target/start
This is my Build.scala. Ive also tried: mainClass in (Compile, stage, run) and many other combinations
object Build extends Build {
override lazy val settings = super.settings
lazy val root = Project(id = "rtbv2",
base = file("."), settings = Project.defaultSettings).settings(
resolvers += "Typesafe Repo" at "http://repo.typesafe.com/typesafe/releases/",
resolvers += "Typesafe Snapshot Repo" at "http://repo.typesafe.com/typesafe/snapshots/",
libraryDependencies += "com.typesafe" %% "play-mini" % "2.0.1",
mainClass in (Compile, run) := Some("play.core.server.NettyServer"))
}
my Build.scala was incorrect and i was able to get the assembly command working:
trait ConfigureScalaBuild {
lazy val typesafe = "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
lazy val typesafeSnapshot = "Typesafe Snapshots Repository" at "http://repo.typesafe.com/typesafe/snapshots/"
val netty = Some("play.core.server.NettyServer")
def scalaMiniProject(org: String, name: String, buildVersion: String, baseFile: java.io.File = file(".")) = Project(id = name, base = baseFile, settings = Project.defaultSettings ++ assemblySettings).settings(
version := buildVersion,
organization := org,
resolvers += typesafe,
resolvers += typesafeSnapshot,
logManager <<= extraLoggers(com.typesafe.util.Sbt.logger),
libraryDependencies += "com.typesafe" %% "play-mini" % "2.0.1",
mainClass in (Compile, run) := netty,
mainClass in assembly := netty,
ivyXML := <dependencies> <exclude org="org.springframework"/> </dependencies>
)
}