Adding a managed dependency to Play 2 app - scala

I want to add Jersey-client to my Play 2 app using SBT.
So, I added the dependency into my ApplicationBuild.scala file as follows:
object ApplicationBuild extends Build {
val appName = "wealcome-webapp"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
// Add your project dependencies here,
jdbc,
anorm,
"com.sun.jersey" % "jersey-client" % "1.16"
)
val main = play.Project(appName, appVersion, appDependencies).settings(
scalaVersion := "2.10.0"
)
}
So, in command-line I make : play reload update.
Thus, I expect to find Jersey's jars file into play-2.1-RC1/repository/local.
However, I find jars into play-2.1-RC1/repository/cache.
What should I do to make automatically the dependency goes into the local folder in order to expect my app to compile?
Is it normal to find jars file into the cache folder? What is exactly the role of cache?

If you are using an IDE make sure to run play eclipsify or play idea after making changes to your dependencies. Afterwards refreshing the project may be necessary. Then the class paths for the project files will be updated appropriately. Only SBT will be aware of your changes before you do this.

Related

After migrating library to scalajs, publish-local does not work

Following the hints of the post explaining the basics of migrating to scalajs and this page about cross-compilations, I decided to add cross compilation to my standalone dependency-free scala library by doing the following changes:
I added a file project/plugins.sbt with the content
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.16")
I added scalaVersion in ThisBuild := "2.11.8" in build.sbt because else just scalaVersion was using 2.10
I also added in the build.sbt the following content to ensure that I can keep the same directory structure, since I don't have any particular files for the JVM or for Javascript:
lazy val root = project.in(file(".")).
aggregate(fooJS, fooJVM).
settings(
publish := {},
publishLocal := {}
)
lazy val foo = crossProject.crossType(CrossType.Pure).in(file(".")).
settings(version := "0.1").
jvmSettings(
// Add JVM-specific settings here
).
jsSettings(
// Add JS-specific settings here
)
lazy val fooJVM = foo.jvm
lazy val fooJS = foo.js
But now, after I published the project locally using sbt publish-local the projects depending on this library do not work anymore, i.e. they don't see the classes that this library was offering and raise errors.
I looked into .ivy2/local/.../foo/0.1/jars and the JAR went from 1MB to 1KB, so the errors make sense.
However, how can I make sure the JVM jar file is compiled correctly?
Further informations
The jar time does not change anymore, it looks like there had been some miscompilation. I deleted the .ivy2 cache, but now sbt publish-local always finishes with success but does not regenerate the files.
Ok I found the solution myself.
I needed to remove the publishLocal := {} from the build, and now all the projects depending on my library work fine.

How to add modules to Play with Scala?

Coming from Ruby on Rails, I used to just do a gem 'some_random_gem' and then bundle in the terminal and there were my dependencies. Now that I'm bumping my head against scala and play, I'm discovering that it might not be that easy on this playground.
I'm trying to runa sample application and this is the warning/error:
module not found: com.wingnest.play2#play21-frames-titan-plugin_2.10;1.3-module-2.4.4
Assume I do not know anything. Assume I have no experience and no scala background. I do have some, but can you give me a description on how to solve this?
I'm believe you will need the projects/build.scala file, so here it is:
import sbt._
import Keys._
import play.Project._
object ApplicationBuild extends Build {
val appName = "play21-frames-titan-simple-app"
val appVersion = "1.2-module-2.3.2"
val titanVersion = "0.4.2"
val appDependencies = Seq(
"com.wingnest.play2" % "play21-frames-titan-plugin_2.10" % "1.3-module-2.4.4",
"com.thinkaurelius.titan" % "titan-cassandra" % {titanVersion},
javaCore
)
val main = play.Project(appName, appVersion, appDependencies).settings(
resolvers += "Oracle Releases" at "http://download.oracle.com/maven/"
)
}
First off, there are two types of plugins.
sbt plugins are declared in project/plugins.sbt using addSbtPlugin("organization" % "plugin-name" % "version") - the same way that Play is enabled (Play is nothing more than an sbt plugin).
You can find more info about it in the sbt plugins documentation.
Play plugins are normal dependencies but must be activated in the conf/play.plugins file (create it if non-existent) using the <priority>:<qualified-plugin-name> syntax, e.g. 500:se.radley.plugin.salat.SalatPlugin.
Unfortunately, this part of Play is not documented.

Play build.scala to build.sbt isn't working for secureSocial plugin. I don't understand why?

I'm new in playFrameWork
I'm trying to figure out how the build.sbt file works in play framework 2.2
i'm also trying to make the secureSocial plugin works
In the sample app of the plugin secureSocial, there is a built.scala containing :
import sbt._
import Keys._
import play.Project._
object ApplicationBuild extends Build {
val appName = "SecureTestApp"
val appVersion = "1.0"
val appDependencies = Seq(
"ws.securesocial" %% "securesocial" % "master-SNAPSHOT"
)
val main = play.Project(appName, appVersion, appDependencies).settings(
resolvers += Resolver.sonatypeRepo("snapshots")
)
}
Whith the command play run, everything wrok fine and the page is showing itself
AnyWay, as i understand it, i should be able to delete project/built.scala and replace it by /build.sbt. i think my file is ok and look like this :
name := "SecureTestApp"
version := "1.0-SNAPSHOT"
libraryDependencies ++= Seq(
"securesocial" %% "securesocial" % "master-SNAPSHOT"
)
resolvers += Resolver.url("Scala Sbt", url("http://repo.scala-sbt.org/scalasbt/sbt-plugin-snapshots"))(Resolver.ivyStylePatterns)
resolvers += Resolver.sonatypeRepo("snapshots")
play.Project.playScalaSettings
This time the play run command work fine the server launch itself but when i launch and test the app homePage,
i get the error : Compilation error "object RuntimeEnvironment is not a member of package securesocial.core"
Play is no longer able to find the package secureSocial. And i don't understand why?
What am i doing wrong?
is there a parametter someWhere to set?
Thanks in advance for any answer!
Edit : whith the line
"ws.securesocial" %% "securesocial" % "2.1.3"
put in both file, play doensn't fine the dependency in both for package secureSocial.
I think the problem is that this object simply does not exist in the version that is published to the repository. If you take a look at the sources, there is no file RuntimeEnvironment.scala in which it is supposed to be defined.
Further if you check the date when the file appeared on github it is 7th May, and the last modified date in the repo shows 23-Jan-2014.
So the bottom line is that your build is working just fine, but the library you're using is not the one that in in the master branch on the github at the moment.
You should rather use the last stable version :
"ws.securesocial" %% "securesocial" % "2.1.3"
and as resolver
resolvers += Resolver.sonatypeRepo("releases")
as master constantly evolves and the doc might not been updated yet.
Major changes have been made on master the 7th May which might break your project if your created it before. (You could also try to clean-all maybe)

Play dependencies on a scala project

I am trying to get a play project to have another local scala project as a dependency. I have the local scala project deploying to my local M2 repository with this line in my configuration file.
publishTo := Some(Resolver.file("file", new File(Path.userHome.absolutePath+"/.m2/repository")))
And I am trying to load the dependency in my play project with this line
val appDependencies = Seq(
"com.experimentalcork" %% "timeywimeyentities" % "0.0.2"
)
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
resolvers += "Local Maven Repository" at "file://" + Path.userHome.absolutePath + "/.m2/repository",testOptions in Test := Nil
)
In the logs as I do a 'play compile' it states that it can not find the dependency. It is looking in the place where I specified the dependency would be.
[warn] ==== Local Maven Repository: tried
[warn] file://C:/Users/caelrin/.m2/repository/com/experimentalcork/timeywimeyentities_2.9.1/0.0.2/timeywimeyentities_2.9.1-0.0.2.pom
And when I go to check that directory, I can confirm that the pom and jar files are there. I am completely baffled as to how it could look in the directory that contains the pom and not find it. Has anyone had any experiences with this?
You need a .dependsOn call too, I think.
val timeywimeyentities: Project = Project([Put all of your settings here for the project just like you would a play project])
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
resolvers += "Local Maven Repository" at "file://" + Path.userHome.absolutePath + "/.m2/repository",testOptions in Test := Nil
).dependsOn(timeywimeyentities % "compile->compile")
Adding "compile->compile" makes the main code of your play project rely on the main code of your dependency. If you wanted to make the test code of your play project also depend on it, you could use "compile->test". If you want only the test code of both to see each other, you could use "test->test". You can also chain them together, for example: "compile->compile;test->test". If all you want is "compile->compile", you need not explicitly state it.
See https://github.com/harrah/xsbt/wiki/Getting-Started-Multi-Project for more information.

sbt: can i put the source of scala compiler plugin into a project that needs to be compiled using that plugin?

i'm writing my own scala compiler plugin and using sbt to build the project. is it possible to put the source of that plugin in the same project that needs to be compiled using that plugin?
all the documentation on sbt seems to be concerned with using a plugin that's external to the project. it just seems much easier to test the plugin if they're in the same project. otherwise i have to continuously build the plugin, copy that jar over to the main project, and then compile that.
the documentation i read is at http://code.google.com/p/simple-build-tool/wiki/CompilerPlugins.
Here is an example using SBT 0.13:
object PluginBuild extends Build {
def buildSettings = Seq(
name := "test-compiler-plugin",
scalaVersion := "2.10.3"
)
override def settings = super.settings ++ buildSettings
lazy val codeToBeChecked = project.in(file("code-to-be-checked")).
settings(
scalacOptions += "-Xplugin:" + packageBin.in(Compile).in(thePlugin).value
)
lazy val thePlugin = project.in(file("the-plugin")).settings(
libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value
)
}
I am not shure about what you are doing, but maybe is the project/plugins/src_managed/ diriectory what you are looking for. If the user of the plugin needs some code from the plugin, it can be found there.