@@ -3,8 +3,12 @@ package com.lightbend.tools.scalamoduleplugin
33import com .typesafe .sbt .osgi .{OsgiKeys , SbtOsgi }
44import com .typesafe .tools .mima .plugin .MimaKeys ._
55import com .typesafe .tools .mima .plugin .MimaPlugin
6+
67import 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 }
812
913object ScalaModulePlugin extends AutoPlugin {
1014 val repoName = settingKey[String ](" The name of the repository under github.com/scala/." )
@@ -150,26 +154,18 @@ object ScalaModulePlugin extends AutoPlugin {
150154
151155 lazy val scalaModuleSettingsJVM : Seq [Setting [_]] = scalaModuleOsgiSettings
152156
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
154158 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 )
173169 }
174170
175171 // Internal task keys for the MiMa settings
@@ -185,10 +181,11 @@ object ScalaModulePlugin extends AutoPlugin {
185181 canRunMima := {
186182 val mimaVer = mimaPreviousVersion.value
187183 val s = streams.value
184+ val ivySbt = Keys .ivySbt.value
188185 if (mimaVer.isEmpty) {
189186 s.log.warn(" MiMa will NOT run because no mimaPreviousVersion is provided." )
190187 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)) {
192189 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). """ )
193190 false
194191 } else {
0 commit comments