From 4a27bd42bcc0017e7886bbade33f7fe1ca952188 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Fri, 26 Jul 2019 15:36:50 +0200 Subject: [PATCH] Fix NoSuchMethodError when using coursier-based sbt launcher (#104) --- .../update-classifiers-1.3.0-RC1/build.sbt | 1 + .../update-classifiers-1.3.0-RC1/disabled | 4 + .../project/build.properties | 2 + .../project/plugins.sbt | 13 +++ .../src/main/scala/sbt/hack/Foo.scala | 83 +++++++++++++++---- 5 files changed, 85 insertions(+), 18 deletions(-) create mode 100644 modules/sbt-coursier/src/sbt-test/sbt-lm-coursier/update-classifiers-1.3.0-RC1/build.sbt create mode 100644 modules/sbt-coursier/src/sbt-test/sbt-lm-coursier/update-classifiers-1.3.0-RC1/disabled create mode 100644 modules/sbt-coursier/src/sbt-test/sbt-lm-coursier/update-classifiers-1.3.0-RC1/project/build.properties create mode 100644 modules/sbt-coursier/src/sbt-test/sbt-lm-coursier/update-classifiers-1.3.0-RC1/project/plugins.sbt diff --git a/modules/sbt-coursier/src/sbt-test/sbt-lm-coursier/update-classifiers-1.3.0-RC1/build.sbt b/modules/sbt-coursier/src/sbt-test/sbt-lm-coursier/update-classifiers-1.3.0-RC1/build.sbt new file mode 100644 index 000000000..cac761e5c --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/sbt-lm-coursier/update-classifiers-1.3.0-RC1/build.sbt @@ -0,0 +1 @@ +scalaVersion := "2.13.0" diff --git a/modules/sbt-coursier/src/sbt-test/sbt-lm-coursier/update-classifiers-1.3.0-RC1/disabled b/modules/sbt-coursier/src/sbt-test/sbt-lm-coursier/update-classifiers-1.3.0-RC1/disabled new file mode 100644 index 000000000..f9d160f99 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/sbt-lm-coursier/update-classifiers-1.3.0-RC1/disabled @@ -0,0 +1,4 @@ +# currently, the coursier-based sbt launcher starts sbt in the scripted tests +# without the coursier sbt plugins. This pulls the lm-coursier-shaded version +# that sbt depends on, which lacks some methods +> updateClassifiers diff --git a/modules/sbt-coursier/src/sbt-test/sbt-lm-coursier/update-classifiers-1.3.0-RC1/project/build.properties b/modules/sbt-coursier/src/sbt-test/sbt-lm-coursier/update-classifiers-1.3.0-RC1/project/build.properties new file mode 100644 index 000000000..50ffba806 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/sbt-lm-coursier/update-classifiers-1.3.0-RC1/project/build.properties @@ -0,0 +1,2 @@ +# testing regression since this sbt version +sbt.version=1.3.0-RC1 diff --git a/modules/sbt-coursier/src/sbt-test/sbt-lm-coursier/update-classifiers-1.3.0-RC1/project/plugins.sbt b/modules/sbt-coursier/src/sbt-test/sbt-lm-coursier/update-classifiers-1.3.0-RC1/project/plugins.sbt new file mode 100644 index 000000000..71a44ffd3 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/sbt-lm-coursier/update-classifiers-1.3.0-RC1/project/plugins.sbt @@ -0,0 +1,13 @@ +addSbtPlugin { + + val name = sys.props.getOrElse( + "plugin.name", + sys.error("plugin.name Java property not set") + ) + val version = sys.props.getOrElse( + "plugin.version", + sys.error("plugin.version Java property not set") + ) + + "io.get-coursier" % name % version +} \ No newline at end of file diff --git a/modules/sbt-lm-coursier/src/main/scala/sbt/hack/Foo.scala b/modules/sbt-lm-coursier/src/main/scala/sbt/hack/Foo.scala index b15e67b1e..c26e0da7d 100644 --- a/modules/sbt-lm-coursier/src/main/scala/sbt/hack/Foo.scala +++ b/modules/sbt-lm-coursier/src/main/scala/sbt/hack/Foo.scala @@ -50,24 +50,71 @@ object Foo { else Def.task((evictionWarningOptions in update).value) }.value - LibraryManagement.cachedUpdate( - // LM API - lm = lm, - // Ivy-free ModuleDescriptor - module = ivyModule.value, - s.cacheStoreFactory.sub(updateCacheName.value), - Reference.display(thisProjectRef.value), - updateConf, - identity, - skip = (skip in update).value, - force = shouldForce, - depsUpdated = transitiveUpdate.value.exists(!_.stats.cached), - uwConfig = (unresolvedWarningConfiguration in update).value, - ewo = evictionOptions, - mavenStyle = publishMavenStyle.value, - compatWarning = compatibilityWarningOptions.value, - log = s.log - ) + try { + LibraryManagement.cachedUpdate( + // LM API + lm = lm, + // Ivy-free ModuleDescriptor + module = ivyModule.value, + s.cacheStoreFactory.sub(updateCacheName.value), + Reference.display(thisProjectRef.value), + updateConf, + identity, + skip = (skip in update).value, + force = shouldForce, + depsUpdated = transitiveUpdate.value.exists(!_.stats.cached), + uwConfig = (unresolvedWarningConfiguration in update).value, + ewo = evictionOptions, + mavenStyle = publishMavenStyle.value, + compatWarning = compatibilityWarningOptions.value, + log = s.log + ) + } catch { + case _: NoSuchMethodError => + // cachedUpdate method changed in https://github.com/sbt/sbt/commit/6c7faf2b8611f122a37b824c6e08e950855d939f + import sbt.internal.librarymanagement.CompatibilityWarningOptions + import sbt.librarymanagement.{DependencyResolution, ModuleDescriptor, UnresolvedWarningConfiguration, UpdateConfiguration} + import sbt.util.CacheStoreFactory + LibraryManagement.asInstanceOf[{ + def cachedUpdate( + lm: DependencyResolution, + module: ModuleDescriptor, + cacheStoreFactory: CacheStoreFactory, + label: String, + updateConfig: UpdateConfiguration, + transform: UpdateReport => UpdateReport, + skip: Boolean, + force: Boolean, + depsUpdated: Boolean, + uwConfig: UnresolvedWarningConfiguration, + ewo: EvictionWarningOptions, + mavenStyle: Boolean, + compatWarning: CompatibilityWarningOptions, + includeCallers: Boolean, + includeDetails: Boolean, + log: Logger + ): UpdateReport + }].cachedUpdate( + // LM API + lm = lm, + // Ivy-free ModuleDescriptor + module = ivyModule.value, + s.cacheStoreFactory.sub(updateCacheName.value), + Reference.display(thisProjectRef.value), + updateConf, + identity, + skip = (skip in update).value, + force = shouldForce, + depsUpdated = transitiveUpdate.value.exists(!_.stats.cached), + uwConfig = (unresolvedWarningConfiguration in update).value, + ewo = evictionOptions, + mavenStyle = publishMavenStyle.value, + compatWarning = compatibilityWarningOptions.value, + includeCallers = false, + includeDetails = false, + log = s.log + ) + } } }