-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle
215 lines (190 loc) · 7.31 KB
/
build.gradle
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
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.owasp:dependency-check-gradle:7.2.1'
}
}
plugins {
id 'idea'
id 'groovy'
id 'java'
id 'java-library'
id 'maven-publish'
id 'signing'
id 'org.owasp.dependencycheck' version '8.0.2'
id 'com.github.johnrengelman.shadow' version '7.1.2'
}
group = 'io.elastic'
version = '4.0.3'
sourceCompatibility = '1.8'
dependencyCheck {
format = 'ALL'
// Dependency Check script will fail in case there are 8.0+ vulnerabilities.
// It should be configured to 7 (high and critical), but so far is not possible as 'jakarta.json-api' library
// does not have any updates that solve the problem
failBuildOnCVSS = 8
suppressionFile = './dependencycheck-base-suppression.xml'
}
check.dependsOn dependencyCheckAnalyze
def isCiEnv = 'true'.equals(System.getenv('CI'))
def isCiTag = System.getenv('CIRCLE_TAG') != null;
def isReleaseBuild = !version.endsWith('SNAPSHOT');
def snapshotRepositoryUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
def releaseRepositoryUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
def repositoryUsername = project.hasProperty('sonatypeUsername') ? sonatypeUsername : ""
def repositoryPassword = project.hasProperty('sonatypePassword') ? sonatypePassword : ""
repositories {
mavenCentral()
maven {
url snapshotRepositoryUrl
}
}
dependencies {
testRuntimeOnly 'org.codehaus.groovy:groovy-all:3.0.22'
testImplementation 'cglib:cglib-nodep:3.3.0'
testImplementation 'org.mockito:mockito-core:3.12.4'
testImplementation 'org.spockframework:spock-junit4:2.2-groovy-3.0'
testImplementation 'org.spockframework:spock-core:2.2-groovy-3.0'
testImplementation 'com.github.rest-driver:rest-client-driver:2.0.1'
testImplementation 'org.eclipse.jetty:jetty-server:9.4.55.v20240627'
testImplementation 'com.github.tomakehurst:wiremock-jre8-standalone:2.35.2'
api 'org.eclipse.parsson:parsson:1.1.6'
api 'com.rabbitmq:amqp-client:5.21.0'
api 'commons-codec:commons-codec:1.17.1'
api 'commons-io:commons-io:2.16.1'
api 'org.apache.httpcomponents:httpclient:4.5.14'
api 'com.google.inject:guice:5.1.0'
api 'com.google.inject.extensions:guice-assistedinject:5.1.0'
api 'ch.qos.logback:logback-classic:1.2.13'
api 'ch.qos.logback.contrib:logback-json-classic:0.1.5'
api 'ch.qos.logback.contrib:logback-jackson:0.1.5'
api 'com.fasterxml.jackson.core:jackson-databind:2.17.2'
}
jar {
manifest {
attributes(
'Implementation-Vendor' : 'elastic.io Gmbh',
'Implementation-Title': 'elastic.io Sailor for JVM',
'Implementation-Version': archiveVersion,
'Multi-Release': true
)
}
}
test {
useJUnitPlatform()
}
java {
withJavadocJar()
withSourcesJar()
}
wrapper {
gradleVersion = '7.5.1'
}
publishing {
publications {
mavenJava(MavenPublication) {
artifactId = 'sailor-jvm'
from components.java
pom {
name = 'elasticio-sailor-jvm'
packaging = 'jar'
description = 'Sailor for JVM'
url = 'http://www.elastic.io'
inceptionYear = '2015'
organization {
name = 'elastic.io GmbH'
url = 'http://www.elastic.io'
}
scm {
url = 'scm:[email protected]:elasticio/sailor-jvm.git'
connection = 'scm:[email protected]:elasticio/sailor-jvm.git'
developerConnection = 'scm:[email protected]:elasticio/sailor-jvm.git'
}
licenses {
license {
name = 'The Apache Software License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution = 'repo'
}
}
issueManagement {
system = 'GitHub'
url = 'https://github.com/elasticio/sailor-jvm/issues'
}
developers {
developer {
id = 'elasticio'
name = 'elastic.io GmbH'
email = '[email protected]'
}
}
}
}
}
repositories {
maven {
url = isReleaseBuild ? releaseRepositoryUrl : snapshotRepositoryUrl
credentials {
username = repositoryUsername
password = repositoryPassword
}
}
}
// A check to disable publishing if it's a snapshot version
if (!isReleaseBuild) {
println 'This is a SNAPSHOT version. Publishing to the Maven Snapshot will be skipped.'
tasks.withType(PublishToMavenRepository) { task ->
task.enabled = false
}
}
}
signing {
println 'isReleaseBuild: ' + isReleaseBuild;
required { isReleaseBuild && gradle.taskGraph.hasTask("publish"); }
if(isReleaseBuild && project.hasProperty('signingPassword') && project.hasProperty('signingKeyBase64')) {
def signingPassword = findProperty("signingPassword")
def signingKey = new String(findProperty("signingKeyBase64").decodeBase64())
useInMemoryPgpKeys(signingKey, signingPassword)
}
sign publishing.publications.mavenJava
}
afterEvaluate {
// In case CI env - skip publishing of release version without created tag
tasks.withType(PublishToMavenRepository) { task ->
if (isReleaseBuild && isCiEnv && !isCiTag) {
println 'Can not publish release version without tag. Did not find CIRCLE_TAG env variable. Skipping publication'
task.enabled = false
}
}
}
task postPublishCopyFilesFromMavelLocal(type: Copy) {
dependsOn publishToMavenLocal
def homeDir = System.getProperty("user.home")
def sourceDir = "${homeDir}/.m2/repository/io/elastic/sailor-jvm/${project.version}"
from fileTree(dir: sourceDir, include: '**/*', exclude: 'maven-metadata-local.xml')
into "${projectDir}/build/sailorReleaseBundle"
}
task postPublishCreateBundleJarFromMavelLocal(type: Exec) {
dependsOn publishToMavenLocal
commandLine "bash", "-c", "cd ${projectDir}/build/sailorReleaseBundle && jar -cvf bundle.jar ./*"
}
task postPublishActions {
dependsOn publishToMavenLocal, postPublishCopyFilesFromMavelLocal, postPublishCreateBundleJarFromMavelLocal
doLast {
println '====================================================================================================='
println 'All done. You can go to ./build/sailorReleaseBundle and upload the bundle.jar file from there'
println '====================================================================================================='
}
}
// Define the task dependencies and ensure they run in order
postPublishCopyFilesFromMavelLocal.mustRunAfter publishToMavenLocal
postPublishCreateBundleJarFromMavelLocal.mustRunAfter postPublishCopyFilesFromMavelLocal
// Add the custom tasks to the lifecycle
publishToMavenLocal.finalizedBy postPublishActions
shadowJar {
archiveBaseName.set('sailor-jvm')
archiveVersion.set(project.version.toString())
archiveClassifier.set('')
}