0

I wanted to concatenate JavaScript files in my java application which is built on play framework 2.5.

In plugins.sbt, I have added the below code:

addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.8")

I also added:

resolvers += Resolver.url("SBT Plugins", url("https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns)

resolvers += Resolver.url("bintray-sbt-plugins", url("https://dl.bintray.com/sbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns)

In Build.scala I have added:

pipelineStages := Seq(rjs)

When I run >activator clean dist I get:

"rjs is undefined"

I tried adding:

import com.typesafe.sbt.rjs.Import._

But there is no rjs package in com.typesafe.sbt.

Build.scala

import play.PlayScala
import sbt._
import Keys._
import play.Play.autoImport._
import com.typesafe.sbt._
import com.typesafe.sbt.web.SbtWeb
import de.johoop.jacoco4sbt.JacocoPlugin._
import com.typesafe.sbt.web.Import.pipelineStages

object ApplicationBuild extends Build {

    def fromEnv(name: String) = System.getenv(name) match {
       case null => None
       case value => Some(value)
    }

    val appName = fromEnv("artifactId").getOrElse("BMT")
    val appVersion = fromEnv("version").getOrElse("1.2-SNAPSHOT")

    pipelineStages := Seq(rjs)

    val appDependencies = Seq(
        javaJdbc,
        javaCore,
        javaJpa,
        javaWs,
        cache,
        javaJpa.exclude("org.hibernate.javax.persistence", "hibernate-jpa-2.0-api"),
        "org.hibernate" % "hibernate-entitymanager" % "4.3.5.Final",
        "org.mockito" % "mockito-all" % "1.9.5" % "test",
        "org.apache.poi" % "poi" % "3.9",
        "org.apache.poi" % "poi-ooxml" % "3.9",
        "org.json" % "json" % "20090211",
        "commons-codec" % "commons-codec" % "1.9",
        "org.apache.directory.api" % "api-all" % "1.0.0-M33" exclude("org.apache.directory.api", "api-ldap-schema-data"),
        "org.apache.directory.server" % "apacheds-server-annotations" % "2.0.0-M15" % "test" exclude("org.apache.directory.api", "api-ldap-schema-data"),
        "org.apache.directory.server" % "apacheds-test-framework" % "2.0.0-M15" % "test" exclude("org.apache.directory.api", "api-ldap-schema-data"),
        "com.microsoft.windowsazure" % "microsoft-windowsazure-api" % "0.4.6"
    )

    val main = Project(appName, file(".")).enablePlugins(play.PlayJava,SbtWeb).settings(
        version := appVersion,
        libraryDependencies ++= appDependencies
    )
}

What I know is how to get the sbt-rjs plugin installed in the application.

marcospereira
  • 11,462
  • 3
  • 42
  • 49
user1184100
  • 6,322
  • 27
  • 74
  • 116

1 Answers1

1

There is more than one problem with your Build.scala project:

Imports

You have imports that do not exists, like:

import play.PlayScala
// the correct import is play.sbt.PlayScala

import play.Play.autoImport._
// the correct import is play.sbt.Play.autoImport._

And also, this one, which I suppose is generating the problem your report:

import com.typesafe.sbt._

Problem here is that rjs is a subpackage of com.typesafe.sbt and then using rjs inside your Build.scala actually references the package instead of the configuration you want. Replace the import above with:

import com.typesafe.sbt.rjs.SbtRjs.autoImport._

And then it will properly reference the rjs pipeline stage.

Misconfigurations

You have:

enablePlugins(play.PlayJava,SbtWeb)

But play.PlayJava does not exists. The correct line would be:

enablePlugins(play.sbt.PlayJava, SbtWeb)

Why not to use build.sbt instead. There is nothing special in your build and build.sbt would be simpler:

lazy val root = (project in file(".")).enablePlugins(PlayJava)

scalaVersion := "2.11.7"

libraryDependencies ++= Seq(
  javaJdbc,
  javaCore,
  javaJpa,
  javaWs,
  cache,
  javaJpa.exclude("org.hibernate.javax.persistence", "hibernate-jpa-2.0-api"),
  "org.hibernate" % "hibernate-entitymanager" % "4.3.5.Final",
  "org.mockito" % "mockito-all" % "1.9.5" % "test",
  "org.apache.poi" % "poi" % "3.9",
  "org.apache.poi" % "poi-ooxml" % "3.9",
  "org.json" % "json" % "20090211",
  "commons-codec" % "commons-codec" % "1.9",
  "org.apache.directory.api" % "api-all" % "1.0.0-M33" exclude("org.apache.directory.api", "api-ldap-schema-data"),
  "org.apache.directory.server" % "apacheds-server-annotations" % "2.0.0-M15" % "test" exclude("org.apache.directory.api", "api-ldap-schema-data"),
  "org.apache.directory.server" % "apacheds-test-framework" % "2.0.0-M15" % "test" exclude("org.apache.directory.api", "api-ldap-schema-data"),
  "com.microsoft.windowsazure" % "microsoft-windowsazure-api" % "0.4.6"
)

pipelineStages := Seq(rjs)

def fromEnv(name: String) = System.getenv(name) match {
  case null => None
  case value => Some(value)
}

name := fromEnv("artifactId").getOrElse("BMT")

version := fromEnv("artifactId").getOrElse("BMT")
marcospereira
  • 11,462
  • 3
  • 42
  • 49
  • I don't have a sbt package under play. If I use play.sbt.PlayScala I get play.sbt is undefined. Similarly if I use import com.typesafe.sbt.rjs.SbtRjs.autoImport._ I get rjs is undefined in com.typesafe.sbt.rjs – user1184100 Jul 26 '16 at 06:52
  • Post your whole `plugin.sbt` file then. If you don't have these packages, then you probably don't have play sbt plugin added. – marcospereira Jul 28 '16 at 21:50
  • At some point (2.2? 2.3? I don't remember) the Play plugin moved from using the `play` package to using `play.sbt`. I assume @user1184100 is using an old version of Play. Seeing the contents of plugins.sbt will help. – danielnixon Mar 13 '17 at 03:06