Search code examples
scalasbtsbt-plugin

Sbt plugin published to nexus with sbt.version 1.2.8 is not resolved by sbt projects which are using sbt.version >1.2.8


We published our sbt plugin to local m2 repository using sbt clean compile publishM2.

Below is the simplified plugin source code :-

build.sbt :-

name := "base-plugin"
version := "0.1"
organization := "io.github.moglideveloper"

sbtPlugin := true

val pluginDeveloper = Developer("mogli", "mogli", "[email protected]", url("https://github.com/moglideveloper"))
developers := List(pluginDeveloper)

homepage := Some(url("https://github.com/moglideveloper/BasePlugin"))
scmInfo := Some(ScmInfo(url("https://github.com/moglideveloper/BasePlugin"), "[email protected]:moglideveloper/BasePlugin.git"))

licenses += ("MIT", url("https://opensource.org/licenses/MIT"))

publishMavenStyle := true
publishArtifact in Test := false
publishConfiguration := publishConfiguration.value.withOverwrite(true)
publishTo := Some(Opts.resolver.sonatypeStaging)

build.properties :-

sbt.version=1.2.8

We are using 1.2.8 because of existing issues of sbt upgrade :-

https://github.com/xerial/sbt-sonatype/pull/98

https://github.com/sbt/sbt/issues/5049

BasePlugin.scala :-

package io.moglideveloper.base_plugin

import sbt._

object BasePlugin extends AutoPlugin {

  lazy val hello = taskKey[Unit]("just say hello")

  override def trigger = allRequirements

  override lazy val projectSettings = Seq(
    hello := {
      println("hello")
    }
  )
}

Now, above published plugin is not resolved correctly with any sbt version that is 1.x, for example sbt.version=1.2.8

Below is the exception trace :-

/Users/mogli/.sdkman/candidates/java/11.0.9.hs-adpt/bin/java -Djline.terminal=jline.UnsupportedTerminal -Dsbt.log.noformat=true -Dfile.encoding=UTF-8 -Didea.managed=true -Dfile.encoding=UTF-8 -jar /Users/mogli/Library/Application Support/JetBrains/IdeaIC2020.3/plugins/Scala/launcher/sbt-launch.jar
[info] Loading settings for project resolvecheck-build from plugins.sbt ...
[info] Loading project definition from /Users/mogli/sources/ResolveCheck/project
[info] Updating ProjectRef(uri("file:/Users/mogli/sources/ResolveCheck/project/"), "resolvecheck-build")...
[warn]  module not found: io.github.moglideveloper#base-plugin;0.1
[warn] ==== typesafe-ivy-releases: tried
[warn]   https://repo.typesafe.com/typesafe/ivy-releases/io.github.moglideveloper/base-plugin/scala_2.12/sbt_1.0/0.1/ivys/ivy.xml
[warn] ==== sbt-plugin-releases: tried
[warn]   https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/io.github.moglideveloper/base-plugin/scala_2.12/sbt_1.0/0.1/ivys/ivy.xml
[warn] ==== local: tried
[warn]   /Users/mogli/.ivy2/local/io.github.moglideveloper/base-plugin/scala_2.12/sbt_1.0/0.1/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/io/github/moglideveloper/base-plugin_2.12_1.0/0.1/base-plugin-0.1.pom
[warn] ==== local-preloaded-ivy: tried
[warn]   /Users/mogli/.sbt/preloaded/io.github.moglideveloper/base-plugin/0.1/ivys/ivy.xml
[warn] ==== local-preloaded: tried
[warn]   file:////Users/mogli/.sbt/preloaded/io/github/moglideveloper/base-plugin_2.12_1.0/0.1/base-plugin-0.1.pom
[warn] ==== Local Repository: tried
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: io.github.moglideveloper#base-plugin;0.1: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn]  Note: Some unresolved dependencies have extra attributes.  Check that these dependencies exist with the requested attributes.
[warn]      io.github.moglideveloper:base-plugin:0.1 (scalaVersion=2.12, sbtVersion=1.0)
[warn]
[warn]  Note: Unresolved dependencies path:
[warn]      io.github.moglideveloper:base-plugin:0.1 (scalaVersion=2.12, sbtVersion=1.0) (/Users/mogli/sources/ResolveCheck/project/plugins.sbt#L2-3)
[warn]        +- default:resolvecheck-build:0.1.0-SNAPSHOT (scalaVersion=2.12, sbtVersion=1.0)
[error] sbt.librarymanagement.ResolveException: unresolved dependency: io.github.moglideveloper#base-plugin;0.1: not found
[error]     at sbt.internal.librarymanagement.IvyActions$.resolveAndRetrieve(IvyActions.scala:332)
[error]     at sbt.internal.librarymanagement.IvyActions$.$anonfun$updateEither$1(IvyActions.scala:208)
[error]     at sbt.internal.librarymanagement.IvySbt$Module.$anonfun$withModule$1(Ivy.scala:239)
[error]     at sbt.internal.librarymanagement.IvySbt.$anonfun$withIvy$1(Ivy.scala:204)
[error]     at sbt.internal.librarymanagement.IvySbt.sbt$internal$librarymanagement$IvySbt$$action$1(Ivy.scala:70)
[error]     at sbt.internal.librarymanagement.IvySbt$$anon$3.call(Ivy.scala:77)
[error]     at xsbt.boot.Locks$GlobalLock.withChannel$1(Locks.scala:95)
[error]     at xsbt.boot.Locks$GlobalLock.xsbt$boot$Locks$GlobalLock$$withChannelRetries$1(Locks.scala:80)
[error]     at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock$1.apply(Locks.scala:99)
[error]     at xsbt.boot.Using$.withResource(Using.scala:10)
[error]     at xsbt.boot.Using$.apply(Using.scala:9)
[error]     at xsbt.boot.Locks$GlobalLock.ignoringDeadlockAvoided(Locks.scala:60)
[error]     at xsbt.boot.Locks$GlobalLock.withLock(Locks.scala:50)
[error]     at xsbt.boot.Locks$.apply0(Locks.scala:31)
[error]     at xsbt.boot.Locks$.apply(Locks.scala:28)
[error]     at sbt.internal.librarymanagement.IvySbt.withDefaultLogger(Ivy.scala:77)
[error]     at sbt.internal.librarymanagement.IvySbt.withIvy(Ivy.scala:199)
[error]     at sbt.internal.librarymanagement.IvySbt.withIvy(Ivy.scala:196)
[error]     at sbt.internal.librarymanagement.IvySbt$Module.withModule(Ivy.scala:238)
[error]     at sbt.internal.librarymanagement.IvyActions$.updateEither(IvyActions.scala:193)
[error]     at sbt.librarymanagement.ivy.IvyDependencyResolution.update(IvyDependencyResolution.scala:20)
[error]     at sbt.librarymanagement.DependencyResolution.update(DependencyResolution.scala:56)
[error]     at sbt.internal.LibraryManagement$.resolve$1(LibraryManagement.scala:45)
[error]     at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$12(LibraryManagement.scala:93)
[error]     at sbt.util.Tracked$.$anonfun$lastOutput$1(Tracked.scala:68)
[error]     at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$19(LibraryManagement.scala:106)
[error]     at scala.util.control.Exception$Catch.apply(Exception.scala:224)
[error]     at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11(LibraryManagement.scala:106)
[error]     at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11$adapted(LibraryManagement.scala:89)
[error]     at sbt.util.Tracked$.$anonfun$inputChanged$1(Tracked.scala:149)
[error]     at sbt.internal.LibraryManagement$.cachedUpdate(LibraryManagement.scala:120)
[error]     at sbt.Classpaths$.$anonfun$updateTask$5(Defaults.scala:2561)
[error]     at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error]     at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:40)
[error]     at sbt.std.Transform$$anon$4.work(System.scala:67)
[error]     at sbt.Execute.$anonfun$submit$2(Execute.scala:269)
[error]     at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error]     at sbt.Execute.work(Execute.scala:278)
[error]     at sbt.Execute.$anonfun$submit$1(Execute.scala:269)
[error]     at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
[error]     at sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
[error]     at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]     at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[error]     at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]     at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[error]     at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[error]     at java.base/java.lang.Thread.run(Thread.java:834)
[error] (update) sbt.librarymanagement.ResolveException: unresolved dependency: io.github.moglideveloper#base-plugin;0.1: not found
Invalid response.

Below is simplified sbt project source from where we attempt to resolve our sbt plugin :-

build.sbt :-

name := "ResolveBasePlugin"

build.properties :-

sbt.version=1.2.8

plugins.sbt :-

resolvers += Opts.resolver.mavenLocalFile
addSbtPlugin("io.github.moglideveloper" % "base-plugin" % "0.1")
addSbtPlugin("org.xerial.sbt" % "sbt-pack" % "0.13")

Link to simplified plugin :- https://github.com/moglideveloper/BasePlugin

Link to simplified sbt project that attempts to resolve base-plugin https://github.com/moglideveloper/ResolveCheck

Kindly suggest, what changes shall we do to BasePlugin, so that it can be resolved in sbt projects
that are using sbt.version=1.x
For eg :- 
sbt pack plugin is published with sbt.version=1.2.8, still it can be resolved
from sbt projects with sbt.version=1.4.5

https://github.com/xerial/sbt-pack/blob/master/project/build.properties


Solution

  • I think you need the following in your project/plugins.sbt:

    // bad: resolvers += Opts.resolver.mavenLocalFile
    
    // good
    resolvers += Resolver.mavenLocal
    

    See Local Maven resolvers.

    Note

    Can you please explain what is the difference between the two?

    Apache Ivy and Coursier both have resolvers for Maven-layout repositories and Ivy-layout repositories, so within sbt they need to be expressed using different types.

    Resolver.mavenLocal has the static type of MavenRepository represented by MavenCache and would translate to a "plugin-capable" IBiblioResolver for Ivy. On the other hand, Opts.resolver.mavenLocalFile is a filesystem resolver:

    val mavenLocalFile = Resolver.file("Local Repository", userHome / ".m2" / "repository")(
      Resolver.defaultPatterns
    )
    

    This would translate to an Ivy repository with Maven-like pattern. It might work for some artifacts, but apparently not for sbt plugins. In general, I can't think of a situation Opts.resolver.mavenLocalFile must be used.