-
-
Notifications
You must be signed in to change notification settings - Fork 108
/
build.sbt
232 lines (212 loc) · 7.97 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
// Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com>
import Dependencies._
import sbtcrossproject.CrossPlugin.autoImport.crossProject
import org.scalajs.jsenv.nodejs.NodeJSEnv
import java.util.Properties
import java.io.StringWriter
val ScalaTestVersion = "3.2.19"
def parserCombinators(scalaVersion: String) = "org.scala-lang.modules" %% "scala-parser-combinators" % {
CrossVersion.partialVersion(scalaVersion) match {
case Some((2, _)) => "1.1.2"
case _ => "2.4.0"
}
}
val previousVersion: Option[String] = Some("2.0.1")
val mimaSettings = Seq(
mimaPreviousArtifacts := previousVersion.map(organization.value %% moduleName.value % _).toSet,
mimaBinaryIssueFilters ++= Seq(
)
)
// Customise sbt-dynver's behaviour to make it work with tags which aren't v-prefixed
ThisBuild / dynverVTagPrefix := false
// Sanity-check: assert that version comes from a tag (e.g. not a too-shallow clone)
// https://github.com/dwijnand/sbt-dynver/#sanity-checking-the-version
Global / onLoad := (Global / onLoad).value.andThen { s =>
dynverAssertTagVersion.value
s
}
lazy val twirl = project
.in(file("."))
.disablePlugins(MimaPlugin)
.settings(
sonatypeProfileName := "org.playframework",
crossScalaVersions := Nil, // workaround so + uses project-defined variants
publish / skip := true,
(Compile / headerSources) ++=
((baseDirectory.value ** ("*.properties" || "*.md" || "*.sbt" || "*.scala.html"))
--- (baseDirectory.value ** "target" ** "*")
--- (baseDirectory.value / "compiler" / "version.properties")
--- (baseDirectory.value ** "gradle-twirl" ** "*") // Gradle Spotless plugin is used
--- (baseDirectory.value / "docs" ** "*")).get ++
(baseDirectory.value / "project" ** "*.scala" --- (baseDirectory.value ** "target" ** "*")).get
)
.aggregate(apiJvm, apiJs, parser, compiler, plugin, mavenPlugin)
lazy val nodeJs = {
if (System.getProperty("NODE_PATH") != null)
new NodeJSEnv(NodeJSEnv.Config().withExecutable(System.getProperty("NODE_PATH")))
else
new NodeJSEnv()
}
lazy val api = crossProject(JVMPlatform, JSPlatform)
.in(file("api"))
.enablePlugins(Common, Playdoc, Omnidoc)
.configs(Docs)
.settings(
sonatypeProfileName := "org.playframework",
scalaVersion := Scala212,
crossScalaVersions := ScalaVersions,
mimaSettings,
name := "twirl-api",
jsEnv := nodeJs,
// hack for GraalVM, see: https://github.com/scala-js/scala-js/issues/3673
// and https://github.com/playframework/twirl/pull/339
testFrameworks := List(
new TestFramework(
"org.scalatest.tools.Framework",
"org.scalatest.tools.ScalaTestFramework"
)
),
libraryDependencies += "org.scala-lang.modules" %%% "scala-xml" % "2.3.0",
libraryDependencies += "org.scalatest" %%% "scalatest" % ScalaTestVersion % Test,
)
lazy val apiJvm = api.jvm
lazy val apiJs = api.js
lazy val parser = project
.in(file("parser"))
.enablePlugins(Common, Omnidoc)
.settings(
sonatypeProfileName := "org.playframework",
scalaVersion := Scala212,
crossScalaVersions := ScalaVersions,
mimaSettings,
name := "twirl-parser",
libraryDependencies += parserCombinators(scalaVersion.value),
libraryDependencies += "com.github.sbt" % "junit-interface" % "0.13.3" % Test,
libraryDependencies += "org.scalatest" %%% "scalatest" % ScalaTestVersion % Test,
)
lazy val compiler = project
.in(file("compiler"))
.enablePlugins(Common, Omnidoc, BuildInfoPlugin)
.settings(
sonatypeProfileName := "org.playframework",
scalaVersion := Scala212,
crossScalaVersions := ScalaVersions,
mimaSettings,
name := "twirl-compiler",
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, _)) =>
// only for scala < 3
Seq("org.scala-lang" % "scala-compiler" % scalaVersion.value % Test)
case _ => Seq("org.scala-lang" %% "scala3-compiler" % scalaVersion.value % Test)
}
},
libraryDependencies += parserCombinators(scalaVersion.value),
libraryDependencies += ("org.scalameta" %% "parsers" % "4.11.0").cross(CrossVersion.for3Use2_13),
run / fork := true,
buildInfoKeys := Seq[BuildInfoKey](scalaVersion),
buildInfoPackage := "play.twirl.compiler",
publishM2 := publishM2.dependsOn(saveCompilerVersion).value,
publish := publish.dependsOn(saveCompilerVersion).value,
publishLocal := publishLocal.dependsOn(saveCompilerVersion).value
)
.aggregate(parser)
.dependsOn(apiJvm % Test, parser % "compile->compile;test->test")
lazy val plugin = project
.in(file("sbt-twirl"))
.enablePlugins(SbtPlugin)
.dependsOn(compiler)
.settings(
name := "sbt-twirl",
organization := "org.playframework.twirl",
sonatypeProfileName := "org.playframework",
scalaVersion := Scala212,
libraryDependencies += "org.scalatest" %%% "scalatest" % ScalaTestVersion % Test,
crossScalaVersions += Scala3,
pluginCrossBuild / sbtVersion := {
scalaBinaryVersion.value match {
case "2.12" =>
sbtVersion.value
case _ =>
"2.0.0-M2"
}
},
Compile / resourceGenerators += generateVersionFile.taskValue,
scriptedLaunchOpts += version.apply { v => s"-Dproject.version=$v" }.value,
// both `locally`s are to work around sbt/sbt#6161
scriptedDependencies := {
locally { val _ = scriptedDependencies.value }
locally {
val _ = publishLocal
.all(
ScopeFilter(
inAnyProject
)
)
.value
}
()
},
mimaFailOnNoPrevious := false
)
lazy val mavenPlugin = project
.in(file("maven-twirl"))
.enablePlugins(SbtMavenPlugin)
.dependsOn(compiler)
.settings(
name := "twirl-maven-plugin",
sonatypeProfileName := "org.playframework",
scalaVersion := Scala212,
crossScalaVersions := ScalaVersions,
mavenPluginGoalPrefix := "twirl",
mavenLaunchOpts ++= Seq(
// Uncomment to debug plugin code while Maven scripted test is running
// "-agentlib:jdwp=transport=dt_socket,address=localhost:62555,suspend=y,server=y",
version.apply { v => s"-Dplugin.version=$v" }.value,
scalaVersion.apply { v => s"-Dscala.binaryVersion=${CrossVersion.binaryScalaVersion(v)}" }.value
),
publishM2 := publishM2
.dependsOn(compiler / publishM2)
.dependsOn(parser / publishM2)
.dependsOn(apiJvm / publishM2)
.value,
libraryDependencies += "org.codehaus.plexus" % "plexus-utils" % "4.0.2",
Compile / headerSources ++= (baseDirectory.value / "src" / "maven-test" ** ("*.java" || "*.scala" || "*.scala.html") --- (baseDirectory.value ** "target" ** "*")).get,
mimaFailOnNoPrevious := false,
)
// Version file
def generateVersionFile =
Def.task {
val version = (apiJvm / Keys.version).value
val file = (Compile / resourceManaged).value / "twirl.version.properties"
val content = s"twirl.api.version=$version"
IO.write(file, content)
Seq(file)
}
def saveCompilerVersion =
Def.task {
val props = new Properties()
val writer = new StringWriter()
val file = baseDirectory.value / "version.properties"
props.setProperty("twirl.compiler.version", version.value)
props.store(writer, "")
IO.write(file, writer.getBuffer.toString)
Seq(file)
}
addCommandAlias(
"validateCode",
List(
"headerCheckAll",
"scalafmtSbtCheck",
"scalafmtCheckAll",
"javafmtCheckAll",
).mkString(";")
)
addCommandAlias(
"format",
List(
"scalafmtSbt",
"scalafmtAll",
"javafmtAll",
).mkString(";")
)