|
1 | 1 | package com.lightbend.tools.scalamoduleplugin
|
2 | 2 |
|
3 | 3 | import com.typesafe.sbt.osgi.{OsgiKeys, SbtOsgi}
|
4 |
| -import com.typesafe.tools.mima.plugin.MimaKeys._ |
5 |
| -import com.typesafe.tools.mima.plugin.MimaPlugin |
6 | 4 | import de.heikoseeberger.sbtheader.HeaderPlugin.autoImport.{HeaderLicense, headerLicense}
|
7 | 5 | import sbt.Keys._
|
8 | 6 | import sbt._
|
9 |
| -import sbt.internal.librarymanagement.IvySbt |
10 |
| -import sbt.librarymanagement.ivy.IvyDependencyResolution |
11 |
| -import sbt.librarymanagement.{UnresolvedWarningConfiguration, UpdateConfiguration} |
12 | 7 | import sbtdynver.DynVerPlugin
|
13 | 8 | import sbtdynver.DynVerPlugin.autoImport.dynverGitDescribeOutput
|
14 | 9 | import xerial.sbt.Sonatype.autoImport.{sonatypeProfileName, sonatypeSessionName}
|
| 10 | +import sbtversionpolicy.SbtVersionPolicyPlugin.autoImport.{Compatibility, versionPolicyCheck, versionPolicyIntention} |
15 | 11 |
|
16 | 12 | object ScalaModulePlugin extends AutoPlugin {
|
17 | 13 | object autoImport {
|
18 | 14 | val scalaModuleRepoName = settingKey[String]("The name of the repository under github.com/scala/.")
|
19 | 15 | val scalaModuleAutomaticModuleName = settingKey[Option[String]]("Automatic-Module-Name setting for manifest")
|
| 16 | + @deprecated("Previous version is now automatically computed by sbt-version-policy. Setting this key has no effect", "2.4.0") |
20 | 17 | val scalaModuleMimaPreviousVersion = settingKey[Option[String]]("The version of this module to compare against when running MiMa.")
|
21 | 18 | val scalaModuleEnableOptimizerInlineFrom = settingKey[String]("The value passed to -opt-inline-from by `enableOptimizer` on 2.13 and higher.")
|
22 | 19 | }
|
@@ -167,47 +164,21 @@ object ScalaModulePlugin extends AutoPlugin {
|
167 | 164 | // a setting-transform to turn the regular version into something osgi can deal with
|
168 | 165 | private val osgiVersion = version(_.replace('-', '.'))
|
169 | 166 |
|
170 |
| - // adapted from https://github.com/lightbend/migration-manager/blob/0.3.0/sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/SbtMima.scala#L112 |
171 |
| - private def artifactExists(organization: String, name: String, scalaBinaryVersion: String, version: String, ivy: IvySbt, s: TaskStreams): Boolean = { |
172 |
| - val moduleId = ModuleID(organization, s"${name}_$scalaBinaryVersion", version) |
173 |
| - val depRes = IvyDependencyResolution(ivy.configuration) |
174 |
| - val module = depRes.wrapDependencyInModule(moduleId) |
175 |
| - val updateConf = UpdateConfiguration() withLogging UpdateLogging.DownloadOnly |
176 |
| - val reportEither = depRes.update(module, updateConf, UnresolvedWarningConfiguration(), s.log) |
177 |
| - reportEither.fold(_ => false, _ => true) |
178 |
| - } |
179 |
| - |
180 |
| - // Internal task keys for the MiMa settings |
181 |
| - private val canRunMima = taskKey[Boolean]("Decides if MiMa should run.") |
182 |
| - private val runMimaIfEnabled = taskKey[Unit]("Run MiMa if mimaPreviousVersion and the module can be resolved against the current scalaBinaryVersion.") |
| 167 | + // Internal task keys for the versionPolicy settings |
| 168 | + private val runVersionPolicyCheckIfEnabled = taskKey[Unit]("Run versionPolicyCheck if versionPolicyIntention is not set to Compatibility.None.") |
183 | 169 |
|
184 | 170 | private lazy val mimaSettings: Seq[Setting[_]] = Seq(
|
185 |
| - scalaModuleMimaPreviousVersion := None, |
186 |
| - |
187 |
| - // We're not using `%%` here in order to support both jvm and js projects (cross version `_2.12` / `_sjs0.6_2.12`) |
188 |
| - mimaPreviousArtifacts := scalaModuleMimaPreviousVersion.value.map(v => organization.value % moduleName.value % v cross crossVersion.value).toSet, |
189 |
| - |
190 |
| - canRunMima := { |
191 |
| - val log = streams.value.log |
192 |
| - scalaModuleMimaPreviousVersion.value match { |
193 |
| - case None => |
194 |
| - log.warn("MiMa will NOT run because no mimaPreviousVersion is provided.") |
195 |
| - false |
196 |
| - case Some(mimaVer) => |
197 |
| - val exists = artifactExists(organization.value, name.value, scalaBinaryVersion.value, mimaVer, ivySbt.value, streams.value) |
198 |
| - if (!exists) |
199 |
| - log.warn(s"""MiMa will NOT run because the previous artifact "${organization.value}" % "${name.value}_${scalaBinaryVersion.value}" % "$mimaVer" could not be resolved (note the binary Scala version).""") |
200 |
| - exists |
201 |
| - } |
202 |
| - }, |
| 171 | + versionPolicyIntention := Compatibility.None, |
203 | 172 |
|
204 |
| - runMimaIfEnabled := Def.taskDyn({ |
205 |
| - if (canRunMima.value) Def.task { mimaReportBinaryIssues.value } |
206 |
| - else Def.task { () } |
| 173 | + runVersionPolicyCheckIfEnabled := Def.taskDyn({ |
| 174 | + if (versionPolicyIntention.value != Compatibility.None) Def.task { versionPolicyCheck.value } |
| 175 | + else Def.task { |
| 176 | + streams.value.log.warn("versionPolicyCheck will NOT run because versionPolicyIntention is set to Compatibility.None.") |
| 177 | + } |
207 | 178 | }).value,
|
208 | 179 |
|
209 | 180 | Test / test := {
|
210 |
| - runMimaIfEnabled.value |
| 181 | + runVersionPolicyCheckIfEnabled.value |
211 | 182 | (Test / test).value
|
212 | 183 | }
|
213 | 184 | )
|
|
0 commit comments