forked from libp2p/jvm-libp2p
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
237 lines (201 loc) · 6.56 KB
/
build.gradle.kts
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import com.google.protobuf.gradle.proto
import com.google.protobuf.gradle.protobuf
import com.google.protobuf.gradle.protoc
import com.jfrog.bintray.gradle.BintrayExtension
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.net.URL
import java.nio.file.Files
import java.nio.file.Paths
// To publish the release artifact to JFrog Bintray repo run the following :
// ./gradlew bintrayUpload -PbintrayUser=<user> -PbintrayApiKey=<api-key>
group = "io.libp2p"
version = "0.4.0-SNAPSHOT"
description = "a minimal implementation of libp2p for the jvm"
plugins {
java
idea
kotlin("jvm") version "1.3.31"
id("org.jmailen.kotlinter") version "1.26.0"
id("com.google.protobuf") version "0.8.7"
`build-scan`
`maven`
`maven-publish`
id("com.jfrog.bintray") version "1.8.1"
id("org.jetbrains.dokka") version "0.9.18"
}
repositories {
jcenter()
mavenCentral()
}
val log4j2Version = "2.11.2"
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0-M1")
compile("io.netty:netty-all:4.1.36.Final")
compile("com.google.guava:guava:27.1-jre")
compile("org.bouncycastle:bcprov-jdk15on:1.62")
compile("org.bouncycastle:bcpkix-jdk15on:1.62")
compile("com.google.protobuf:protobuf-java:3.11.0")
compile("commons-codec:commons-codec:1.13")
compile("org.apache.logging.log4j:log4j-api:${log4j2Version}")
compile("org.apache.logging.log4j:log4j-core:${log4j2Version}")
compile("javax.xml.bind:jaxb-api:2.3.1")
testCompile("org.junit.jupiter:junit-jupiter-api:5.4.2")
testCompile("org.junit.jupiter:junit-jupiter-params:5.4.2")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.4.2")
}
sourceSets {
main {
proto {
srcDir("src/main/proto")
}
}
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.0.0"
}
tasks.get("clean").doFirst({ delete(generatedFilesBaseDir) })
idea {
module {
sourceDirs.add(file("${generatedFilesBaseDir}/main/java"))
}
}
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions {
freeCompilerArgs = listOf("-XXLanguage:+InlineClasses", "-Xjvm-default=enable")
}
}
// Parallel build execution
tasks.test {
description = "Runs the unit tests."
useJUnitPlatform{
excludeTags("interop")
}
testLogging {
events("PASSED", "FAILED", "SKIPPED")
}
// disabling the parallel test runs for the time being due to port collisions
// If GRADLE_MAX_TEST_FORKS is not set, use half the available processors
// maxParallelForks = (System.getenv("GRADLE_MAX_TEST_FORKS")?.toInt() ?:
// Runtime.getRuntime().availableProcessors().div(2))
}
// Interop Tests
fun findOnPath(executable: String): Boolean {
return System.getenv("PATH").split(File.pathSeparator)
.map { Paths.get(it) }
.any { Files.exists(it.resolve(executable)) }
}
val goOnPath = findOnPath("go")
val nodeOnPath = findOnPath("node")
val rustOnPath = findOnPath("cargo")
val externalsDir = File(sourceSets.test.get().resources.sourceDirectories.singleFile, "../external")
val goPingServer = File(externalsDir, "go/ping-server")
val goPingClient = File(externalsDir, "go/ping-client")
val jsPinger = File(externalsDir, "js/pinger")
val rustPingServer = File(externalsDir, "rust/ping-server")
val rustPingClient = File(externalsDir, "rust/ping-client")
val goTargets = listOf(goPingServer, goPingClient).map { target ->
val name = "go-build-${target.name}"
task(name, Exec::class) {
workingDir = target
commandLine = "go build".split(" ")
}
name
}
val rustTargets = listOf(rustPingServer, rustPingClient).map { target ->
val name = "rust-build-${target.name}"
task(name, Exec::class) {
workingDir = target
commandLine = "cargo build".split(" ")
}
name
}
task("npm-install-pinger", Exec::class) {
workingDir = jsPinger
commandLine = "npm install".split(" ")
}
task("interopTest", Test::class) {
group = "Verification"
description = "Runs the interoperation tests."
val dependencies = ArrayList<String>()
if (goOnPath) dependencies.addAll(goTargets)
if (nodeOnPath) dependencies.add("npm-install-pinger")
if (rustOnPath) dependencies.addAll(rustTargets)
dependsOn(dependencies)
useJUnitPlatform {
includeTags("interop")
}
testLogging {
events("PASSED", "FAILED", "SKIPPED")
}
environment("ENABLE_JS_INTEROP", nodeOnPath)
environment("JS_PINGER", jsPinger.toString())
environment("ENABLE_GO_INTEROP", goOnPath)
environment("GO_PING_SERVER", goPingServer.toString())
environment("GO_PING_CLIENT", goPingClient.toString())
environment("ENABLE_RUST_INTEROP", rustOnPath)
environment("RUST_PING_SERVER", rustPingServer.toString())
environment("RUST_PING_CLIENT", rustPingClient.toString())
}
// End Interop Tests
kotlinter {
allowWildcardImports = false
}
buildScan {
termsOfServiceUrl = "https://gradle.com/terms-of-service"
termsOfServiceAgree = "yes"
}
val sourcesJar by tasks.registering(Jar::class) {
classifier = "sources"
from(sourceSets.main.get().allSource)
}
val dokka by tasks.getting(DokkaTask::class) {
outputFormat = "html"
outputDirectory = "$buildDir/dokka"
jdkVersion = 8
reportUndocumented = false
externalDocumentationLink {
url = URL("https://netty.io/4.1/api/")
}
}
val dokkaJar by tasks.creating(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Assembles Kotlin docs with Dokka"
archiveClassifier.set("javadoc")
from(tasks.dokka)
dependsOn(tasks.dokka)
}
publishing {
repositories {
maven {
// change to point to your repo, e.g. http://my.org/repo
url = uri("$buildDir/repo")
}
}
publications {
register("mavenJava", MavenPublication::class) {
from(components["java"])
artifact(sourcesJar.get())
artifact(dokkaJar)
}
}
}
fun findProperty(s: String) = project.findProperty(s) as String?
bintray {
user = findProperty("bintrayUser")
key = findProperty("bintrayApiKey")
publish = true
setPublications("mavenJava")
setConfigurations("archives")
pkg(delegateClosureOf<BintrayExtension.PackageConfig> {
userOrg = "libp2p"
repo = "jvm-libp2p"
name = "io.libp2p"
setLicenses("Apache-2.0", "MIT")
vcsUrl = "https://github.com/libp2p/jvm-libp2p"
})
}