无法导入本地发布的 Scala 插件

Unable to import locally published Scala plugin

我有一个项目作为插件在本地发布到我的 .m2 目录,稍后我需要将其导入到不同的 Scala 项目中并使用它。 发布步骤似乎已正确执行。 插件项目的 build.sbt 文件如下所示:

lazy val root = (project in file("."))
  .enablePlugins(SbtPlugin)
  .settings(
    name := "pluginName",
    organization := "com.myOrg",
    pluginCrossBuild / sbtVersion := {
      scalaBinaryVersion.value match {
        case "2.12" => "1.4.6" // set minimum sbt version
      }
    }
  )

resolvers += "confluent" at "https://packages.confluent.io/maven"

libraryDependencies ++= Seq(
      "io.confluent"    % "kafka-schema-registry-client" % "7.0.1"
      // some other dependemcies
    )

在 运行 sbt shell 中的 compilepublishLocal 命令之后,我收到下一条消息:

[info]  delivering ivy file to /Users/me/Work/repos/external/pluginName/target/scala-2.12/sbt-1.0/ivy-1.0.0.xml
[info]  published pluginName to /Users/me/.ivy2/local/com.myOrg/pluginName/scala_2.12/sbt_1.0/1.0.0/poms/pluginName.pom
[info]  published pluginName to /Users/me/.ivy2/local/com.myOrg/pluginName/scala_2.12/sbt_1.0/1.0.0/jars/pluginName.jar
[info]  published pluginName to /Users/me/.ivy2/local/com.myOrg/pluginName/scala_2.12/sbt_1.0/1.0.0/srcs/pluginName-sources.jar
[info]  published pluginName to /Users/me/.ivy2/local/com.myOrg/pluginName/scala_2.12/sbt_1.0/1.0.0/docs/pluginName-javadoc.jar
[info]  published ivy to /Users/me/.ivy2/local/com.myOrg/pluginName/scala_2.12/sbt_1.0/1.0.0/ivys/ivy.xml
[success] Total time: 0 s, completed 3 Jan 2022, 10:07:43

为了在其他 Scala 项目中 import/install 这个插件,我在 plugins.sbt 文件中添加了下一行:addSbtPlugin("com.myOrg" % "pluginName" % "1.0.0") 我还在 buid.sbt 文件的 externalResolvers 部分添加了 libs-release-locallibs-snapshot-local

重新加载和编译项目后,我收到此错误:

    [error] (update) sbt.librarymanagement.ResolveException: Error downloading io.confluent:kafka-schema-registry-client:7.0.1
[error]   Not found
[error]   Not found
[error]   not found: https://repo1.maven.org/maven2/io/confluent/kafka-schema-registry-client/7.0.1/kafka-schema-registry-client-7.0.1.pom
[error]   not found: /Users/me/.ivy2/local/io.confluent/kafka-schema-registry-client/7.0.1/ivys/ivy.xml
[error]   not found: https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/io.confluent/kafka-schema-registry-client/7.0.1/ivys/ivy.xml
[error]   not found: https://repo.typesafe.com/typesafe/ivy-releases/io.confluent/kafka-schema-registry-client/7.0.1/ivys/ivy.xml

我是 Scala 的新手,我不明白我做错了什么。 任何人都可以阐明这个问题吗?

您正在发布到本地 Maven 缓存,但 sbt 使用 Ivy。

尝试删除 publishTo 设置,应该不需要。只需使用 publishLocal 任务发布到本地 Ivy 缓存。