forked from waves-enterprise/we-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
189 lines (159 loc) · 6.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
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
import com.typesafe.sbt.git.JGit
import sbt.Tests.Group
import scala.jdk.CollectionConverters._
name := "waves-enterprise"
enablePlugins(GitVersioning)
disablePlugins(AssemblyPlugin)
Global / onChangedBuildSource := ReloadOnSourceChanges
Global / concurrentRestrictions := {
val processorsCount = java.lang.Runtime.getRuntime.availableProcessors
val parallelism = Option(System.getenv("SBT_THREAD_NUMBER")).fold(processorsCount)(_.toInt)
println(s"[info] sbt parallelism – $parallelism")
Seq(
Tags.limit(Tags.CPU, parallelism),
Tags.limit(Tags.Test, parallelism),
Tags.limitAll(parallelism)
)
}
initialize := {
val _ = initialize.value // run the previous initialization
val required = 11
val current = sys.props("java.specification.version").toDouble
assert(current >= required, s"Unsupported JDK version: required '$required' or above, but current is '$current'")
}
inThisBuild {
Seq(
scalaVersion := "2.12.10",
organization := "com.wavesenterprise",
crossPaths := false,
scalafmtOnCompile := true,
fork := true,
Test / parallelExecution := true,
testOptions += Tests.Argument("-oIDOF", "-u", "target/test-reports"),
scalacOptions ++= Seq(
"-feature",
"-deprecation",
"-language:higherKinds",
"-language:implicitConversions",
"-Ywarn-unused:-implicits",
"-Xlint",
"-Yresolve-term-conflict:object",
"-Ypartial-unification",
"-language:postfixOps"
)
)
}
lazy val branchName = Def.setting[String](sys.env.getOrElse("CI_COMMIT_REF_NAME", git.gitCurrentBranch.value))
/**
* The version is generated by the first possible method in the following order:
* Release version – {Tag}[-DIRTY]. When the tag corresponding to the version pattern is set on the last commit;
* Snapshot version – {Tag}-{Commits-ahead}-{Branch-name}-{Commit-hash}[-DIRTY]-SNAPSHOT. When the `git describe --tags` is worked;
* Fallback version – {Current-date}-SNAPSHOT.
*/
ThisBuild / version := {
if (git.gitUncommittedChanges.value) {
val changes = JGit(baseDirectory.value).porcelain
.status()
.call()
.getUncommittedChanges
.asScala
.mkString("\n")
println(s"Uncommitted changes detected:\n$changes")
}
val uncommittedChangesSuffix = git.makeUncommittedSignifierSuffix(git.gitUncommittedChanges.value, Some("DIRTY"))
val snapshotSuffix = "SNAPSHOT"
val releaseVersion = git.releaseVersion(git.gitCurrentTags.value, git.gitTagToVersionNumber.value, uncommittedChangesSuffix)
lazy val snapshotVersion = git.gitDescribedVersion.value.map { described =>
val commitHashLength = 7
val (tagVersionWithoutCommitHash, commitHash) = described.splitAt(described.length - commitHashLength)
val tagVersionWithCommitsAhead = tagVersionWithoutCommitHash.dropRight(2)
val branchSuffix = branchName.value.replaceAll("/", "__")
s"$tagVersionWithCommitsAhead-$branchSuffix-$commitHash$uncommittedChangesSuffix-$snapshotSuffix"
}
lazy val fallbackVersion = s"${git.formattedDateVersion.value}-$snapshotSuffix"
(releaseVersion orElse snapshotVersion) getOrElse fallbackVersion
}
ThisBuild / versionScheme := Some("semver-spec")
/**
* You have to put your credentials in a local file ~/.sbt/.credentials
*
* File structure:
* realm=Sonatype Nexus Repository Manager
* host=artifacts.wavesenterprise.com
* username={YOUR_LDAP_USERNAME}
* password={YOUR_LDAP_PASSWORD}
*/
ThisBuild / credentials += {
val envUsernameOpt = sys.env.get("nexusUser")
val envPasswordOpt = sys.env.get("nexusPassword")
(envUsernameOpt, envPasswordOpt) match {
case (Some(username), Some(password)) =>
println("Using credentials from environment for artifacts.wavesenterprise.com")
Credentials("Sonatype Nexus Repository Manager", "artifacts.wavesenterprise.com", username, password)
case _ =>
val localCredentialsFile = Path.userHome / ".sbt" / ".credentials"
println(s"Going to use ${localCredentialsFile.getAbsolutePath} as credentials for artifacts.wavesenterprise.com")
Credentials(localCredentialsFile)
}
}
lazy val testGroupingConfig: Def.Setting[_] =
testGrouping := {
val javaHomeValue = javaHome.value
val envVarsValue = envVars.value
val javaOptionsValue = javaOptions.value
for {
group <- testGrouping.value
test <- group.tests
} yield {
Group(
name = test.name,
tests = Seq(test),
runPolicy = Tests.SubProcess {
ForkOptions(
javaHome = javaHomeValue,
outputStrategy = outputStrategy.value,
bootJars = Vector.empty[java.io.File],
workingDirectory = Option(baseDirectory.value),
runJVMOptions = javaOptionsValue.toVector,
connectInput = false,
envVars = envVarsValue
)
}
)
}
}
lazy val testParallelizationSettings: Seq[Def.Setting[_]] =
inConfig(Test) {
inTask(test)(testGroupingConfig) ++
inTask(testOnly)(testGroupingConfig)
}
/* ********************************************************* */
lazy val isSnapshotVersion: Def.Initialize[Boolean] = version(_ endsWith "-SNAPSHOT")
lazy val wePublishingRepo: Def.Initialize[Some[Resolver]] = isSnapshotVersion {
case true =>
Some("Sonatype Nexus Snapshots Repository Manager" at "https://artifacts.wavesenterprise.com/repository/we-snapshots")
case _ =>
Some("Sonatype Nexus Repository Manager" at "https://artifacts.wavesenterprise.com/repository/we-releases")
}
lazy val publicationSettings: Def.Setting[Task[Option[Resolver]]] =
publishTo := wePublishingRepo.value
/* ********************************************************* */
lazy val root: Project = project
.in(file("."))
.aggregate(
node,
generator,
transactionsSigner
)
.settings(
publish / skip := true
)
lazy val node = (project in file("node"))
.settings(publicationSettings, testParallelizationSettings)
lazy val generator = (project in file("generator"))
.dependsOn(node)
.dependsOn(node % "test->test")
.settings(publicationSettings)
lazy val transactionsSigner = (project in file("transactions-signer"))
.dependsOn(node)
.settings(publicationSettings)