无法在播放应用程序中导入sbt-rjs插件

时间:2016-07-25 09:35:18

标签: scala playframework sbt sbt-web sbt-rjs

我想在我的java应用程序中连接JavaScript文件,这是基于play framework 2.5。

plugins.sbt中,我添加了以下代码:

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

我还补充说:

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)

Build.scala我已添加:

pipelineStages := Seq(rjs)

当我运行>activator clean dist时,我得到:

"rjs is undefined"

我尝试添加:

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

rjs中没有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
    )
}

我所知道的是如何在应用程序中安装sbt-rjs插件。

1 个答案:

答案 0 :(得分:1)

您的Build.scala项目存在多个问题:

进口

您有不存在的导入,例如:

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

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

而且,这个,我想这会产生你的报告问题:

import com.typesafe.sbt._

问题在于rjscom.typesafe.sbt的子包,然后在rjs内使用Build.scala实际引用包而不是您想要的配置。将上面的导入替换为:

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

然后它将正确引用rjs管道阶段。

配置错误

你有:

enablePlugins(play.PlayJava,SbtWeb)

play.PlayJava不存在。正确的行是:

enablePlugins(play.sbt.PlayJava, SbtWeb)

为什么不使用build.sbt代替。您的构建没有什么特别之处,build.sbt会更简单:

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")