-
Notifications
You must be signed in to change notification settings - Fork 148
/
build.sbt
192 lines (180 loc) · 6.15 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
import com.typesafe.sbt.SbtScalariform.ScalariformKeys
import scalariform.formatter.preferences._
import scala.sys.process._
import sbt.io.Using
lazy val commonSettings = inConfig(Test)(Defaults.testSettings) ++
Seq(
organization := "org.scalariform",
sonatypeProfileName := organization.value,
scalaVersion := crossScalaVersions.value.head,
crossScalaVersions := Seq(
"2.13.0",
"2.12.8",
"2.11.12",
"2.10.7"
),
scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, major)) if major >= 12 => Seq(
"-Xlint:-unused,_", "-Ywarn-unused:imports",
"-language:postfixOps", "-language:implicitConversions",
"-deprecation", "-feature"
)
case Some((2, major)) if major >= 11 =>
scalac2_10Options ++ scalac2_11Options
case _ =>
scalac2_10Options
}),
credentials ++= {
val creds = Path.userHome / ".m2" / "credentials"
if (creds.exists) Seq(Credentials(creds)) else Nil
}
)
def scalac2_10Options = Seq(
"-encoding", "UTF-8",
"-feature",
"-language:_",
"-unchecked",
"-Xlint",
"-Xfuture",
"-Yno-adapted-args",
"-Ywarn-dead-code"
)
def scalac2_11Options = Seq(
"-deprecation:false",
"-Xlint",
"-Xfatal-warnings",
"-Ywarn-unused-import"
)
def publishSettings(projectName: String) = Seq(
pomExtra := pomExtraXml,
publishMavenStyle := true,
publishArtifact in Test := false,
publishArtifact in (Compile, packageDoc) := true,
publishArtifact in (Compile, packageSrc) := true,
pomIncludeRepository := { _ ⇒ false },
buildInfoKeys := Seq[BuildInfoKey](version),
buildInfoPackage := projectName,
publishTo := getPublishToRepo.value
)
def getPublishToRepo = Def.setting {
if (isSnapshot.value)
Some(Opts.resolver.sonatypeSnapshots)
else
Some(Opts.resolver.sonatypeStaging)
}
def subprojectSettings(projectName: String) = commonSettings ++ Seq(
ScalariformKeys.preferences := PreferencesImporterExporter.loadPreferences(
(baseDirectory.value / ".." / "formatterPreferences.properties").getPath)
)
def scala2_11Dependencies = Def.setting {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, major)) if major >= 11 =>
val parserV = if (major == 11) "1.1.1" else "1.1.2" // cf https://github.com/scala/scala-parser-combinators/issues/197
Seq(
"org.scala-lang.modules" %% "scala-xml" % "1.2.0",
"org.scala-lang.modules" %% "scala-parser-combinators" % parserV
)
case _ => Nil
}
}
lazy val scalariform = (project
enablePlugins(BuildInfoPlugin)
settings(subprojectSettings("scalariform"))
settings(publishSettings("scalariform"))
settings(
libraryDependencies ++= scala2_11Dependencies.value,
libraryDependencies += "org.scalatest" %% "scalatest" % "3.1.0-SNAP13" % Test,
// sbt doesn't automatically load the content of the MANIFST.MF file, therefore
// we have to do it here by ourselves. Furthermore, the version format in the
// MANIFEST.MF is `version.qualifier`, which means that we have to replace
// `version` by the actual version and `qualifier` with a unique identifier
// otherwise OSGi can't find out which nightly build is newest and therefore
// not all caches are updated with the correct version of a nightly.
packageOptions in Compile in packageBin += {
val m = Using.fileInputStream(new java.io.File("MANIFEST.MF.prototype")) { in =>
val manifest = new java.util.jar.Manifest(in)
val attr = manifest.getMainAttributes
val key = "Bundle-Version"
val versionSuffix = scalaBinaryVersion.value.replace('.', '_')
// get the version but get rid of "-SNAPSHOT" suffix if it exists
val v = {
val v = version.value
val i = v.lastIndexOf('-')
if (i > 0)
v.substring(0, i)
else
v
}
val date = new java.text.SimpleDateFormat("yyyyMMddHHmm").format(new java.util.Date)
val sha = "git rev-parse --short HEAD".!!.trim
attr.putValue(key, attr.getValue(key).replace("version.qualifier", s"$v.$versionSuffix-$date-$sha"))
manifest
}
Package.JarManifest(m)
},
testOptions in Test += Tests.Argument("-oI"),
mimaPreviousArtifacts := Set(organization.value %% "scalariform" % "0.2.9")
)
)
lazy val cli = (project
enablePlugins(BuildInfoPlugin)
settings(subprojectSettings("cli"))
settings(publishSettings("cli"))
settings(
libraryDependencies += "commons-io" % "commons-io" % "1.4",
mainClass in (Compile, packageBin) := Some("scalariform.commandline.Main"),
mainClass in assembly := Some("scalariform.commandline.Main"),
artifact in (Compile, assembly) := {
val art = (artifact in (Compile, assembly)).value
art.withClassifier(Some("assembly"))
}
)
settings(addArtifact(artifact in (Compile, assembly), assembly))
dependsOn(scalariform)
)
lazy val root = (project in file(".")
settings(publishSettings("root"))
settings(commonSettings)
aggregate(scalariform, cli)
)
def pomExtraXml =
<inceptionYear>2010</inceptionYear>
<url>https://github.com/scala-ide/scalariform</url>
<licenses>
<license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<url>git@github.com:scala-ide/scalariform.git</url>
<connection>scm:git:git@github.com:scala-ide/scalariform</connection>
</scm>
<developers>
<developer>
<id>scala-ide</id>
<name>Scala IDE</name>
<url>https://github.com/scala-ide/</url>
</developer>
<developer>
<id>mdr</id>
<name>Matt Russell</name>
<url>https://github.com/mdr/</url>
</developer>
<developer>
<id>daniel-trinh</id>
<name>Daniel Trinh</name>
<url>https://github.com/daniel-trinh/</url>
</developer>
<developer>
<id>machaval</id>
<name>Mariano de Achaval</name>
<url>https://github.com/machaval/</url>
</developer>
<developer>
<id>godenji</id>
<name>N.S. Cutler</name>
<url>https://github.com/godenji/</url>
</developer>
</developers>