How can I use an sbt plugin as a dependency in a multi-project build?

前端 未结 1 1234
無奈伤痛
無奈伤痛 2021-01-28 14:18

I have two sbt plugin projects that both use multi-project builds. I would like to use one of the plugins as a dependency for the other. I was able to get this working with sing

相关标签:
1条回答
  • 2021-01-28 14:27

    You're not setting a distinct name for each module:

    my-test-plugin

    > ;show root/name ;show plugin/name
    [info] my-test-plugin
    [info] my-test-plugin
    

    my-sub-plugin

    > ;show root/name ;show plugin/name
    [info] my-sub-plugin
    [info] my-sub-plugin
    

    As you can see, publishing in my-test-plugin works:

    > ;root/publishLocal ;plugin/publishLocal
    [info] Wrote /Users/dnw/Desktop/sbt-tests/my-test-plugin/target/scala-2.10/my-test-plugin_2.10-0.1.0-SNAPSHOT.pom
    [info] :: delivering :: com.example#my-test-plugin_2.10;0.1.0-SNAPSHOT :: 0.1.0-SNAPSHOT :: integration :: Sat Apr 11 09:16:15 BST 2015
    [info]  delivering ivy file to /Users/dnw/Desktop/sbt-tests/my-test-plugin/target/scala-2.10/ivy-0.1.0-SNAPSHOT.xml
    [info]  published my-test-plugin_2.10 to /Users/dnw/.ivy2/local/com.example/my-test-plugin_2.10/0.1.0-SNAPSHOT/poms/my-test-plugin_2.10.pom
    [info]  published my-test-plugin_2.10 to /Users/dnw/.ivy2/local/com.example/my-test-plugin_2.10/0.1.0-SNAPSHOT/jars/my-test-plugin_2.10.jar
    [info]  published my-test-plugin_2.10 to /Users/dnw/.ivy2/local/com.example/my-test-plugin_2.10/0.1.0-SNAPSHOT/srcs/my-test-plugin_2.10-sources.jar
    [info]  published my-test-plugin_2.10 to /Users/dnw/.ivy2/local/com.example/my-test-plugin_2.10/0.1.0-SNAPSHOT/docs/my-test-plugin_2.10-javadoc.jar
    [info]  published ivy to /Users/dnw/.ivy2/local/com.example/my-test-plugin_2.10/0.1.0-SNAPSHOT/ivys/ivy.xml
    [success] Total time: 0 s, completed 11-Apr-2015 09:16:15
    [info] Wrote /Users/dnw/Desktop/sbt-tests/my-test-plugin/plugin/target/scala-2.10/sbt-0.13/my-test-plugin-0.1.0-SNAPSHOT.pom
    [info] :: delivering :: com.example#my-test-plugin;0.1.0-SNAPSHOT :: 0.1.0-SNAPSHOT :: integration :: Sat Apr 11 09:16:15 BST 2015
    [info]  delivering ivy file to /Users/dnw/Desktop/sbt-tests/my-test-plugin/plugin/target/scala-2.10/sbt-0.13/ivy-0.1.0-SNAPSHOT.xml
    [info]  published my-test-plugin to /Users/dnw/.ivy2/local/com.example/my-test-plugin/scala_2.10/sbt_0.13/0.1.0-SNAPSHOT/poms/my-test-plugin.pom
    [info]  published my-test-plugin to /Users/dnw/.ivy2/local/com.example/my-test-plugin/scala_2.10/sbt_0.13/0.1.0-SNAPSHOT/jars/my-test-plugin.jar
    [info]  published my-test-plugin to /Users/dnw/.ivy2/local/com.example/my-test-plugin/scala_2.10/sbt_0.13/0.1.0-SNAPSHOT/srcs/my-test-plugin-sources.jar
    [info]  published my-test-plugin to /Users/dnw/.ivy2/local/com.example/my-test-plugin/scala_2.10/sbt_0.13/0.1.0-SNAPSHOT/docs/my-test-plugin-javadoc.jar
    [info]  published ivy to /Users/dnw/.ivy2/local/com.example/my-test-plugin/scala_2.10/sbt_0.13/0.1.0-SNAPSHOT/ivys/ivy.xml
    [success] Total time: 0 s, completed 11-Apr-2015 09:16:15
    

    But note the publish paths:

    com.example/my-test-plugin_2.10/0.1.0-SNAPSHOT/jars/my-test-plugin_2.10.jar
    com.example/my-test-plugin/scala_2.10/sbt_0.13/0.1.0-SNAPSHOT/jars/my-test-plugin.jar
    
    1. A non-sbt-plugin called my-test-plugin cross-built for Scala 2.10.
    2. An sbt-plugin called my-test-plugin, cross-built for Scala 2.10 and sbt 0.13.

    This has an impact when trying to resolve my-test-plugin in my-sub-plugin:

    [error] Modules were resolved with conflicting cross-version suffixes in {file:/Users/dnw/Desktop/sbt-tests/my-sub-plugin/}root:
    [error]    com.example:my-test-plugin <none>, _2.10
    java.lang.RuntimeException: Conflicting cross-version suffixes in: com.example:my-test-plugin
        at scala.sys.package$.error(package.scala:27)
        at sbt.ConflictWarning$.processCrossVersioned(ConflictWarning.scala:46)
        at sbt.ConflictWarning$.apply(ConflictWarning.scala:32)
    

    Try and specify different names for each module and it should work.

    0 讨论(0)
提交回复
热议问题