sbt - sbt 说“不是一个有效的命令”,但启用了插件
问题描述
我有一个名为 sonar 的插件,它是作为 AutoPlugin 开发和发布的:
object Sonar extends AutoPlugin {
object autoImport {
lazy val sonar = taskKey[Unit]("sonar")
}
import autoImport._
override def trigger = allRequirements
lazy val sonarTask = Def.task {
<snip task code here which runs sonarqube scanner>
}
}
然后我们有一个使用该插件的项目,plugins.sbt
它看起来像这样:
resolvers ++= Seq(
"Nexus Snapshot repo" at "url here"
)
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")
addSbtPlugin("packagename" % "sonar" % "1.0-SNAPSHOT")
像这样 build.sbt :
name := "hashing-library"
organization := "org name here"
scalaVersion := "2.12.6"
autoScalaLibrary := false
crossPaths := false
resolvers += "Nexus Release repo" at "https://nexusurl/content/repositories/releases/"
resolvers += "nexus Snapshot repo" at "https://nexusurl/content/repositories/snapshots/"
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")
// Publishing options:
publishMavenStyle := true
publishArtifact in Test := false
pomIncludeRepository := { x => false }
publishTo := {
val nexus = "nexus url here"
if (isSnapshot.value)
Some("sonatype-snapshots" at nexus + "content/repositories/snapshots")
else
Some("sonatype-releases" at nexus + "content/repositories/releases")
}
当我尝试运行 sbt 插件时,它说插件已启用:
<snip output>
packagename.sonar.Sonar: enabled in hashingLibrary
那么为什么我的插件已启用,但我无法运行sbt sonar
?当我这样做时,它说:
[info] Set current project to hashing-library (in build file:/home/work/hashing-library/)
[error] Not a valid command: sonar
[error] Not a valid project ID: sonar
[error] Expected ':'
[error] Not a valid key: sonar
[error] sonar
[error]
(显然组织名称和网址已被删除以保护我的客户的机密性,但希望这不会影响我的问题!)
解决方案
sonar
您的插件缺少的部分是任务键和sonarTask
任务实现之间的连接,即您需要在某处说键设置为实现的值。您通常通过覆盖插件中的项目设置来做到这一点:
override def projectSettings = Seq(
sonar := sonarTask.value
)
推荐阅读
- flutter - BitmapDescriptor.fromBytes 在 iOS 上不起作用,但在 Android 上运行良好
- android - 比较不同的 adb 日志
- c - 在 C 中计算破折号以退出 While 循环
- react-native - React Native 垂直粘性滑动标签栏/面板
- javascript - 通过“require”功能将菜单导入浏览器窗口
- firebase - Flutter App 卡在启动画面,没有移动到登录页面或主页
- python - 分类数据计数
- javascript - 尝试在 Angular 的新选项卡中打开网站但无法正常工作
- sql - 如何删除数据库中5分钟内取消的订单记录?
- javascript - 使用反应链接时如何防止外部网址附加到本地主机网址?