-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.gradle
253 lines (222 loc) · 8.13 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'ca.cutterslade.gradle:gradle-dependency-analyze:1.1.0'
}
}
plugins {
id "signing"
id "io.github.gradle-nexus.publish-plugin" version "1.0.0"
}
apply plugin: 'java-library'
apply plugin: 'idea'
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: 'io.github.gradle-nexus.publish-plugin'
ext.isPropertySet = { propName ->
if (!project.hasProperty(propName)) {
return false
} else {
def prop = project.getProperty(propName)
return (prop != "unspecified" && (prop != "" || prop != null))
}
}
ext.ensurePropertyIsSet = { propName ->
if (!isPropertySet(propName)) {
throw new GradleException(
"Expecting project property [${propName}] or env var [ORG_GRADLE_PROJECT_${propName}] to be set.")
}
}
//if the project has a value for the passed property (i.e from the cmd line via -PpropName=xxx)
//use that, else use a default value
ext.getPropertyOrDefault = { propName, defaultValue ->
def val;
if (isPropertySet(propName)) {
val = project.getProperty(propName)
println "Getting property [$propName] with value [$val]"
} else {
val = defaultValue
println "Property [$propName] has no value, using default value [$val]"
}
return val;
}
ext.versions = [
stroomExpression: getPropertyOrDefault('version', 'SNAPSHOT').replaceFirst(/^v/, "")
]
ext.isReleaseBuild = !versions.stroomExpression.endsWith('SNAPSHOT')
ext.moduleName = 'stroom.expression'
if (isReleaseBuild) {
println "This is a release build for maven version [${versions.stroomExpression}]"
// Ensure the various props are set for signing and publishing to sonatype
// The username for Sonatype OSSRH Jira account
ensurePropertyIsSet("sonatypeUsername")
// The password for Sonatype OSSRH Jira account
ensurePropertyIsSet("sonatypePassword")
// The GPG2 secret key in ascii armour format, base64 encoded
ensurePropertyIsSet("signingKey")
// The password for the GPG2 secret key
ensurePropertyIsSet("signingPassword")
}
group = 'uk.gov.gchq.stroom.expression'
version = versions.stroomExpression
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
implementation 'org.slf4j:slf4j-api:1.7.25'
testCompileOnly "org.junit.jupiter:junit-jupiter-api:5.3.2"
testImplementation "org.assertj:assertj-core:3.10.0"
testImplementation "com.caucho:hessian:4.0.51"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.3.2"
testRuntimeOnly "org.slf4j:slf4j-nop:1.7.25"
}
String base64DecodeProjectProperty(String propName) {
def encodedVal = project.findProperty(propName)
return encodedVal == null
? null
: new String(Base64.getDecoder().decode(encodedVal.toString())).trim()
}
void configureSigning(Project project) {
// To create the GPG key do:
// gpg2 --gen-key
// To list it
// gpg2 --list-keys
// To publish the public key on a keyserver
// gpg2 --keyserver hkp://keyserver.ubuntu.com --send-keys <your short key id>
// To get the ascii-armour private key for use in travis env vars as base64 encoded
// gpg2 --armor --export-secret-keys <your short key id> | base64 -w0
//project.signing.gnupg.keyName = project.findProperty("signingKeyId")
project.signing {
println "Configuring project to sign maven artifacts"
required { project.gradle.taskGraph.hasTask("required") }
def signingKeyId = project.findProperty("signingKeyId")
def signingKey = base64DecodeProjectProperty("signingKey")
def signingPassword = project.findProperty("signingPassword")
//println "pword: [$signingPassword]"
//println "key: [$signingKey]"
//println "keyId: [$signingKeyId]"
if (signingKeyId) {
println "Using in memory pgp key with ID"
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
} else if (signingKey) {
println "Using in memory pgp key without ID"
useInMemoryPgpKeys(signingKey, signingPassword)
}
//useGpgCmd()
sign project.publishing.publications.mavenJava
}
}
//for java plugin
//see https://docs.gradle.org/current/userguide/java_plugin.html
java {
//package JavaDoc as part of publication
withJavadocJar()
//package Sources as part of publication
withSourcesJar()
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
pom {
name = project['name']
description = "Library of functions as used in Stroom dashboards"
url = 'https://github.com/gchq/stroom-expression'
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
name = 'GCHQDevelopers'
organization = 'GCQH'
organizationUrl = 'https://github.com/gchq'
}
}
scm {
connection = 'scm:git:git@github.com:gchq/stroom-expression.git'
developerConnection = 'scm:git:git@github.com:gchq/stroom-expression.git'
url = 'https://github.com/gchq/stroom-expression'
}
}
}
}
}
def hasSigningKey = project.hasProperty("signingkeyId") || project.findProperty("signingKey")
if(hasSigningKey) {
configureSigning(project)
}
// See https://github.com/rwinch/gradle-publish-ossrh-sample
// Also https://github.com/kit-data-manager/nexus-publish-example
nexusPublishing {
repositories {
// Uses sonotypeUsername and sonotypePassword via ORG_GRADLE_PROJECT_sonatypeUsername
// and ORG_GRADLE_PROJECT_sonatypePassword
sonatype()
}
// these are not strictly required. The default timeouts are set to 1 minute. But Sonatype can be really slow.
// If you get the error "java.net.SocketTimeoutException: timeout", these lines will help.
connectTimeout = Duration.ofMinutes(3)
clientTimeout = Duration.ofMinutes(3)
}
afterEvaluate {
repositories {
mavenCentral()
}
// compileJava {
// inputs.property("moduleName", moduleName)
// doFirst {
// options.compilerArgs = [
// '--module-path', classpath.asPath,
// ]
// classpath = files()
// }
// }
//
// compileTestJava {
// inputs.property("moduleName", moduleName)
// doFirst {
// options.compilerArgs = [
// '--module-path', classpath.asPath,
// '--patch-module', "$moduleName=" + files(sourceSets.test.java.srcDirs).asPath,
// ]
// classpath = files()
// }
// }
//
// test {
// useJUnitPlatform()
//
// inputs.property("moduleName", moduleName)
// doFirst {
// jvmArgs = [
// '--module-path', classpath.asPath,
// '--add-modules', 'ALL-MODULE-PATH',
// '--patch-module', "$moduleName=" + files(sourceSets.test.java.outputDir).asPath,
//// '--add-opens', 'java.base/java.net=ALL-UNNAMED', // add the following VM parameters to the run configuration to avoid problems with the reflection restrictions in Java 9
//// '--add-opens', 'stroom.expression/stroom.dashboard.expression.v1=org.junit.platform.commons',
// ]
// classpath = files()
// }
// }
//
// javadoc {
// options.addStringOption('-module-path', classpath.asPath)
// options.addStringOption('Xdoclint:all,-missing', '-html5')
// }
jar {
inputs.property("moduleName", moduleName)
manifest {
attributes(
"Automatic-Module-Name": moduleName,
)
}
}
}