Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build play framework sample application using sbt (not play)?

I am getting an NPE when invoking sbt within a sample app.

Please note: we can not run our overall app using "play": we need to be able to run this via sbt.

C:\apps\playframework\samples\scala\websocket-chat>sbt
java.lang.NullPointerException
        at sbt.StringUtilities$.nonEmpty(StringUtilities.scala:14)
        at sbt.impl.GroupArtifactID.$percent(DependencyBuilders.scala:50)
        at $f01bf36bc7174607fa7f$.$sbtdef(C:\apps\playframework\samples\scala\websocket-chat\project\plugins.sbt:8)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at sbt.compiler.Eval$.getValue(Eval.scala:420)
        at sbt.compiler.Eval$$anonfun$4.apply(Eval.scala:87)
        at sbt.compiler.Eval$$anonfun$4.apply(Eval.scala:87)
        at sbt.EvaluateConfigurations$$anonfun$evaluateSetting$1.apply(EvaluateConfigurations.scala:150)
        at sbt.EvaluateConfigurations$$anonfun$evaluateSetting$1.apply(EvaluateConfigurations.scala:148)
        at sbt.EvaluateConfigurations$$anonfun$flatten$1$$anonfun$apply$5.apply(EvaluateConfigurations.scala:115)
        at sbt.EvaluateConfigurations$$anonfun$flatten$1$$anonfun$apply$5.apply(EvaluateConfigurations.scala:115)
        at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:251)
        at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:251)
        at scala.collection.immutable.List.foreach(List.scala:318)
        at scala.collection.TraversableLike$class.flatMap(TraversableLike.scala:251)
        at scala.collection.AbstractTraversable.flatMap(Traversable.scala:105)
        at sbt.EvaluateConfigurations$$anonfun$flatten$1.apply(EvaluateConfigurations.scala:115)
        at sbt.EvaluateConfigurations$$anonfun$flatten$1.apply(EvaluateConfigurations.scala:115)
        at sbt.EvaluateConfigurations$$anonfun$evaluateSbtFile$1.apply(EvaluateConfigurations.scala:110)
        at sbt.EvaluateConfigurations$$anonfun$evaluateSbtFile$1.apply(EvaluateConfigurations.scala:110)
        at sbt.Load$.sbt$Load$$loadSettingsFile$1(Load.scala:507)
        at sbt.Load$$anonfun$sbt$Load$$memoLoadSettingsFile$1$1.apply(Load.scala:502)
        at sbt.Load$$anonfun$sbt$Load$$memoLoadSettingsFile$1$1.apply(Load.scala:501)
        at scala.Option.getOrElse(Option.scala:120)
        at sbt.Load$.sbt$Load$$memoLoadSettingsFile$1(Load.scala:501)
        at sbt.Load$$anonfun$loadSettings$1$2.apply(Load.scala:500)
        at sbt.Load$$anonfun$loadSettings$1$2.apply(Load.scala:500)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
        at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
        at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
        at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
        at scala.collection.AbstractTraversable.map(Traversable.scala:105)
        at sbt.Load$.loadSettings$1(Load.scala:500)
        at sbt.Load$.sbt$Load$$expand$1(Load.scala:523)
        at sbt.Load$.loadSettings(Load.scala:528)
        at sbt.Load$.sbt$Load$$loadSbtFiles$1(Load.scala:464)
        at sbt.Load$.defaultLoad$1(Load.scala:475)

EDIT Here is the project\plugins.sbt

logLevel := Level.Warn

addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.1.5")

addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.0.1")

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "0.6.0")

addSbtPlugin("play" % "sbt-plugin" % Option(System.getProperty("play.version")).getOrElse("2.0"))

libraryDependencies <+= sbtVersion { sv =>
  "org.scala-sbt" % "scripted-plugin" % sv
}

The line:

addSbtPlugin("play" % "sbt-plugin" % Option(System.getProperty("play.version")).getOrElse("2.0"))

causes the following:

[warn]
sbt.ResolveException: unresolved dependency: play#sbt-plugin;2.0: not found
        at sbt.IvyActions$.sbt$IvyActions$$resolve(IvyActions.scala:214)

EDIT More details

C:\apps\play\framework>sbt package
"sbt13"
Picked up _JAVA_OPTIONS: -Djava.net.preferIPv4Stack=true
[info] Loading project definition from C:\apps\play\framework\project
[warn]  module not found: play#sbt-plugin;2.2.3
[warn] ==== typesafe-ivy-releases: tried
[warn]   http://repo.typesafe.com/typesafe/ivy-releases/play/sbt-plugin/scala_2.9.2/sbt_0.12/2.2.3/ivys/ivy.xml
[warn] ==== sbt-plugin-releases: tried
[warn]   http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/play/sbt-plugin/scala_2.9.2/sbt_0.12/2.2.3/ivys/ivy.xml
[warn] ==== local: tried
[warn]   C:\Users\S80035683\.ivy2\local\play\sbt-plugin\scala_2.9.2\sbt_0.12\2.2.3\ivys\ivy.xml
[warn] ==== public: tried
[warn]   http://repo1.maven.org/maven2/play/sbt-plugin_2.9.2_0.12/2.2.3/sbt-plugin-2.2.3.pom
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: play#sbt-plugin;2.2.3: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn]  Note: Some unresolved dependencies have extra attributes.  Check that these dependencies exist with the requested attributes.
[warn]          play:sbt-plugin:2.2.3 (sbtVersion=0.12, scalaVersion=2.9.2)
[warn]
sbt.ResolveException: unresolved dependency: play#sbt-plugin;2.2.3: not found
        at sbt.IvyActions$.sbt$IvyActions$$resolve(IvyActions.scala:214)
        at sbt.IvyActions$$anonfun$update$1.apply(IvyActions.scala:122)
like image 541
WestCoastProjects Avatar asked May 21 '14 00:05

WestCoastProjects


People also ask

What is sbt in play framework?

sbt file defines settings for your project. You can also define your own custom settings for your project, as described in the sbt documentation. In particular, it helps to be familiar with the settings in sbt.


2 Answers

Edit the project/plugins.sbt and change

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % System.getProperty("play.version"))

to

addSbtPlugin("play" % "sbt-plugin" % Option(System.getProperty("play.version")).getOrElse("2.2.3"))

You can also get an updated Play version, where this issue seems to be fixed.

You can also set the system property play.version, if you want.

Edit

Make sure you are including Typesafe repository in the resolvers in your plugins.sbt.

resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
like image 175
lpiepiora Avatar answered Oct 21 '22 14:10

lpiepiora


This is based on lpiepiora's answer, but up-to-date (as his suggested fix did not work for me). I run the latest versions of everything (as of April 4, 2016) and got the scala play samples to build and run using the below:

Edit the project/plugins.sbt and make sure you have this line:

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.3")

Explicitly specifying play version as 2.2.3 will work just fine, as this is what the samples are targeting.

like image 22
Peter Perháč Avatar answered Oct 21 '22 14:10

Peter Perháč