我正在尝试编写一个非常基本的 SBT 插件来发布和使用仅源代码包,以将节俭的 IDL 文件传递给其他想要调用我的 API 的服务。为什么说来话长,但这个问题是关于 SBT 而不是节俭。
build.sbt
当我按预期在作品中编写以下内容时( src/main
jar中仅包含以下文件:
name := "test-dep2"
scalaVersion := "2.12.5"
lazy val root = (project in file(".")).
settings(
inThisBuild(List(
organization := "com.example",
scalaVersion := "2.12.4",
version := "0.1.1-SNAPSHOT")),
name := "test-dep2",
mappings in (Compile, packageBin) := {
(sourceDirectory.value / "main" ** "*.*").get. map { file =>
(file, file.relativeTo(baseDirectory.value).get.toString )
}
}
)
但是,以下build.sbt
内容不起作用(即,jar 包含已编译的类,正常):
name := "test-dep2"
scalaVersion := "2.12.5"
lazy val root = (project in file(".")).
settings(
inThisBuild(List(
organization := "com.example",
scalaVersion := "2.12.4",
version := "0.1.1-SNAPSHOT")),
name := "test-dep2"
).enablePlugins(com.example.sbt.MyPlugin)
这是MyPlugin
:
package com.example
import sbt.Keys._
import sbt._
object MyPlugin extends AutoPlugin {
object autoImport {
val someTask = taskKey[Unit]("Some task")
}
import autoImport._
val sbtSourceSettings: Seq[Setting[_]] = Seq(
someTask := {
println("I'm doing something!")
},
mappings in (Compile, packageBin) := {
(sourceDirectory.value / "main" ** "*.*").get. map { file =>
(file, file.relativeTo(baseDirectory.value).get.toString )}
}
)
override lazy val projectSettings: Seq[Def.Setting[_]] = sbtSourceSettings
}
通过 将插件添加到项目project/plugins.sbt
中,包含以下内容:
lazy val root = (project in file(".")).dependsOn(assemblyPlugin)
lazy val assemblyPlugin = RootProject(uri("file:///home/tjarvstrand/src/sbt-source-only-dependency"))
我知道插件已加载,因为我可以运行sbt root/someTask
并打印I'm doing something
. 我究竟做错了什么?