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
- import sbt ._
9
- import sbt .internal .librarymanagement .IvySbt
10
- import sbt .librarymanagement .ivy .IvyDependencyResolution
11
- import sbt .librarymanagement .{UnresolvedWarningConfiguration , UpdateConfiguration }
6
+ import sbt .{Def , _ }
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 , versionPolicyIgnoredInternalDependencyVersions , 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
}
@@ -36,7 +33,7 @@ object ScalaModulePlugin extends AutoPlugin {
36
33
dv.copy(ref = sbtdynver.GitRef (dv.ref.value.split('#' ).head)))),
37
34
)
38
35
39
- // Settings added to the global scope
36
+ // Settings added to the project scope
40
37
override def projectSettings : Seq [Setting [_]] = Seq (
41
38
// The staging profile is called `org.scala-lang`, the default is `org.scala-lang.modules`
42
39
sonatypeProfileName := " org.scala-lang" ,
@@ -53,6 +50,12 @@ object ScalaModulePlugin extends AutoPlugin {
53
50
},
54
51
)
55
52
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
+
56
59
/**
57
60
* Enable `-opt:l:inline`, `-opt:l:project` or `-optimize`, depending on the scala version.
58
61
*/
@@ -167,47 +170,21 @@ object ScalaModulePlugin extends AutoPlugin {
167
170
// a setting-transform to turn the regular version into something osgi can deal with
168
171
private val osgiVersion = version(_.replace('-' , '.' ))
169
172
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." )
183
175
184
176
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 ,
203
178
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
+ }
207
184
}).value,
208
185
209
186
Test / test := {
210
- runMimaIfEnabled .value
187
+ runVersionPolicyCheckIfEnabled .value
211
188
(Test / test).value
212
189
}
213
190
)
0 commit comments