@@ -3,8 +3,12 @@ package com.lightbend.tools.scalamoduleplugin
3
3
import com .typesafe .sbt .osgi .{OsgiKeys , SbtOsgi }
4
4
import com .typesafe .tools .mima .plugin .MimaKeys ._
5
5
import com .typesafe .tools .mima .plugin .MimaPlugin
6
+
6
7
import sbt .Keys ._
7
- import sbt .{Def , _ }
8
+ import sbt ._
9
+ import sbt .internal .librarymanagement .IvySbt
10
+ import sbt .librarymanagement .ivy .IvyDependencyResolution
11
+ import sbt .librarymanagement .{ UnresolvedWarningConfiguration , UpdateConfiguration }
8
12
9
13
object ScalaModulePlugin extends AutoPlugin {
10
14
val repoName = settingKey[String ](" The name of the repository under github.com/scala/." )
@@ -150,26 +154,18 @@ object ScalaModulePlugin extends AutoPlugin {
150
154
151
155
lazy val scalaModuleSettingsJVM : Seq [Setting [_]] = scalaModuleOsgiSettings
152
156
153
- // adapted from https://github.com/typesafehub /migration-manager/blob/0.1.6 /sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/SbtMima.scala#L69
157
+ // adapted from https://github.com/lightbend /migration-manager/blob/0.3.0 /sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/SbtMima.scala#L112
154
158
private def artifactExists (organization : String , name : String , scalaBinaryVersion : String , version : String , ivy : IvySbt , s : TaskStreams ): Boolean = {
155
- val moduleId = new ModuleID (organization, s " ${name}_ $scalaBinaryVersion" , version)
156
- val moduleSettings = InlineConfiguration (
157
- " dummy" % " test" % " version" ,
158
- ModuleInfo (" dummy-test-project-for-resolving" ),
159
- dependencies = Seq (moduleId))
160
- val ivyModule = new ivy.Module (moduleSettings)
161
- try {
162
- IvyActions .update(
163
- ivyModule,
164
- new UpdateConfiguration (
165
- retrieve = None ,
166
- missingOk = false ,
167
- logging = UpdateLogging .DownloadOnly ),
168
- s.log)
169
- true
170
- } catch {
171
- case _ : ResolveException => false
172
- }
159
+ val moduleId = ModuleID (organization, s " ${name}_ $scalaBinaryVersion" , version)
160
+ val depRes = IvyDependencyResolution (ivy.configuration)
161
+ val module = depRes.wrapDependencyInModule(moduleId)
162
+ val reportEither = depRes.update(
163
+ module,
164
+ UpdateConfiguration () withLogging UpdateLogging .DownloadOnly ,
165
+ UnresolvedWarningConfiguration (),
166
+ s.log
167
+ )
168
+ reportEither.fold(_ => false , _ => true )
173
169
}
174
170
175
171
// Internal task keys for the MiMa settings
@@ -185,10 +181,11 @@ object ScalaModulePlugin extends AutoPlugin {
185
181
canRunMima := {
186
182
val mimaVer = mimaPreviousVersion.value
187
183
val s = streams.value
184
+ val ivySbt = Keys .ivySbt.value
188
185
if (mimaVer.isEmpty) {
189
186
s.log.warn(" MiMa will NOT run because no mimaPreviousVersion is provided." )
190
187
false
191
- } else if (! artifactExists(organization.value, name.value, scalaBinaryVersion.value, mimaVer.get, ivySbt.value , s)) {
188
+ } else if (! artifactExists(organization.value, name.value, scalaBinaryVersion.value, mimaVer.get, ivySbt, s)) {
192
189
s.log.warn(s """ MiMa will NOT run because the previous artifact " ${organization.value}" % " ${name.value}_ ${scalaBinaryVersion.value}" % " ${mimaVer.get}" could not be resolved (note the binary Scala version). """ )
193
190
false
194
191
} else {
0 commit comments