0
votes

How can you configure a playframework-2.1 application build.scala file to generate an eclipse project with scalanature and not javanature?

I found this code (https://github.com/playframework/playframework/blob/2.1.x/framework/src/sbt-plugin/src/main/scala/play/Project.scala)

val mainLang = if (dependencies.contains(javaCore)) JAVA else SCALA

This suggests that if I have javaCore in dependencies i will get a JAVA project. I tried to remove the dependencies on javaCore but I've got compilation errors.

Any suggestions?

2

2 Answers

0
votes

I managed to be able to configure a playframework project that is

  • using java and scala sources
  • generates eclipse project with scala natures
  • compiles properly in eclipse
  • using playframework-2.1.x

The script is the following

import sbt._
import Keys._
import play.Project._

object ApplicationBuild extends Build {

    val appName         = "darzaar"
    val appVersion      = "1.0-SNAPSHOT"
    //play.Project.playScalaSettings - is available only in playframework-2.2.x
    val appDependencies = Seq(
      // added instead of javaCore
      "play"  %%  "play-java"     % "2.1.5",
      "be.objectify"  %%  "deadbolt-java"     % "2.1-RC2",
      "be.objectify"  %%  "deadbolt-scala"     % "2.1-RC2",
      // Comment this for local development of the Play Authentication core
      "com.feth"      %%  "play-authenticate" % "0.3.4-SNAPSHOT",
      "postgresql"    %   "postgresql"        % "9.1-901-1.jdbc4",
      //javaCore, - commented to keep SCALA nature in eclipse
      //javaJdbc,
      jdbc,
      javaEbean
    )

    import com.typesafe.sbteclipse.core.EclipsePlugin._ 

    val main = play.Project(appName, appVersion, appDependencies)
        //.settings(play.Project.playScalaSettings:_*)
        .settings(
      resolvers += Resolver.url("Objectify Play Repository (release)", url("http://schaloner.github.com/releases/"))(Resolver.ivyStylePatterns),
      resolvers += Resolver.url("Objectify Play Repository (snapshot)", url("http://schaloner.github.com/snapshots/"))(Resolver.ivyStylePatterns),

      resolvers += Resolver.url("play-easymail (release)", url("http://joscha.github.com/play-easymail/repo/releases/"))(Resolver.ivyStylePatterns),
      resolvers += Resolver.url("play-easymail (snapshot)", url("http://joscha.github.com/play-easymail/repo/snapshots/"))(Resolver.ivyStylePatterns),

      resolvers += Resolver.url("play-authenticate (release)", url("http://joscha.github.com/play-authenticate/repo/releases/"))(Resolver.ivyStylePatterns),
      resolvers += Resolver.url("play-authenticate (snapshot)", url("http://joscha.github.com/play-authenticate/repo/snapshots/"))(Resolver.ivyStylePatterns)

      // These keys wheren't used by sbt-eclipse when used in playframework
      //,EclipseKeys.projectFlavor := EclipseProjectFlavor.Scala
      //,PlayEclipse.mainLang := SCALA
    )
//  Uncomment this for local development of the Play Authenticate core:
//    .dependsOn(playAuthenticate).aggregate(playAuthenticate)

}

I also needed to add to some templates the following imports since defaultScalaTemplatesImport differ from the defaultJavaTemplatesImport at https://github.com/playframework/playframework/blob/b4006e9dbecaca6f8257a209f7d0fdc6e0345b48/framework/src/sbt-plugin/src/main/scala/PlayKeys.scala

@import play.mvc.Http.Context.Implicit._
@import scala.collection.JavaConversions._
@import scala.collection.JavaConverters._
0
votes

Add the following Sbt eclipse plugin in your plugins.sbt

addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.3.0")

From the play console, type "eclipse" and hit enter.

Take a look at SBTEclipse plugin. I see that you are already on latest version of Play. May I suggest you to try 'activator' from typesafe.