Home > Blockchain >  Unable to import locally published Scala plugin
Unable to import locally published Scala plugin

Time:01-04

I have a project which I publish locally to my .m2 directory as a plugin, which later I need to import into a different Scala project and use it. It seems like the publishing step is executed correctly. The build.sbt file of the plugin project looks like this:

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
    )

After running the compile and publishLocal commands in sbt shell I get the next message:

[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

In order to import/install this plugin in the other Scala project, I have added the next line to the plugins.sbt file: addSbtPlugin("com.myOrg" % "pluginName" % "1.0.0") I also added libs-release-local and libs-snapshot-local to the externalResolvers section in the buid.sbt file.

After reloading and compiling the project I received this error:

    [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

I am kind of new to Scala and I don't understand what and I doing wrong. Can anyone shed some light on this problem?

CodePudding user response:

You're publishing to your local Maven cache, but sbt uses Ivy.

Try removing the publishTo setting, it shouldn't be needed. Just use the publishLocal task to publish to your local Ivy cache.

  • Related