Skip to content

Commit 4a27bd4

Browse files
Fix NoSuchMethodError when using coursier-based sbt launcher (#104)
1 parent df3d5c6 commit 4a27bd4

File tree

5 files changed

+85
-18
lines changed

5 files changed

+85
-18
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
scalaVersion := "2.13.0"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# currently, the coursier-based sbt launcher starts sbt in the scripted tests
2+
# without the coursier sbt plugins. This pulls the lm-coursier-shaded version
3+
# that sbt depends on, which lacks some methods
4+
> updateClassifiers
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# testing regression since this sbt version
2+
sbt.version=1.3.0-RC1
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
addSbtPlugin {
2+
3+
val name = sys.props.getOrElse(
4+
"plugin.name",
5+
sys.error("plugin.name Java property not set")
6+
)
7+
val version = sys.props.getOrElse(
8+
"plugin.version",
9+
sys.error("plugin.version Java property not set")
10+
)
11+
12+
"io.get-coursier" % name % version
13+
}

modules/sbt-lm-coursier/src/main/scala/sbt/hack/Foo.scala

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,71 @@ object Foo {
5050
else Def.task((evictionWarningOptions in update).value)
5151
}.value
5252

53-
LibraryManagement.cachedUpdate(
54-
// LM API
55-
lm = lm,
56-
// Ivy-free ModuleDescriptor
57-
module = ivyModule.value,
58-
s.cacheStoreFactory.sub(updateCacheName.value),
59-
Reference.display(thisProjectRef.value),
60-
updateConf,
61-
identity,
62-
skip = (skip in update).value,
63-
force = shouldForce,
64-
depsUpdated = transitiveUpdate.value.exists(!_.stats.cached),
65-
uwConfig = (unresolvedWarningConfiguration in update).value,
66-
ewo = evictionOptions,
67-
mavenStyle = publishMavenStyle.value,
68-
compatWarning = compatibilityWarningOptions.value,
69-
log = s.log
70-
)
53+
try {
54+
LibraryManagement.cachedUpdate(
55+
// LM API
56+
lm = lm,
57+
// Ivy-free ModuleDescriptor
58+
module = ivyModule.value,
59+
s.cacheStoreFactory.sub(updateCacheName.value),
60+
Reference.display(thisProjectRef.value),
61+
updateConf,
62+
identity,
63+
skip = (skip in update).value,
64+
force = shouldForce,
65+
depsUpdated = transitiveUpdate.value.exists(!_.stats.cached),
66+
uwConfig = (unresolvedWarningConfiguration in update).value,
67+
ewo = evictionOptions,
68+
mavenStyle = publishMavenStyle.value,
69+
compatWarning = compatibilityWarningOptions.value,
70+
log = s.log
71+
)
72+
} catch {
73+
case _: NoSuchMethodError =>
74+
// cachedUpdate method changed in https://github.com/sbt/sbt/commit/6c7faf2b8611f122a37b824c6e08e950855d939f
75+
import sbt.internal.librarymanagement.CompatibilityWarningOptions
76+
import sbt.librarymanagement.{DependencyResolution, ModuleDescriptor, UnresolvedWarningConfiguration, UpdateConfiguration}
77+
import sbt.util.CacheStoreFactory
78+
LibraryManagement.asInstanceOf[{
79+
def cachedUpdate(
80+
lm: DependencyResolution,
81+
module: ModuleDescriptor,
82+
cacheStoreFactory: CacheStoreFactory,
83+
label: String,
84+
updateConfig: UpdateConfiguration,
85+
transform: UpdateReport => UpdateReport,
86+
skip: Boolean,
87+
force: Boolean,
88+
depsUpdated: Boolean,
89+
uwConfig: UnresolvedWarningConfiguration,
90+
ewo: EvictionWarningOptions,
91+
mavenStyle: Boolean,
92+
compatWarning: CompatibilityWarningOptions,
93+
includeCallers: Boolean,
94+
includeDetails: Boolean,
95+
log: Logger
96+
): UpdateReport
97+
}].cachedUpdate(
98+
// LM API
99+
lm = lm,
100+
// Ivy-free ModuleDescriptor
101+
module = ivyModule.value,
102+
s.cacheStoreFactory.sub(updateCacheName.value),
103+
Reference.display(thisProjectRef.value),
104+
updateConf,
105+
identity,
106+
skip = (skip in update).value,
107+
force = shouldForce,
108+
depsUpdated = transitiveUpdate.value.exists(!_.stats.cached),
109+
uwConfig = (unresolvedWarningConfiguration in update).value,
110+
ewo = evictionOptions,
111+
mavenStyle = publishMavenStyle.value,
112+
compatWarning = compatibilityWarningOptions.value,
113+
includeCallers = false,
114+
includeDetails = false,
115+
log = s.log
116+
)
117+
}
71118
}
72119

73120
}

0 commit comments

Comments
 (0)