forked from lemonlabsuk/scala-uri
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
178 lines (160 loc) · 6.92 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
import sbt.Keys.libraryDependencies
import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}
import scala.xml.transform.{RewriteRule, RuleTransformer}
import com.typesafe.tools.mima.core.{
DirectMissingMethodProblem,
IncompatibleResultTypeProblem,
MissingClassProblem,
ProblemFilters,
ReversedMissingMethodProblem
}
import com.typesafe.tools.mima.plugin.MimaKeys.{mimaBinaryIssueFilters, mimaPreviousArtifacts, mimaReportBinaryIssues}
lazy val NEXUS_HOST = sys.props.get("NEXUS_HOST").getOrElse("")
lazy val NEXUS_USER = sys.props.get("NEXUS_USER").getOrElse("")
lazy val NEXUS_PASS = sys.props.get("NEXUS_PASS").getOrElse("")
name := "scala-uri root"
ThisBuild / scalaVersion := "3.3.3"
ThisBuild / crossScalaVersions := Seq("2.12.19", "2.13.13", scalaVersion.value)
publish / skip := true // Do not publish the root project
val simulacrumScalafixVersion = "0.5.4"
ThisBuild / scalafixDependencies += "org.typelevel" %% "simulacrum-scalafix" % simulacrumScalafixVersion
val isScala3 = Def.setting {
CrossVersion.partialVersion(scalaVersion.value).exists(_._1 != 2)
}
val sharedSettings = Seq(
organization := "com.actian",
libraryDependencies ++= Seq(
"org.typelevel" %%% "simulacrum-scalafix-annotations" % simulacrumScalafixVersion,
"org.scalatest" %%% "scalatest" % "3.2.18" % Test,
"org.scalatestplus" %%% "scalacheck-1-17" % "3.2.18.0" % Test,
"org.scalacheck" %%% "scalacheck" % "1.18.0" % Test,
"org.typelevel" %%% "cats-laws" % "2.10.0" % Test
),
scalacOptions ++= Seq(
"-unchecked",
"-deprecation",
"-encoding",
"utf8",
"-feature",
"-Xfatal-warnings",
"-language:higherKinds,implicitConversions"
) ++ (
VersionNumber(scalaVersion.value) match {
case v if v.matchesSemVer(SemanticSelector("=2.13")) => Seq("-Ymacro-annotations")
case v if v.matchesSemVer(SemanticSelector("<=2.12")) => Seq("-Ypartial-unification")
case _ => Nil
}
),
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision,
Test / parallelExecution := false,
coverageExcludedPackages := "(io.lemonlabs.uri.inet.Trie.*|io.lemonlabs.uri.inet.PublicSuffixes.*|io.lemonlabs.uri.inet.PublicSuffixTrie.*|io.lemonlabs.uri.inet.PunycodeSupport.*)"
)
def removePomDependency(groupId: String, artifactIdPrefix: String): PartialFunction[xml.Node, Seq[xml.Node]] = {
case e: xml.Elem
if e.label == "dependency" &&
e.child.exists(child => child.label == "groupId" && child.text == groupId) &&
e.child.exists(child => child.label == "artifactId" && child.text.startsWith(artifactIdPrefix)) =>
Nil
}
val scalaUriSettings = Seq(
name := "scala-uri",
description := "Simple scala library for building and parsing URIs",
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-core" % "2.10.0",
"org.typelevel" %%% "cats-parse" % "1.0.0"
),
libraryDependencies ++= (if (isScala3.value) Nil else Seq("com.chuusai" %%% "shapeless" % "2.3.10")),
pomPostProcess := { node =>
new RuleTransformer(new RewriteRule {
override def transform(node: xml.Node): Seq[xml.Node] = {
removePomDependency(groupId = "org.typelevel", artifactIdPrefix = "simulacrum")
.applyOrElse(node, (_: xml.Node) => Seq(node))
}
}).transform(node).head
}
)
val publishingSettings = Seq(
publishMavenStyle := true,
publish / skip := false,
Test / publishArtifact := false,
pomIncludeRepository := { _ =>
false
},
credentials += Credentials("Sonatype Nexus Repository Manager", NEXUS_HOST, NEXUS_USER, NEXUS_PASS),
publishTo := {
val nexus = "https://alm.actian.com/nexus/"
if (version.value.trim.endsWith("SNAPSHOT"))
Some("snapshots" at nexus + "content/repositories/aop-snapshot")
else
Some("releases" at nexus + "content/repositories/aop")
}
)
val previousVersions = Set.empty[String] // Set(0, 4).map(v => s"3.$v.0")
val mimaExcludes = Seq(
ProblemFilters.exclude[ReversedMissingMethodProblem]("io.lemonlabs.uri.typesafe.QueryValueInstances1.*"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("io.lemonlabs.uri.Host.*"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("io.lemonlabs.uri.Uri.*"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("io.lemonlabs.uri.Url.*"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("io.lemonlabs.uri.UrlPath.*")
)
val mimaSettings = Seq(
mimaPreviousArtifacts := {
if (VersionNumber(scalaVersion.value).matchesSemVer(SemanticSelector("<=2.13")))
previousVersions.map { organization.value % s"${name.value}_${scalaBinaryVersion.value}" % _ }
else
Set.empty
},
mimaBinaryIssueFilters ++= {
VersionNumber(scalaVersion.value) match {
case v if v.matchesSemVer(SemanticSelector("<2.13")) =>
mimaExcludes ++ Seq(
// In scala 2.12 adding a method to a value class breaks binary compatibility (see here: https://github.com/lightbend/mima/issues/135).
// This was fixed in scala 2.13, which is why we only exclude from mima for 2.12
ProblemFilters.exclude[DirectMissingMethodProblem]("io.lemonlabs.uri.typesafe.dsl.TypesafeUrlDsl.*")
)
case _ => mimaExcludes
}
},
mimaBinaryIssueFilters ++= Seq(
// Exclude the autogenerated public suffix Trie
ProblemFilters.exclude[MissingClassProblem]("io.lemonlabs.uri.inet._*")
),
Test / test := (Test / test).dependsOn(mimaReportBinaryIssues, mimaBinaryIssueFilters).value
)
lazy val scalaUri =
crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Full)
.in(file("."))
.settings(sharedSettings)
.settings(scalaUriSettings)
.settings(publishingSettings)
.settings(mimaSettings)
.jvmSettings(
Test / fork := true
)
.jsSettings(
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "2.8.0",
libraryDependencies ++= (
// securerandom used by scoverage in scala 2 tests
if (isScala3.value) Nil
else Seq("org.scala-js" %%% "scalajs-java-securerandom" % "1.0.0" % Test)
)
)
lazy val docs = project
.in(file("scala-uri-docs"))
.settings(
// README.md has examples with expected compiler warnings (deprecated code, exhaustive matches)
// Turn off these warnings to keep this noise down
// We can remove this if the following is implemented https://github.com/scalameta/mdoc/issues/286
scalacOptions ++= Seq("--no-warnings"),
publish / skip := true,
publishArtifact := false
)
.dependsOn(scalaUri.jvm)
.enablePlugins(MdocPlugin)
lazy val updatePublicSuffixes =
taskKey[Unit]("Updates the public suffix Set at io.lemonlabs.uri.internet.PublicSuffixes")
updatePublicSuffixes := UpdatePublicSuffixes.generate()
addCommandAlias("check", ";scalafmtCheckAll;scalafmtSbtCheck")
addCommandAlias("fmt", ";scalafmtAll;scalafmtSbt")