forked from stellar/java-stellar-anchor-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
198 lines (167 loc) · 6.73 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
import org.apache.tools.ant.taskdefs.condition.Os
// The alias call in plugins scope produces IntelliJ false error which is suppressed here.
@Suppress("DSL_SCOPE_VIOLATION")
plugins {
java
`java-test-fixtures`
alias(libs.plugins.spotless)
alias(libs.plugins.kotlin.jvm) apply false
jacoco
}
// *******************************************************************************
// Task registration and configuration
// *******************************************************************************
// The printVersionName task is used to print the version name of the project. This
// is useful for CI/CD pipelines to get the version string of the project.
tasks.register("printVersionName") { println(rootProject.version.toString()) }
// The updateGitHook task is used to copy the pre-commit.sh file to the .git/hooks
// directory. This is part of the efforts to force the Java/Kotlin code to be formatted
// before committing the code.
tasks.register<Copy>("updateGitHook") {
from("scripts/pre-commit.sh") { rename { it.removeSuffix(".sh") } }
into(".git/hooks")
doLast {
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
project.exec { commandLine("chmod", "+x", ".git/hooks/pre-commit") }
}
}
}
tasks { build { dependsOn("updateGitHook") } }
// *******************************************************************************
// Common configurations
// *******************************************************************************
subprojects {
apply(plugin = "java")
apply(plugin = "com.diffplug.spotless")
apply(plugin = "jacoco")
apply(plugin = "java-test-fixtures")
repositories {
mavenLocal()
mavenCentral()
maven { url = uri("https://packages.confluent.io/maven") }
maven { url = uri("https://repository.mulesoft.org/nexus/content/repositories/public/") }
maven { url = uri("https://jitpack.io") }
}
/** Specifies JDK-17 */
java { toolchain { languageVersion.set(JavaLanguageVersion.of(17)) } }
spotless {
java {
importOrder("java", "javax", "org.stellar")
removeUnusedImports()
googleJavaFormat()
}
kotlin { ktfmt("0.42").googleStyle() }
tasks.jacocoTestReport {
dependsOn(tasks.test) // tests are required to run before generating the report
reports {
xml.required.set(true)
csv.required.set(false)
html.required.set(false)
}
}
}
dependencies {
// `rootProject` is required here if we want to use the libs object in the root project.
implementation(rootProject.libs.findbugs.jsr305)
implementation(rootProject.libs.aws.sqs)
implementation(rootProject.libs.postgresql)
// used to force the version of scala-library (used by kafka-json-schema-serializer) to a safer
// one.
implementation(rootProject.libs.scala.library)
implementation(rootProject.libs.bundles.kafka)
implementation(rootProject.libs.spring.kafka)
implementation(rootProject.libs.log4j.template.json)
// Although the following libraries are transitive dependencies, we are including them here to
// override the version
// for security vulnerabilities.
implementation(rootProject.libs.spring.aws.messaging)
implementation(rootProject.libs.aws.java.sdk.s3)
// The common dependencies are declared here because we would like to have a uniform unit
// testing across all subprojects.
//
// We need to use the dependency string because the VERSION_CATEGORY feature isn't supported in
// subproject task as of today.
//
testImplementation(rootProject.libs.bundles.junit)
testImplementation(rootProject.libs.jsonassert)
testFixturesImplementation(rootProject.libs.bundles.junit)
testFixturesImplementation(rootProject.libs.jsonassert)
testAnnotationProcessor(rootProject.libs.lombok)
}
/**
* This is to fix the Windows default cp-1252 character encoding that may potentially cause
* compilation error
*/
tasks {
compileJava {
options.encoding = "UTF-8"
/** Enforces google-java-format at Java compilation. */
dependsOn("spotlessApply")
}
compileTestJava { options.encoding = "UTF-8" }
javadoc { options.encoding = "UTF-8" }
test {
useJUnitPlatform()
systemProperty(
"junit.jupiter.testclass.order.default",
"org.junit.jupiter.api.ClassOrderer\$OrderAnnotation")
exclude("**/AnchorPlatformCustodyEnd2EndTest**")
exclude("**/AnchorPlatformCustodyApiRpcEnd2EndTest**")
testLogging {
events("SKIPPED", "FAILED")
showExceptions = true
showStandardStreams = true
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
}
}
processResources {
doFirst {
val existingFile = file("$buildDir/resources/main/metadata.properties")
existingFile.delete()
}
// This is to replace the %APP_VERSION_TOKEN% in the metadata.properties file.
filter { line -> line.replace("%APP_VERSION_TOKEN%", rootProject.version.toString()) }
}
}
configurations {
all {
exclude(group = "ch.qos.logback", module = "logback-classic")
exclude(group = "org.apache.logging.log4j", module = "log4j-to-slf4j")
exclude(group = "org.slf4j", module = "slf4j-log4j12")
exclude(group = "org.slf4j", module ="slf4j-simple")
}
}
}
allprojects {
group = "org.stellar.anchor-sdk"
version = "2.8.2"
tasks.jar {
manifest {
attributes(
mapOf(
"Implementation-Title" to project.name, "Implementation-Version" to project.version))
}
}
}
tasks.register("printUsage") {
doLast {
val green = "\u001B[32m"
val bold = "\u001B[1m"
// ANSI escape code to reset
val reset = "\u001B[0m"
println(
"""
${green}${bold}Usage: ./gradlew <task>${reset}
Available custom tasks:
- ${bold}printVersionName${reset}: Prints the version of the project.
- ${bold}updateGitHook${reset}: Updates the git hook to format the code before committing.
- ${bold}startAllServers${reset}: Starts all the servers based on the `default` test configuration.
- ${bold}startServersWithTestProfile${reset}: Starts the servers based on the test configuration specified by the TEST_PROFILE_NAME environment variable.
- ${bold}dockerComposeStart${reset}: Runs docker-compose up to start Postgres, Kafka, etc.
- ${bold}dockerComposeStop${reset}: Runs docker-compose down to stop Postgres, Kafka, etc.
- ${bold}anchorTest${reset}: Runs stellar anchor tests. Set `TEST_HOME_DOMAIN` and `TEST_SEPS` environment variables to customize the tests.
"""
.trimIndent())
}
}
defaultTasks("printUsage")