Playframework Play Framework 2.3.4:如何将JSHint作为编译任务的一部分运行

Playframework Play Framework 2.3.4:如何将JSHint作为编译任务的一部分运行,playframework,sbt,jshint,Playframework,Sbt,Jshint,我有一个多项目应用程序,我想让JSHint作为编译任务的一部分运行。以下是我如何配置我的项目: 1) 将JSHint插件添加到myApp/project/plugins.sbt: ... addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.1") ... lazy val apidocs = project.in(file("modules/apidocs")).enablePlugins(play.PlayScala, SbtWeb

我有一个多项目应用程序,我想让
JSHint
作为编译任务的一部分运行。以下是我如何配置我的项目:

1) 将JSHint插件添加到
myApp/project/plugins.sbt

...

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

lazy val apidocs = project.in(file("modules/apidocs")).enablePlugins(play.PlayScala, SbtWeb).settings(
  javaOptions in Test += "-Dconfig.resource=apidocs-application.conf"
).dependsOn(
  common % "test->test;compile->compile"
)
val triggeredTask = taskKey[Seq[sbt.File]]("Triggered by compile")

triggeredTask <<= Def.task {
  JshintKeys.jshint.value
}.triggeredBy(compile in Compile)
2) 在
myApp/build.sbt
中启用它(SbtWeb):

...

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

lazy val apidocs = project.in(file("modules/apidocs")).enablePlugins(play.PlayScala, SbtWeb).settings(
  javaOptions in Test += "-Dconfig.resource=apidocs-application.conf"
).dependsOn(
  common % "test->test;compile->compile"
)
val triggeredTask = taskKey[Seq[sbt.File]]("Triggered by compile")

triggeredTask <<= Def.task {
  JshintKeys.jshint.value
}.triggeredBy(compile in Compile)

我还尝试运行
资产
任务。。。但是看起来JSHint没有被调用。如何使JSHint作为编译任务的一部分运行?也许更好的选择是修改
myApp/projects/Build.scala
,让JSHint压缩任何子项目中的
*.js

JSHint不会压缩任何内容,它会检测并警告Java脚本中的错误做法

从插件的文档(和源代码)来看,linting任务似乎不是自动运行的,它只是提供了任务“jshint”,您可以在sbt控制台中调用该任务以获得jshint结果输出


你可能会将它与你的项目的编译任务结合起来,在出现警告时让它失败,但我无法从我的头脑中确切地告诉你怎么做,我建议你与sbt成为更好的朋友来解决这个问题。()

首先,我假设您正在使用(似乎至少有3个流行版本)

总的来说,我们需要一个由编译触发的任务。这是非常容易适应的。因此,我们将以下内容添加到
build.sbt

...

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

lazy val apidocs = project.in(file("modules/apidocs")).enablePlugins(play.PlayScala, SbtWeb).settings(
  javaOptions in Test += "-Dconfig.resource=apidocs-application.conf"
).dependsOn(
  common % "test->test;compile->compile"
)
val triggeredTask = taskKey[Seq[sbt.File]]("Triggered by compile")

triggeredTask <<= Def.task {
  JshintKeys.jshint.value
}.triggeredBy(compile in Compile)
val triggeredTask=taskKey[Seq[sbt.File]](“由编译触发”)
触发任务