-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathbuild.sbt
174 lines (158 loc) · 7.14 KB
/
build.sbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import lmcoursier.internal.shaded.coursier.core.Version
import xerial.sbt.Sonatype.GitHubHosting
import scala.collection.mutable
ThisBuild / organization := "org.jetbrains.scala"
ThisBuild / homepage := Some(url("https://github.com/JetBrains/sbt-structure"))
ThisBuild / licenses += ("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0"))
lazy val CommonSonatypeSettings = Seq(
sonatypeProfileName := "org.jetbrains",
sonatypeProjectHosting := Some(GitHubHosting("JetBrains", "sbt-structure", "[email protected]"))
)
lazy val sbtStructure = project.in(file("."))
.aggregate(core, extractor, extractorLegacy_013)
.settings(
name := "sbt-structure",
CommonSonatypeSettings,
// disable publishing in the root project
publish / skip := true,
crossScalaVersions := List.empty,
crossSbtVersions := List.empty,
sonatypePublishTo := None
)
//NOTE: an extra scala 2.12 version is used just to distinguish between different sbt 1.x versions
// when calculating pluginCrossBuild / sbtVersion
val scala212_Earlier: String = "2.12.19" //used for sbt < 1.3
val scala212: String = "2.12.20" //used for sbt >= 1.3
val scala3: String = "3.6.2" //used for sbt 2
val Scala_2_10_Legacy = "2.10.7"
val SbtVersion_1_0 = "1.0.0"
val SbtVersion_1_3 = "1.3.0"
val SbtVersion_2 = "2.0.0-M3"
val SbtVersion_0_13_Legacy = "0.13.17"
val CommonSharedCoreDataSourcesSettings: Seq[Def.Setting[Seq[File]]] = Seq(
Compile / unmanagedSourceDirectories +=
(ThisBuild / baseDirectory).value / "shared" / "src" / "main" / "scala",
)
lazy val core = project.in(file("core"))
.settings(
name := "sbt-structure-core",
CommonSonatypeSettings,
libraryDependencies ++= {
val scalaVersion = Version(scalaBinaryVersion.value)
if (scalaVersion >= Version("2.12"))
Seq("org.scala-lang.modules" %% "scala-xml" % "2.3.0")
else
Nil
},
crossScalaVersions := Seq("2.13.16", scala212),
CommonSharedCoreDataSourcesSettings,
)
lazy val extractor = project.in(file("extractor"))
.enablePlugins(SbtPlugin)
.settings(
name := "sbt-structure-extractor",
CommonSonatypeSettings,
scalacOptions ++= Seq("-deprecation", "-feature") ++ {
// Mute some warnings
// We have to use some deprecated things because we cross-compile for 2.10, 2.12 and 3.x
if (scalaBinaryVersion.value.startsWith("3")) {
val patterns = Seq(
"""msg=(?s)`_` is deprecated for wildcard arguments of types. use `\?` instead.*:silent""",
"""msg=(?s)method mapValues in trait MapOps is deprecated since 2.13.0.*:silent""",
"""msg=.*is no longer supported for vararg splices.*:silent""",
"""msg=method toIterable in class IterableOnceExtensionMethods is deprecated since 2.13.0.*:silent""",
"""msg=method right in class Either is deprecated since 2.13.0.*:silent""",
"""msg=method get in class RightProjection is deprecated since 2.13.0.*:silent""",
"""msg=object JavaConverters in package scala.collection is deprecated since 2.13.0.*:silent""",
// We have to use IntegrationTest to support older sbt versions
"""msg=value IntegrationTest in trait LibraryManagementSyntax is deprecated since 1.9.0.*:silent""",
)
Seq(s"-Wconf:${patterns.mkString(",")}")
} else
Seq.empty
},
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.2.19" % Test,
"org.dom4j" % "dom4j" % "2.1.4" % Test
),
scalaVersion := scala212,
// scalaVersion := scala3,
crossScalaVersions := Seq(
scala212_Earlier,
scala212,
scala3,
),
crossSbtVersions := Seq(
SbtVersion_1_0,
SbtVersion_1_3,
SbtVersion_2
),
pluginCrossBuild / sbtVersion := {
// keep this as low as possible to avoid running into binary incompatibility such as https://github.com/sbt/sbt/issues/5049
val scalaVer = scalaVersion.value
if (scalaVer == scala212_Earlier)
SbtVersion_1_0
else if (scalaVer == scala212)
SbtVersion_1_3
else if (scalaVer == scala3)
SbtVersion_2
else
throw new AssertionError(s"Unexpected scala version $scalaVer")
},
// By default, when you crosscompile sbt plugin for multiple sbt 1.x versions,
// it will use the same binary version 1.0 for all of them
// It will use the same source directory `scala-sbt-1.0`, same target dirs and same artifact names.
// But we need different directories because some code compiles in sbt 1.x but not in sbt 1.y
pluginCrossBuild / sbtBinaryVersion := {
val sbtVersion3Digits = (pluginCrossBuild / sbtVersion).value
val sbtVersion2Digits = sbtVersion3Digits.substring(0, sbtVersion3Digits.lastIndexOf("."))
sbtVersion2Digits
},
Compile / unmanagedSourceDirectories ++= {
val sbtVersion = Version((pluginCrossBuild / sbtBinaryVersion).value)
val baseDir = (Compile / sourceDirectory).value
val result = mutable.Buffer[File]()
if (sbtVersion.repr.startsWith("1"))
result += baseDir / "scala-sbt-1.0-1.x"
if (sbtVersion >= Version("1.3"))
result += baseDir / "scala-sbt-1.3+"
result
},
CommonSharedCoreDataSourcesSettings,
// We only run tests in Scala 2.
// This is done to avoid cross-compilation for test sources, which would introduce some redundant burden.
// TODO: ensure CI is updated (TeamCity & GitHub)
Test / unmanagedSourceDirectories := {
if (scalaVersion.value.startsWith("2"))
(Test / unmanagedSourceDirectories).value
else
Nil
},
)
// We use separate module for 0.13 with many sources duplicated as an alternative to cross-compilation.
// Such an approach should be easier than cross-compiling against 0.13, 1.0, 1.2, 2.x.
// Trying to cross-compile between 3 major versions of sbt (and thus scala 2.10, 2.12, 3.x) is very fragile
lazy val extractorLegacy_013 = project.in(file("extractor-legacy-0.13"))
.enablePlugins(SbtPlugin)
.settings(
name := "sbt-structure-extractor-legacy-0.13",
// NOTE: use the same module name for 0.13 when publishing.
// We have to do this explicitly because we extracted the 0.13 code to a separate project with a different name
// which is used as the module name by default.
moduleName := (extractor / Keys.moduleName).value,
CommonSonatypeSettings,
scalaVersion := Scala_2_10_Legacy,
crossScalaVersions := Seq(Scala_2_10_Legacy),
crossSbtVersions := Seq(SbtVersion_0_13_Legacy),
pluginCrossBuild / sbtVersion := SbtVersion_0_13_Legacy,
CommonSharedCoreDataSourcesSettings,
)
val publishCoreCommand =
"; project core ; ci-release"
val publishExtractorCommand =
"; project extractor ; ci-release ; project extractorLegacy_013 ; ci-release"
// the ^ sbt-cross operator doesn't work that well for publishing, so we need to be more explicit about the command chain
addCommandAlias("publishCore", publishCoreCommand)
addCommandAlias("publishExtractor", publishExtractorCommand)
// note: we can only run tests for Scala 2 (see comments in extractor module)
addCommandAlias("crossCompileAndRunTests", s"""; +compile ; project extractor ; set scalaVersion := "$scala212" ; test""")