@@ -22,7 +22,10 @@ lazy val sbtStructure = project.in(file("."))
2222 )
2323
2424val scala210 : String = " 2.10.7"
25- val scala212 : String = " 2.12.17"
25+ // NOTE: extra scala 2.12 version is used just to distinguish between different sbt 1.x versions
26+ // when calculating pluginCrossBuild / sbtVersion
27+ val scala212_6 : String = " 2.12.6" // used for sbt < 1.3
28+ val scala212 : String = " 2.12.18" // used for sbt >= 1.3
2629
2730lazy val core = project.in(file(" core" ))
2831 .settings(
@@ -43,6 +46,10 @@ lazy val core = project.in(file("core"))
4346 sonatypeSettings
4447 )
4548
49+ val SbtVersion_0_13 = " 0.13.17"
50+ val SbtVersion_1_2 = " 1.2.1"
51+ val SbtVersion_1_3 = " 1.3.0"
52+
4653lazy val extractor = project.in(file(" extractor" ))
4754 .enablePlugins(SbtPlugin , TestDataDumper )
4855 .settings(
@@ -51,12 +58,42 @@ lazy val extractor = project.in(file("extractor"))
5158 (ThisBuild / baseDirectory).value / " shared" / " src" / " main" / " scala" ,
5259 scalacOptions ++= Seq (" -deprecation" ),
5360 libraryDependencies += " org.scalatest" %% " scalatest" % " 3.2.15" % Test ,
54- crossScalaVersions := Seq (scala212, scala210),
61+ scalaVersion := scala212,
62+ crossScalaVersions := Seq (
63+ scala212,
64+ scala212_6,
65+ scala210
66+ ),
67+ crossSbtVersions := Seq (
68+ SbtVersion_0_13 ,
69+ SbtVersion_1_2 ,
70+ SbtVersion_1_3 ,
71+ ),
5572 pluginCrossBuild / sbtVersion := {
5673 // keep this as low as possible to avoid running into binary incompatibility such as https://github.com/sbt/sbt/issues/5049
57- scalaBinaryVersion.value match {
58- case " 2.10" => " 0.13.17"
59- case " 2.12" => " 1.2.1"
74+ val scalaVer = scalaVersion.value
75+ if (scalaBinaryVersion.value == " 2.10" )
76+ SbtVersion_0_13
77+ else if (scalaVer == scala212_6)
78+ SbtVersion_1_2
79+ else if (scalaVer == scala212)
80+ SbtVersion_1_3
81+ else
82+ throw new AssertionError (s " Unexpected scala version $scalaVer" )
83+ },
84+ // By default when you crosscompile sbt plugin for multiple sbt 1.x versions it will use same binary version 1.0 for all of them
85+ // It will use the same source directory `scala-sbt-1.0`, same target dirs, same artifact names
86+ // But we need different directories because some code compiles in sbt 1.x but not in sbt 1.y
87+ pluginCrossBuild / sbtBinaryVersion := {
88+ val sbtVersion3Digits = (pluginCrossBuild / sbtVersion).value
89+ val sbtVersion2Digits = sbtVersion3Digits.substring(0 , sbtVersion3Digits.lastIndexOf(" ." ))
90+ sbtVersion2Digits
91+ },
92+ Compile / unmanagedSourceDirectories ++= {
93+ val sbtBinVer = (pluginCrossBuild / sbtBinaryVersion).value
94+ if (sbtBinVer.startsWith(" 0" )) Nil else {
95+ val baseDir = (Compile / sourceDirectory).value
96+ Seq (baseDir / " scala-sbt-1.x" ) // shared source dir for all sbt 1.x
6097 }
6198 },
6299 sonatypeSettings
0 commit comments