forked from scala-ide/scalariform
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sbt
167 lines (156 loc) · 5.25 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
import com.typesafe.sbt.SbtScalariform.ScalariformKeys
import scalariform.formatter.preferences._
lazy val commonSettings = inConfig(Test)(Defaults.testSettings) ++
SbtScalariform.defaultScalariformSettings ++ Seq(
organization := "com.github.machaval",
sonatypeProfileName := organization.value,
scalaVersion := crossScalaVersions.value.head,
crossScalaVersions := Seq(
"2.12.0",
"2.11.8",
"2.10.6"
),
exportJars := true, // Needed for cli oneJar
scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
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",
"-Xfatal-warnings",
"-Ywarn-unused-import",
"-Ywarn-unused"
)
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)
}
lazy val subprojectSettings = commonSettings :+ (
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 => Seq(
"org.scala-lang.modules" %% "scala-xml" % "1.0.5",
"org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.4"
)
case _ => Nil
}
}
lazy val scalariform = (project
enablePlugins(BuildInfoPlugin)
settings(subprojectSettings)
settings(publishSettings("scalariform"))
settings(
libraryDependencies ++= scala2_11Dependencies.value,
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "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 `x.y.z.qualifier` but we need to replace the `qualifier` part
// 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(file("scalariform/META-INF/MANIFEST.MF")) { in =>
val manifest = new java.util.jar.Manifest(in)
val attr = manifest.getMainAttributes
val key = "Bundle-Version"
val versionSuffix = scalaBinaryVersion.value.replace('.', '_')
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("qualifier", s"$versionSuffix-$date-$sha"))
manifest
}
Package.JarManifest(m)
},
testOptions in Test += Tests.Argument("-oI")
)
)
lazy val cli = (project
enablePlugins(BuildInfoPlugin)
settings(subprojectSettings)
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.copy(`classifier` = 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/machaval/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>[email protected]:machaval/scalariform.git</url>
<connection>scm:git:[email protected]:machaval/scalariform</connection>
</scm>
<developers>
<developer>
<id>machaval</id>
<name>Mariano de Achaval</name>
<url>https://github.com/machaval/</url>
</developer>
<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>
</developers>