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

2

8

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)
Yaker answered 21/5, 2014 at 0:37 Comment(0)
S
8

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/"
Steffens answered 21/5, 2014 at 10:49 Comment(11)
Hi, what does the play.version have to do with this? In any case i will try what you say - but would appreciate an explanation.Yaker
It's just that the sbt-plugin is bound to the play version (for different play versions there will be different sbt plugins). Normally the version is set as a system property, but for the play version you're using seems to be a bug.Steffens
The plugins.sbt does not have the specific entry you mentioned. I have copied it to the OP for your perusal (and showing that I added the line you suggested). That extra line has errors (also included in the OP)Yaker
You should have had the entry. However I have made a mistake, suggested by the way it was done in the original plugins.sbt for that example. The version should be actually "2.0.1" or whatever play version you're using. I've updated my answer. Btw. which version of Play are you using?Steffens
2.2.X . where do I see precise version? Clearly i do not use play at all. This was/is first foray.Yaker
You should have the line in the build.sbt then, however you still are missing the part .getOrElse("2.2.3"), which you may just add.Steffens
yes i did add the .getOrElse, and am recompiling: unresolved dependency: play#sbt-plugin;2.2.3: not foundYaker
Could you put complete report (especially which repos were tried) and the output of show externalResolvers to the OP? And seems you're also missing this line from plugins.sbt: resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"Steffens
op updated. and I am adding the line to plugins.sbt nowYaker
You don't need to add this line, but seems you're not using play 2.2.x, for that particular version of Scala and sbt you can only use play up to 2.1.5 (which is the value you should have set).Steffens
OK I am going to give this a rest now (and myself too!) I will award now for your help.Yaker
S
1

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.

Smiga answered 9/4, 2016 at 21:34 Comment(1)
Thanks for updating the answer.Yaker

© 2022 - 2024 — McMap. All rights reserved.