SBT插件的交叉发布不起作用

时间:2018-04-04 16:17:43

标签: scala sbt

我的目标是编写一个SBT插件,可供SBT 0.13.x和1.x版本的SBT使用。基于this主题和this文档。我为我的插件项目编写了以下build.sbt

lazy val foo = (project in file(".")).settings(
   name := "foo",
   sbtPlugin := true,
   organization := "com.bar",
   version := "1.0.0",
   scalaVersion:= "2.12.4",
   sbtVersion in Global := "1.0.0",
   crossSbtVersions := Seq("0.13.17", "1.0.0"),
   libraryDependencies ++= Seq(
       "com.typesafe" % "config" % "1.3.3"
   ),
   scalaCompilerBridgeSource := {
      val sv = appConfiguration.value.provider.id.version
      ("org.scala-sbt" % "compiler-interface" % sv % "component").sources
   }
)

当我sbt +publichLocal时,我看到了

info] Packaging /Users/user1/IdeaProjects/fulfillment-sbt/target/scala-2.12/sbt-0.13/foo-1.0.0-javadoc.jar ...
[info] Done packaging.
[info]  published foo to /Users/user1/.ivy2/local/com.bar/foo/scala_2.12/sbt_0.13/1.0.0/poms/foo.pom
[info]  published foo to /Users/user1/.ivy2/local/com.bar/foo/scala_2.12/sbt_0.13/1.0.0/jars/foo.jar
[info]  published foo to /Users/user1/.ivy2/local/com.bar/foo/scala_2.12/sbt_0.13/1.0.0/srcs/foo-sources.jar
[info]  published foo to /Users/user1/.ivy2/local/com.bar/foo/scala_2.12/sbt_0.13/1.0.0/docs/foo-javadoc.jar
[info]  published ivy to /Users/user1/.ivy2/local/com.bar/foo/scala_2.12/sbt_0.13/1.0.0/ivys/ivy.xml
[success] Total time: 9 s, completed Apr 4, 2018 11:12:38 AM

但它没有发布1.0版本的SBT。我能为两个版本的SBT发布什么?

1 个答案:

答案 0 :(得分:1)

我去了SBT的gitter频道并与SBT的创作者进行了对话。基于那次谈话,我创建了一个工作示例。我在这里列出它,以便将来帮助某人交叉发布sbt插件。

项目/ build.properties

sbt.version=0.13.17

build.sbt

lazy val p = (project in file(".")).settings(
   name := "sbt-crosspublish",
   sbtPlugin := true,
   organization := "com.abhi",
   version := "1.0.0",
   crossScalaVersions := Seq("2.10.6", "2.12.0"),   
   crossSbtVersions := Seq("0.13.17", "1.0.0"),
   libraryDependencies ++= Seq(
       "com.typesafe" % "config" % "1.3.3"
   ),
   scalaCompilerBridgeSource := {
      val sv = appConfiguration.value.provider.id.version
      ("org.scala-sbt" % "compiler-interface" % sv % "component").sources
   }
)

最后,为了交叉发布SBT插件,必须要做

sbt ^publishLocal

哇。我不知道^ sbt +publishLocal用于交叉发布普通二进制文件而不是插件。对于sbt插件的交叉发布,我们必须sbt ^publishLocal

需要注意的一点是,只有在使用SBT 0.13.17时才需要scalaCompilerBridgeSource。如果您在插件项目中升级到SBT 1.1.0,则代码将被简化。

项目/ build.properties

sbt.version=1.1.2

build.sbt

lazy val p = (project in file(".")).settings(
   name := "sbt-crosspublish",
   sbtPlugin := true,
   organization := "com.abhi",
   version := "1.0.0",
   crossScalaVersions := Seq("2.10.6", "2.12.0"),   
   crossSbtVersions := Seq("0.13.17", "1.0.0"),
   libraryDependencies ++= Seq(
       "com.typesafe" % "config" % "1.3.3"
   )
)