forked from nscala-time/nscala-time
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sbt
108 lines (89 loc) · 3.22 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
organization := "com.github.nscala-time"
sonatypeProfileName := "com.github.nscala-time"
name := "nscala-time"
publishMavenStyle := true
val Scala210 = "2.10.6"
scalaVersion := Scala210
// sbt "release cross"
crossScalaVersions := Seq(Scala210, "2.11.8", "2.12.0-M4")
val unusedWarnings = "-Ywarn-unused" :: "-Ywarn-unused-import" :: Nil
scalacOptions <++= scalaVersion map { v =>
Seq("-unchecked", "-deprecation", "-feature", "-language:implicitConversions", "-language:higherKinds")
}
scalacOptions ++= PartialFunction.condOpt(CrossVersion.partialVersion(scalaVersion.value)){
case Some((2, scalaMajor)) if scalaMajor >= 11 => unusedWarnings
}.toList.flatten
Seq(Compile, Test).flatMap(c =>
scalacOptions in (c, console) ~= {_.filterNot(unusedWarnings.toSet)}
)
def gitHashOrBranch: String = scala.util.Try(
sys.process.Process("git rev-parse HEAD").lines_!.head
).getOrElse("master")
scalacOptions in (Compile, doc) ++= {
Seq(
"-sourcepath", baseDirectory.value.getAbsolutePath,
"-doc-source-url", s"https://github.com/nscala-time/nscala-time/tree/${gitHashOrBranch}€{FILE_PATH}.scala"
)
}
libraryDependencies ++= Seq(
"joda-time" % "joda-time" % "2.9.4",
"org.joda" % "joda-convert" % "1.2"
)
libraryDependencies += {
val v = CrossVersion.partialVersion(scalaVersion.value) match {
case Some((_, n)) if n <= 11 && n >= 10 => "1.12.5"
case _ => "1.11.6"
}
"org.scalacheck" %% "scalacheck" % v % "test"
}
pomPostProcess := { node =>
import scala.xml._
import scala.xml.transform._
def stripIf(f: Node => Boolean) = new RewriteRule {
override def transform(n: Node) =
if (f(n)) NodeSeq.Empty else n
}
val stripTestScope = stripIf { n => n.label == "dependency" && (n \ "scope").text == "test" }
new RuleTransformer(stripTestScope).transform(node)(0)
}
initialCommands in console += {
Iterator("org.joda.time._", "com.github.nscala_time.time.Imports._").map("import "+).mkString("\n")
}
pomExtra := (
<url>https://github.com/nscala-time/nscala-time</url>
<licenses>
<license>
<name>Apache</name>
<url>http://www.opensource.org/licenses/Apache-2.0</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<url>[email protected]:nscala-time/nscala-time.git</url>
<connection>scm:git:[email protected]:nscala-time/nscala-time.git</connection>
</scm>
<developers>
<developer>
<id>kmizu</id>
<name>Kota Mizushima</name>
<url>https://github.com/kmizu</url>
</developer>
</developers>
)
credentials ++= {
val sonatype = ("Sonatype Nexus Repository Manager", "oss.sonatype.org")
def loadMavenCredentials(file: java.io.File) : Seq[Credentials] = {
xml.XML.loadFile(file) \ "servers" \ "server" map (s => {
val host = (s \ "id").text
val realm = if (host == sonatype._2) sonatype._1 else "Unknown"
Credentials(realm, host, (s \ "username").text, (s \ "password").text)
})
}
val ivyCredentials = Path.userHome / ".ivy2" / ".credentials"
val mavenCredentials = Path.userHome / ".m2" / "settings.xml"
(ivyCredentials.asFile, mavenCredentials.asFile) match {
case (ivy, _) if ivy.canRead => Credentials(ivy) :: Nil
case (_, mvn) if mvn.canRead => loadMavenCredentials(mvn)
case _ => Nil
}
}