Not able to cross publish my sbt plugin for multip

2019-09-01 05:04发布

问题:

I have the following sbt file

lazy val root = (project in file(".")).
  settings(
    inThisBuild(List(
      sbtPlugin := true, 
      organization := "com.foo",
      crossScalaVersions := Seq("2.11.2", "2.12.0"),
      version      := "1.0.0"
    )),
    name := "myplugin",
    libraryDependencies ++= Seq(
      "org.scala-lang.modules" %% "scala-xml" % "1.0.6",
      "com.typesafe" % "config" % "1.3.3"
    )
  )

Now I can easily do sbt publishLocal and I see that it generates a jar file in the .ivy2/local/com.foo/myplugin/scala_2.12/sbt_1.0/1.0.0/jars/

but if I do a

sbt +publishLocal

I get an error

[error] Modules were resolved with conflicting cross-version suffixes in ProjectRef(uri("file:/Users/user/myplugin/"), "root"):
[error]    org.scala-lang.modules:scala-xml _2.11, _2.12
[error]    org.scala-lang.modules:scala-parser-combinators _2.11, _2.12
[error] java.lang.RuntimeException: Conflicting cross-version suffixes in: org.scala-lang.modules:scala-xml, org.scala-lang.modules:scala-parser-combinators
[error]         at scala.sys.package$.error(package.scala:27)
[error]         at sbt.librarymanagement.ConflictWarning$.processCrossVersioned(ConflictWarning.scala:39)
[error]         at sbt.librarymanagement.ConflictWarning$.apply(ConflictWarning.scala:19)
[error]         at sbt.Classpaths$.$anonfun$ivyBaseSettings$64(Defaults.scala:1995)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error]         at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:39)
[error]         at sbt.std.Transform$$anon$4.work(System.scala:66)
[error]         at sbt.Execute.$anonfun$submit$2(Execute.scala:262)

My expectation was that SBT will do the compilation and publishing twice and each time it will pick the right jars for the right Scala version. Why does it say that there is a conflict?

My end goal is to make SBT publish multiple jar files one for each scala version in my crossScalaVersions list.

回答1:

sbt uses a fixed version of Scala: sbt 0.13 uses Scala 2.10, sbt 1.x uses Scala 2.12. So

  1. one thing is that you cannot compile an sbt plugin for Scala 2.11,
  2. and another thing is that you should cross-build your plugin for different versions of sbt (because Scala versions are implied).

There is documentation about Cross building plugins, but I'm not sure it is up to date, so it's better to see some examples in existing plugins. I think it should be enough to have this setup for your plugin project:

  • in project/build.properties:

    sbt.version=0.13.17
    
  • in build.sbt settings:

    sbtPlugin := true,
    crossSbtVersions := Seq("0.13.17", "1.0.0"),
    

See sbt-boilerplate for an example.



回答2:

After poking around with your build.sbt I found out the following:

  • removing all dependencies does not resolve the problem
  • removing sbtPlugin := true do resolve the problem
  • downgrading sbt from 1.x to 0.13.16 helps me compile your example

Additionally we should remember that sbt 0.13.x was written with Scala 2.10.

So, if you are writing a sbt plugin:

  • downgrade sbt
  • change Scala from 2.11.2 to 2.10.x

if you are not writing a plugin:

  • remove sbtPlugin := true


标签: scala sbt