11package com .lightbend .tools .scalamoduleplugin
22
33import com .typesafe .sbt .osgi .{OsgiKeys , SbtOsgi }
4- import com .typesafe .tools .mima .plugin .MimaKeys ._
5- import com .typesafe .tools .mima .plugin .MimaPlugin
64import de .heikoseeberger .sbtheader .HeaderPlugin .autoImport .{HeaderLicense , headerLicense }
75import sbt .Keys ._
8- import sbt ._
9- import sbt .internal .librarymanagement .IvySbt
10- import sbt .librarymanagement .ivy .IvyDependencyResolution
11- import sbt .librarymanagement .{UnresolvedWarningConfiguration , UpdateConfiguration }
6+ import sbt .{Def , _ }
127import sbtdynver .DynVerPlugin
138import sbtdynver .DynVerPlugin .autoImport .dynverGitDescribeOutput
149import xerial .sbt .Sonatype .autoImport .{sonatypeProfileName , sonatypeSessionName }
10+ import sbtversionpolicy .SbtVersionPolicyPlugin .autoImport .{Compatibility , versionPolicyCheck , versionPolicyIgnoredInternalDependencyVersions , versionPolicyIntention }
1511
1612object ScalaModulePlugin extends AutoPlugin {
1713 object autoImport {
1814 val scalaModuleRepoName = settingKey[String ](" The name of the repository under github.com/scala/." )
1915 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" )
2017 val scalaModuleMimaPreviousVersion = settingKey[Option [String ]](" The version of this module to compare against when running MiMa." )
2118 val scalaModuleEnableOptimizerInlineFrom = settingKey[String ](" The value passed to -opt-inline-from by `enableOptimizer` on 2.13 and higher." )
2219 }
@@ -36,7 +33,7 @@ object ScalaModulePlugin extends AutoPlugin {
3633 dv.copy(ref = sbtdynver.GitRef (dv.ref.value.split('#' ).head)))),
3734 )
3835
39- // Settings added to the global scope
36+ // Settings added to the project scope
4037 override def projectSettings : Seq [Setting [_]] = Seq (
4138 // The staging profile is called `org.scala-lang`, the default is `org.scala-lang.modules`
4239 sonatypeProfileName := " org.scala-lang" ,
@@ -53,6 +50,12 @@ object ScalaModulePlugin extends AutoPlugin {
5350 },
5451 )
5552
53+ // Global settings
54+ override def globalSettings : Seq [Def .Setting [_]] = Seq (
55+ // Since we use sbt-dynver, see https://github.com/scalacenter/sbt-version-policy#how-to-integrate-with-sbt-dynver
56+ versionPolicyIgnoredInternalDependencyVersions := Some (" ^\\ d+\\ .\\ d+\\ .\\ d+\\ +\\ d+" .r)
57+ )
58+
5659 /**
5760 * Enable `-opt:l:inline`, `-opt:l:project` or `-optimize`, depending on the scala version.
5861 */
@@ -167,47 +170,21 @@ object ScalaModulePlugin extends AutoPlugin {
167170 // a setting-transform to turn the regular version into something osgi can deal with
168171 private val osgiVersion = version(_.replace('-' , '.' ))
169172
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." )
173+ // Internal task keys for the versionPolicy settings
174+ private val runVersionPolicyCheckIfEnabled = taskKey[Unit ](" Run versionPolicyCheck if versionPolicyIntention is not set to Compatibility.None." )
183175
184176 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- },
177+ versionPolicyIntention := Compatibility .None ,
203178
204- runMimaIfEnabled := Def .taskDyn({
205- if (canRunMima.value) Def .task { mimaReportBinaryIssues.value }
206- else Def .task { () }
179+ runVersionPolicyCheckIfEnabled := Def .taskDyn({
180+ if (versionPolicyIntention.value != Compatibility .None ) Def .task { versionPolicyCheck.value }
181+ else Def .task {
182+ streams.value.log.warn(" versionPolicyCheck will NOT run because versionPolicyIntention is set to Compatibility.None." )
183+ }
207184 }).value,
208185
209186 Test / test := {
210- runMimaIfEnabled .value
187+ runVersionPolicyCheckIfEnabled .value
211188 (Test / test).value
212189 }
213190 )
0 commit comments