-
Notifications
You must be signed in to change notification settings - Fork 9
/
build.sbt
154 lines (140 loc) · 5.18 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
import com.typesafe.sbt.pgp.PgpKeys.publishSigned
import ReleaseTransformations._
lazy val buildSettings = Seq(
organization := "com.milessabin",
scalaVersion := "2.11.8",
crossScalaVersions := Seq("2.10.7", scalaVersion.value),
crossVersion := CrossVersion.full
)
lazy val commonSettings = Seq(
scalacOptions := Seq(
"-feature",
"-language:higherKinds",
"-language:implicitConversions",
"-unchecked"
),
javacOptions ++= Seq("-source", "1.6", "-target", "1.6"),
resolvers ++= Seq(
Resolver.sonatypeRepo("releases"),
Resolver.sonatypeRepo("snapshots"),
"bintray/non" at "http://dl.bintray.com/non/maven"
),
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-library" % scalaVersion.value % "provided",
"org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided",
"org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided"
)
) ++ crossVersionSharedSources
lazy val usePluginSettings = Seq(
scalacOptions in Compile <++= (Keys.`package` in (plugin, Compile)) map { (jar: File) =>
System.setProperty("sbt.paths.plugin.jar", jar.getAbsolutePath)
val addPlugin = "-Xplugin:" + jar.getAbsolutePath
// Thanks Jason for this cool idea (taken from https://github.com/retronym/boxer)
// add plugin timestamp to compiler options to trigger recompile of
// main after editing the plugin. (Otherwise a 'clean' is needed.)
val dummy = "-Jdummy=" + jar.lastModified
Seq(addPlugin, dummy)
}
)
lazy val coreSettings = buildSettings ++ commonSettings ++ publishSettings ++ releaseSettings
lazy val root = project.in(file("."))
.aggregate(plugin, library)
.dependsOn(plugin, library)
.settings(coreSettings:_*)
.settings(noPublishSettings)
lazy val library = project.in(file("library"))
.settings(moduleName := "si2712fix-library")
.settings(coreSettings)
lazy val plugin = project.in(file("plugin"))
.settings(moduleName := "si2712fix-plugin")
.settings(coreSettings)
.settings(resourceDirectory in Compile <<= baseDirectory(_ / "src" / "main" / "scala" / "si2712fix" / "embedded"))
.settings(compileOrder := CompileOrder.ScalaThenJava)
.settings(sources in (Compile, doc) ~= (_ filter (_.getName endsWith ".scala")))
.settings(manipulateBytecode in Compile := {
val previous = (manipulateBytecode in Compile).value
fixSuperCtorCall(
classes = (classDirectory in Compile).value,
classpath =
(managedClasspath in Compile).value.files ++
(unmanagedResourceDirectories in Compile).value :+
(classDirectory in Compile).value
)
previous
})
lazy val tests = project.in(file("tests"))
.dependsOn(library)
.settings(moduleName := "tests")
.settings(coreSettings)
.settings(noPublishSettings)
.settings(usePluginSettings)
.settings(
fullClasspath in Test := {
val testcp = (fullClasspath in Test).value.files.map(_.getAbsolutePath).mkString(java.io.File.pathSeparatorChar.toString)
sys.props("sbt.paths.tests.classpath") = testcp
(fullClasspath in Test).value
}
)
def scalaPartV = Def setting (CrossVersion partialVersion scalaVersion.value)
lazy val crossVersionSharedSources: Seq[Setting[_]] =
Seq(Compile, Test).map { sc =>
(unmanagedSourceDirectories in sc) ++= {
(unmanagedSourceDirectories in sc).value.map { dir =>
scalaPartV.value match {
case Some((2, y)) if y == 10 => new File(dir.getPath + "_2.10")
case Some((2, y)) if y == 11 => new File(dir.getPath + "_2.11")
}
}
}
}
lazy val publishSettings = Seq(
publishMavenStyle := true,
publishArtifact in Test := false,
pomIncludeRepository := { _ => false },
publishTo <<= version { (v: String) =>
val nexus = "https://oss.sonatype.org/"
if (v.trim.endsWith("SNAPSHOT"))
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
},
homepage := Some(url("https://github.com/milessabin/si2712fix-plugin")),
licenses := Seq("Apache 2" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt")),
scmInfo := Some(ScmInfo(url("https://github.com/milessabin/si2712fix-plugin"), "scm:git:[email protected]:milessabin/si2712fix-plugin.git")),
pomExtra := (
<developers>
<developer>
<id>milessabin</id>
<name>Miles Sabin</name>
<url>http://milessabin.com/blog</url>
</developer>
</developers>
)
)
lazy val noPublishSettings = Seq(
publish := (),
publishLocal := (),
publishArtifact := false
)
lazy val releaseSettings = Seq(
releaseCrossBuild := true,
releasePublishArtifactsAction := PgpKeys.publishSigned.value,
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
commitReleaseVersion,
tagRelease,
publishArtifacts,
setNextVersion,
commitNextVersion,
ReleaseStep(action = Command.process("sonatypeReleaseAll", _)),
pushChanges
)
)
credentials ++= (for {
username <- Option(System.getenv().get("SONATYPE_USERNAME"))
password <- Option(System.getenv().get("SONATYPE_PASSWORD"))
} yield Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", username, password)).toSeq