Play 2.0 - Build.scala - converting from pom.xml - scala

I'm trying to migrate from a Nexus maven repo to using https://github.com/jcaddel/maven-s3-wagon. Getting on the wagon? I've read some things about build scripts for SBT, but that doesn't seem like what I want...am I missing something? Documentation is sparse.
Here is my Play! 2.0 Build.scala file:
import sbt._
import Keys._
import PlayProject._
object ApplicationBuild extends Build {
val appName = "my-play-app"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
"org.fusesource.mqtt-client" % "mqtt-client" % "1.0")
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
resolvers ++= Seq(
"Maven Repository" at "http://repo1.maven.org/maven2/",
"fusesource.snapshots" at "http://repo.fusesource.com/nexus/content/repositories/snapshots",
"fusesource.releases" at "http://repo.fusesource.com/nexus/content/groups/public"))
}
Here is what I need to convert from the pom.xml file to Build.scala (via the wagon wiki):
<build>
<extensions>
<extension>
<groupId>org.kuali.maven.wagons</groupId>
<artifactId>maven-s3-wagon</artifactId>
<version>[S3 Wagon Version]</version>
</extension>
</extensions>
</build>
And
<distributionManagement>
<site>
<id>s3.site</id>
<url>s3://[AWS Bucket Name]/site</url>
</site>
<repository>
<id>s3.release</id>
<url>s3://[AWS Bucket Name]/release</url>
</repository>
<snapshotRepository>
<id>s3.snapshot</id>
<url>s3://[AWS Bucket Name]/snapshot</url>
</snapshotRepository>
</distributionManagement>
I think I understand how to add the distribution portion to Build.scala:
import sbt._
import Keys._
import PlayProject._
object ApplicationBuild extends Build {
val appName = "my-play-app"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
"org.fusesource.mqtt-client" % "mqtt-client" % "1.0")
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
resolvers ++= Seq(
"Maven Repository" at "http://repo1.maven.org/maven2/",
"fusesource.snapshots" at "http://repo.fusesource.com/nexus/content/repositories/snapshots",
"fusesource.releases" at "http://repo.fusesource.com/nexus/content/groups/public",
"s3.site" at "s3://[AWS Bucket Name]/site",
"s3.release" at "s3://[AWS Bucket Name]/release",
"s3.snapshot" at "s3://[AWS Bucket Name]/snapshot"))
}

It looks like there is still no automatic S3 publish support in sbt (although there is a s3-plugin). But I think you can easily create your own, given that
sbt can be enhanced with plugins
Maven plugins are just POJOs (so you can easily reuse them outside of maven)
There is an existing Maven plugin that already does what you want
I think you can
Use the sbt release plugin...
...add your own custom release step...
...that calls S3Wagon.putResource or S3Plugin.S3.s3Settings.upload

A combination of sbt-aether-deploy, maven-s3-wagon and fmt-sbt-s3-resolver works well for me
build.sbt:
publishMavenStyle := true
publishTo <<= version { v: String =>
if (v.trim.endsWith("SNAPSHOT"))
Some("Snapshots" at "s3://myrepo/snapshots")
else
Some("Releases" at "s3://myrepo/releases")
}
aetherSettings
aetherPublishSettings
wagons := Seq(aether.WagonWrapper("s3", "org.kuali.maven.wagon.S3Wagon"))
plugins.sbt:
addSbtPlugin("no.arktekk.sbt" % "aether-deploy" % "0.13")
addSbtPlugin("com.frugalmechanic" % "fm-sbt-s3-resolver" % "0.4.0")
libraryDependencies += "org.kuali.maven.wagons" % "maven-s3-wagon" % "1.2.1"
fm-sbt-s3-resolver is used for resolving s3 dependencies and aether for deploy. Deployment with fm-sbt-s3-resolver alone will not AFAIK generate and publish metadata (maven-metadata.xml)

Sbt doesn't support maven extensions which is what gives you the s3:// protocol, so in short there is no easy way to do what you are trying to do

There is an S3 Plugin for sbt available.

Related

Migrating from Play 2.1 to 2.5: Build.scala configuration issues

I am upgrading from Play 2.1.3 to Play 2.5.4. I resolved multiple issues but I am now stuck at one last step I guess:
My project/Build.scala:
import sbt._
import Keys._
import play.sbt._
import Play.autoImport._
import PlayKeys._
object ApplicationBuild extends Build {
val appName = "dashboard"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
// Add your project dependencies here,
javaCore,
javaJdbc,
javaEbean
)
val main = play.Project(appName, appVersion, appDependencies).settings(
// Add your own project settings here
)
}
When I do activator run on my project, I get the following error:
[error] \project\Build.scala:19: object Project is not a member of package play
[error] val main = play.Project(appName, appVersion, apDependencies).settings(
[error] ^
[error] one error found
[debug] Compilation failed (CompilerInterface)
[error] (compile:compileIncremental) Compilation failed
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore?
Can someone please help?
play.Project was replaced by native sbt Project support at version 2.3:. From this version migration docs:
If you were previously using play.Project, for example a Scala project:
object ApplicationBuild extends Build {
val appName = "myproject"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq()
val main = play.Project(appName, appVersion, appDependencies).settings(
)
}
...then you can continue to use a similar approach via native sbt:
object ApplicationBuild extends Build {
val appName = "myproject"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq()
val main = Project(appName, file(".")).enablePlugins(play.PlayScala).settings(
version := appVersion,
libraryDependencies ++= appDependencies
)
}
But, since you are migrating from a very old version (Play 2.1 last release was in Sep 2013), I truly recommend you to use build.sbt instead of project/Build.scala. The migration would be something like:
name := """dashboard"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs
)
And, instead of adding javaEbean, you will need to use play-ebean instead. To do so, just add the following line to your project/plugins.sbt file (this was changed at Play 2.4 and you have to use the updated version as documented for Play 2.5):
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "3.0.0")
After that, change your root project definition to something like this:
lazy val myProject = (project in file(".")).enablePlugins(PlayJava, PlayEbean)
This will automatically add Ebean dependencies. Finally, I can't recommend enough that you read all the migration guides for version between 2.1 and 2.5.

How to use SBT IntegrationTest configuration from Scala objects

To make our multi-project build more manageable we split up our Build.scala file into several files, e.g. Dependencies.scala contains all dependencies:
import sbt._
object Dependencies {
val slf4j_api = "org.slf4j" % "slf4j-api" % "1.7.7"
...
}
We want to add integration tests to our build. Following the SBT documentation we added
object Build extends sbt.Build {
import Dependencies._
import BuildSettings._
import Version._
import MergeStrategies.custom
lazy val root = Project(
id = "root",
base = file("."),
settings = buildSettings ++ Seq(Git.checkNoLocalChanges, TestReport.testReport)
).configs(IntegrationTest).settings(Defaults.itSettings: _*)
...
}
where Dependencies, BuildSettings, Version and MergeStrategies are custom Scala objects definied in their own files.
Following the documentation we want to add some dependencies for the IntegrationTest configuration in Dependencies.scala:
import sbt._
object Dependencies {
val slf4j_api = "org.slf4j" % "slf4j-api" % "1.7.7"
val junit = "junit" % "junit" % "4.11" % "test,it"
...
}
Unfortunately this breaks the build:
java.lang.IllegalArgumentException: Cannot add dependency
'junit#junit;4.11' to configuration 'it' of module ... because this configuration doesn't exist!
I guess I need to import the IntegrationTest configuration. I tried importing the IntegrationTest configuration in Dependencies.scala:
import sbt.Configurations.IntegrationTest
IntegrationTest is a lazy val defined in the Configurations object:
object Configurations {
...
lazy val IntegrationTest = config("it") extend (Runtime)
...
}
But that did not solve the problem.
Does someone has an idea how to solve this?
You need to add the config to the Project object before you add the dependency to the Project object.
Your code quotes show you doing the former, but you don't show where you are doing the latter in your quoted code.
Please could you post the full config, or try moving those two around each other?
Here is where the config is added to the Project object in the SBT docs you linked to:
lazy val root = (project in file(".")).
configs(IntegrationTest).
Your quoted code above which declares a lazy val but does not use it is not sufficient to get the "it" config into use:
lazy val IntegrationTest = config("it") extend (Runtime)

How to set-up the sbt-proguard plugin in Build.scala

I want to use the sbt-proguard plugin in my project, but I need to set it up in a Build.scala file.
I read the documentation but there is just an example for the build.sbt file, which won't work in my case. I need to know how to configure the plugin for my Build.scala file.
Here's the link to the repo: https://github.com/sbt/sbt-proguard/blob/master/README.md#example
FYI: I'm using scala.version=2.11.4 and sbt.version=0.13.5
(Note: sbt currently recommends multi-project build.sbt instead of build.scala.)
Some of the sbt plugins use scripted to test itself, which sets up fake builds under src/sbt-test. If you find one it could contain nice samples on how to set up the plugin.
sbt-proguard created a sample called akka supposedly used by Akka project.
import sbt._
import sbt.Keys._
import com.typesafe.sbt.SbtProguard._
object SampleBuild extends Build {
import ProguardKeys.{ mergeStrategies, merge, options }
import ProguardOptions.keepMain
import ProguardMerge.append
lazy val proguardAkka = Project(
id = "proguard-akka",
base = file("."),
settings = Defaults.defaultSettings ++ proguardSettings ++ Seq(
scalaVersion := "2.10.1",
libraryDependencies += "com.typesafe.akka" %% "akka-remote" % "2.1.2",
merge in Proguard := true,
mergeStrategies in Proguard += append("reference.conf"),
options in Proguard += keepMain("A"),
options in Proguard += keepMain("B"),
options in Proguard += "-dontoptimize", // reduce time for proguard
options in Proguard += ProguardConf.akka
)
)
}
object ProguardConf {
val akka = ....
}

Adding multiple subprojects to Play 2 framework

am using play 2 framework with java
I have added a project dependency as a sub-project
by following the tutorials
Now I want a second sub-project.
But kind of new to the scala codes in the build.scala file
can some one tell me how to ass a second sub-project.
below is my code for the build.scala file and the sub-project.
import sbt._
import Keys._
import PlayProject._
object ApplicationBuild extends Build {
val appName = "Rub_Server"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
// These are the project dependencies
"mysql" % "mysql-connector-java" % "5.1.18",
)
val subProject = Project("Com-RubineEngine-GesturePoints", file("modules/Com-RubineEngine-GesturePoints"))
val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
// Add your own project settings here
).dependsOn(subProject)
}
now I want add a second project to the build.scala file
how do I do tht
thanks.
.dependsOn(subProject, anotherProject)

libraryDependencies on sbt Build.scala Full Configuration with sub-projects

I have a project foo with two children foo-core and foo-cli, foo-cli depends on foo-core
(I come from Java/Maven and tried to transpose the parent module with 2 submodules architecture).
Following https://github.com/harrah/xsbt/wiki/Full-Configuration, I wrote my project/Build.scala this way:
import sbt._
import Keys._
object MyBuild extends Build {
//Dependencies
val slf4s = "com.weiglewilczek.slf4s" %% "slf4s" % "1.0.6"
val slf4j = "org.slf4j" %% "slf4j-simple" % "1.5.6"
val grizzled = "org.clapper" %% "grizzled-slf4j" % "0.5"
val junit = "junit" % "junit" % "4.8" % "test"
//End dependencies
lazy val root : Project = Project("root", file(".")) aggregate(cli) settings(
mainClass:= Some("Main")
)
lazy val core : Project = Project("core", file("core"), delegates = root :: Nil) settings(
name := "foo-core",
libraryDependencies ++= Seq(grizzled)
)
lazy val cli: Project = Project("cli", file("cli")) dependsOn(core) settings(
name := "foo-cli",
libraryDependencies ++= Seq(grizzled)
)
}
This configuration does not work: grizzled library is not dowloaded when I run sbt reload;sbt +update (as indicated in http://software.clapper.org/grizzled-slf4j/) and thus the "import grizzli._" fail in my core and cli projects when I sbt compile.
Since I'm new to scala/sbt I imagine I'm doing something awful but can't figure why since I'm confused with all sbt 0.7/sbt0.10 conflicting configurations that were suggested
(like Subproject dependencies in SBT).
Any idea? Hint that could help me?
Thanks in advance
That's grizzled, not grizzli you are using as dependency. The import is:
import grizzled._
This works here from console on project cli and project core, with nothing more than the configuration file above.
Are you using SBT 0.10?