我有一个使用多项目构建的 sbt 插件项目。我想将此插件用作其他 sbt 项目的依赖项。我已经创建了一个插件,但是当我将此插件添加到项目时,我似乎无法正确链接依赖项。
sbt 插件
构建.sbt
name := "sbt-plugin"
sbtPlugin := true
val commonSettings = Seq(
organization := "com.example",
version := "1.0",
scalaVersion := "2.11.7",
javacOptions := Seq("-source", "1.8", "-target", "1.8"),
scalacOptions := Seq("-target:jvm-1.8", "-unchecked", "-deprecation", "-encoding", "utf8"))
lazy val plugin = (project in file("plugin"))
.settings(commonSettings: _*)
.settings(
name := "plugin"
)
lazy val root = (project in file("."))
.settings(commonSettings: _*)
.dependsOn(plugin)
.aggregate(plugin)
sbt-plugin\plugin\src\main\scala\com\example\Hello.scala
package com.example
// Sample code I would like to access from another sbt project
object Hello {
def show = println("Hello, world!")
}
插件测试
plugin-test 是一个 sbt 项目,我用来测试 sbt-plugin
插件测试\build.sbt
name := """plugin-test"""
version := "1.0"
scalaVersion := "2.11.7"
libraryDependencies += "org.scalatest" %% "scalatest" % "2.2.4" % "test"
fork in run := true
插件测试\项目\plugins.sbt
addSbtPlugin("com.example" % "sbt-plugin" % "1.0", "0.13","2.11")
插件测试\src\main\scala\com\exam\Test.scala
package com.exam
object Test {
def result = com.example.Hello.show()
}
但是当我编译插件测试项目时,它显示以下错误:
[error] E:\Play\SBT Plugin\sbt demo1\plugin-test\src\main\scala\com\exam\Test.scala:4: object example is not a member of package com
[error] def result = com.example.Hello.show()
[error] one error found
我在两个项目上都执行了发布本地和插件/发布本地,并且工件正确解析。我将 sbt-plugin 添加到plugins.sbt
并编译了项目,但Test.scala
由于上述错误无法编译,就好像依赖项不存在一样。
我在这里想念什么?