forked from scalapb-json/scalapb-circe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sbt
191 lines (179 loc) · 6.13 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
import scalapb.compiler.Version._
import sbtrelease.ReleaseStateTransformations._
import sbtcrossproject.CrossPlugin.autoImport.crossProject
val Scala211 = "2.11.12"
val circeVersion = settingKey[String]("")
val scalapbJsonCommonVersion = settingKey[String]("")
val tagName = Def.setting {
s"v${if (releaseUseGlobalVersion.value) (version in ThisBuild).value else version.value}"
}
val tagOrHash = Def.setting {
if (isSnapshot.value) sys.process.Process("git rev-parse HEAD").lineStream_!.head
else tagName.value
}
val unusedWarnings = Seq("-Ywarn-unused")
lazy val macros = project
.in(file("macros"))
.settings(
commonSettings,
name := UpdateReadme.scalapbCirceMacrosName,
libraryDependencies ++= Seq(
"io.github.scalapb-json" %%% "scalapb-json-macros" % scalapbJsonCommonVersion.value,
)
)
.dependsOn(
scalapbCirceJVM
)
lazy val tests = crossProject(JVMPlatform, JSPlatform)
.in(file("tests"))
.settings(
commonSettings,
noPublish,
)
.configure(_ dependsOn macros)
.dependsOn(
scalapbCirce % "test->test"
)
val scalapbCirce = crossProject(JVMPlatform, JSPlatform)
.in(file("core"))
.enablePlugins(BuildInfoPlugin)
.settings(
commonSettings,
name := UpdateReadme.scalapbCirceName,
mappings in (Compile, packageSrc) ++= (managedSources in Compile).value.map { f =>
// https://github.com/sbt/sbt-buildinfo/blob/v0.7.0/src/main/scala/sbtbuildinfo/BuildInfoPlugin.scala#L58
val buildInfoDir = "sbt-buildinfo"
val path = if (f.getAbsolutePath.contains(buildInfoDir)) {
(file(buildInfoPackage.value) / f
.relativeTo((sourceManaged in Compile).value / buildInfoDir)
.get
.getPath).getPath
} else {
f.relativeTo((sourceManaged in Compile).value).get.getPath
}
(f, path)
},
buildInfoPackage := "scalapb_circe",
buildInfoObject := "ScalapbCirceBuildInfo",
buildInfoKeys := Seq[BuildInfoKey](
"scalapbVersion" -> scalapbVersion,
circeVersion,
scalapbJsonCommonVersion,
scalaVersion,
version
)
)
.jvmSettings(
PB.targets in Test := Seq(
PB.gens.java -> (sourceManaged in Test).value,
scalapb.gen(javaConversions = true) -> (sourceManaged in Test).value
),
libraryDependencies ++= Seq(
"com.google.protobuf" % "protobuf-java-util" % protobufVersion % "test",
"com.google.protobuf" % "protobuf-java" % protobufVersion % "protobuf"
)
)
.jsSettings(
buildInfoKeys ++= Seq[BuildInfoKey](
"scalajsVersion" -> scalaJSVersion
),
scalacOptions += {
val a = (baseDirectory in LocalRootProject).value.toURI.toString
val g = "https://raw.githubusercontent.com/scalapb-json/scalapb-circe/" + tagOrHash.value
s"-P:scalajs:mapSourceURI:$a->$g/"
},
PB.targets in Test := Seq(
scalapb.gen(javaConversions = false) -> (sourceManaged in Test).value
)
)
commonSettings
val noPublish = Seq(
PgpKeys.publishLocalSigned := {},
PgpKeys.publishSigned := {},
publishLocal := {},
publish := {},
publishArtifact in Compile := false
)
noPublish
lazy val commonSettings = Seq[Def.SettingsDefinition](
unmanagedResources in Compile += (baseDirectory in LocalRootProject).value / "LICENSE.txt",
resolvers += Opts.resolver.sonatypeReleases,
scalaVersion := Scala211,
crossScalaVersions := Seq("2.12.8", Scala211),
scalacOptions ++= unusedWarnings,
Seq(Compile, Test).flatMap(c => scalacOptions in (c, console) --= unusedWarnings),
scalacOptions ++= Seq("-feature", "-deprecation", "-language:existentials"),
description := "Json/Protobuf convertors for ScalaPB",
licenses += ("MIT", url("https://opensource.org/licenses/MIT")),
organization := "io.github.scalapb-json",
Project.inConfig(Test)(sbtprotoc.ProtocPlugin.protobufConfigSettings),
PB.targets in Compile := Nil,
PB.protoSources in Test := Seq(baseDirectory.value.getParentFile / "shared/src/test/protobuf"),
scalapbJsonCommonVersion := "0.4.2",
circeVersion := "0.11.1",
libraryDependencies ++= Seq(
"io.github.scalapb-json" %%% "scalapb-json-common" % scalapbJsonCommonVersion.value,
"com.thesamet.scalapb" %%% "scalapb-runtime" % scalapbVersion % "protobuf,test",
"io.circe" %%% "circe-parser" % circeVersion.value,
"org.scalatest" %%% "scalatest" % "3.0.5" % "test"
),
pomExtra in Global := {
<url>https://github.com/scalapb-json/scalapb-circe</url>
<scm>
<connection>scm:git:github.com/scalapb-json/scalapb-circe.git</connection>
<developerConnection>scm:git:[email protected]:scalapb-json/scalapb-circe.git</developerConnection>
<url>github.com/scalapb-json/scalapb-circe.git</url>
<tag>{tagOrHash.value}</tag>
</scm>
<developers>
<developer>
<id>xuwei-k</id>
<name>Kenji Yoshida</name>
<url>https://github.com/xuwei-k</url>
</developer>
</developers>
},
publishTo := Some(
if (isSnapshot.value)
Opts.resolver.sonatypeSnapshots
else
Opts.resolver.sonatypeStaging
),
scalacOptions in (Compile, doc) ++= {
val t = tagOrHash.value
Seq(
"-sourcepath",
(baseDirectory in LocalRootProject).value.getAbsolutePath,
"-doc-source-url",
s"https://github.com/scalapb-json/scalapb-circe/tree/${t}€{FILE_PATH}.scala"
)
},
ReleasePlugin.extraReleaseCommands,
commands += Command.command("updateReadme")(UpdateReadme.updateReadmeTask),
releaseCrossBuild := true,
releaseTagName := tagName.value,
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
commitReleaseVersion,
UpdateReadme.updateReadmeProcess,
tagRelease,
ReleaseStep(
action = { state =>
val extracted = Project extract state
extracted.runAggregated(PgpKeys.publishSigned in Global in extracted.get(thisProjectRef), state)
},
enableCrossBuild = true
),
setNextVersion,
commitNextVersion,
releaseStepCommand("sonatypeReleaseAll"),
UpdateReadme.updateReadmeProcess,
pushChanges
)
).flatMap(_.settings)
val scalapbCirceJVM = scalapbCirce.jvm
val scalapbCirceJS = scalapbCirce.js