-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathbuild.gradle.kts
111 lines (94 loc) · 3.84 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
// SPDX-License-Identifier: Apache-2.0
plugins {
id("org.hiero.gradle.module.application")
id("org.gradlex.java-module-dependencies")
}
mainModuleInfo {
runtimeOnly("io.grpc.netty.shaded")
runtimeOnly("org.slf4j.simple")
}
// 'protobuf' implementation provided through 'sdk' as it differs between 'sdk' and 'sdk-full'
dependencyAnalysis {
issues {
all { onUsedTransitiveDependencies { exclude("com.google.protobuf:protobuf-javalite") } }
}
}
dependencies.constraints {
implementation("com.google.guava:guava:33.3.1-android")
implementation("io.github.cdimascio:dotenv-java:3.0.2")
implementation("com.hedera.hashgraph:sdk:2.49.0")
implementation("com.hedera.hashgraph:sdk-full:2.49.0")
}
tasks.register<RunAllExample>("runAllExamples") {
workingDirectory = rootDir
sources.from(sourceSets.main.get().java.asFileTree)
rtClasspath.from(configurations.runtimeClasspath.get() + files(tasks.jar))
}
tasks.addRule("Pattern: run<Example>: Runs an example.") {
if (startsWith("run")) {
tasks.register<JavaExec>(this) {
workingDir = rootDir
classpath = configurations.runtimeClasspath.get() + files(tasks.jar)
mainModule = "com.hedera.hashgraph.sdk.examples"
mainClass =
"com.hedera.hashgraph.sdk.examples.${[email protected]("run".length)}Example"
}
}
}
abstract class RunAllExample : DefaultTask() {
@get:InputFiles abstract val sources: ConfigurableFileCollection
@get:InputFiles abstract val rtClasspath: ConfigurableFileCollection
@get:Internal abstract val workingDirectory: RegularFileProperty
@get:Inject abstract val exec: ExecOperations
@TaskAction
fun runAll() {
val exampleClasses =
sources
.filter { it.name.endsWith("Example.java") }
.asSequence()
.map { it.name.replace(".java", "") }
.filter {
it != "ValidateChecksumExample"
} // disabled this example, because it needs user input (but it WORKS)
.filter {
it != "ConsensusPubSubChunkedExample"
} // is flaky on local-node env, will be investigated
.filter {
it != "InitializeClientWithMirrorNetworkExample"
} // disabled - cannot run on localnode
.toList()
exampleClasses.forEach { className ->
println(
"""
---EXECUTING $className:
"""
.trimIndent()
)
exec.javaexec {
workingDir = workingDirectory.get().asFile
classpath = rtClasspath
mainModule = "com.hedera.hashgraph.sdk.examples"
mainClass = "com.hedera.hashgraph.sdk.examples.$className"
// NOTE: Uncomment to enable trace logs in the SDK during the examples
// jvmArgs "-Dorg.slf4j.simpleLogger.log.org.hiero=trace"
}
}
}
}
val updateAddressbooks = tasks.register("updateAddressbooks")
listOf("mainnet", "testnet", "previewnet").forEach { network ->
val taskName = "updateAddressbooks${network.replaceFirstChar(Char::titlecase)}"
tasks.register<JavaExec>(taskName) {
workingDir = rootDir
classpath = configurations.runtimeClasspath.get() + files(tasks.jar)
mainModule = "com.hedera.hashgraph.sdk.examples"
mainClass = "com.hedera.hashgraph.sdk.examples.GetAddressBookExample"
environment("HEDERA_NETWORK", network)
doLast {
val binFile = File(workingDir, "address-book.proto.bin")
val target = File(workingDir, "../sdk/src/main/resources/addressbook/$network.pb")
binFile.copyTo(target, overwrite = true)
}
}
updateAddressbooks { dependsOn(taskName) }
}