-
Notifications
You must be signed in to change notification settings - Fork 92
/
build.gradle
300 lines (261 loc) · 11 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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
import java.util.regex.Pattern
plugins {
id 'java-library'
id 'maven-publish'
id 'com.diffplug.spotless' version '6.11.0'
id 'nu.studer.credentials' version '2.1'
id 'org.asciidoctor.jvm.convert' version '3.3.2' apply false
id 'io.github.gradle-nexus.publish-plugin' version '1.1.0'
}
ext {
// Credentials can be specified on the command-line using project properties,
// or stored locally using the gradle-credentials-plugin.
// See below for the name of project properties.
// See https://github.com/etiennestuder/gradle-credentials-plugin to store credentials locally.
if (!project.hasProperty('jbossNexusUser')) {
jbossNexusUser = credentials.jbossNexusUser
}
if (!project.hasProperty('jbossNexusPassword')) {
jbossNexusPassword = credentials.jbossNexusPassword
}
if (!project.hasProperty('sonatypeOssrhUser')) {
sonatypeOssrhUser = credentials.sonatypeOssrhUser
}
if (!project.hasProperty('sonatypeOssrhPassword')) {
sonatypeOssrhPassword = credentials.sonatypeOssrhPassword
}
}
ext {
projectGroup = 'org.hibernate.reactive'
projectVersionFile = file( "${rootProject.projectDir}/gradle/version.properties" )
projectVersion = Version.parseProjectVersion( readVersionFromProperties( projectVersionFile ) )
if ( project.hasProperty('releaseVersion') ) {
releaseVersion = Version.parseReleaseVersion( project.releaseVersion )
}
if ( project.hasProperty('developmentVersion') ) {
developmentVersion = Version.parseDevelopmentVersion( project.developmentVersion )
}
}
// nexusPublishing uses group and version
// as defaults
group = projectGroup
version = projectVersion
// Versions which need to be aligned across modules; this also
// allows overriding the build using a parameter, which can be
// useful to monitor compatibility for upcoming versions on CI:
//
// ./gradlew clean build -PhibernateOrmVersion=5.6.15-SNAPSHOT
ext {
if ( !project.hasProperty('hibernateOrmVersion') ) {
hibernateOrmVersion = '6.2.0-SNAPSHOT'
}
// For ORM, we need a parsed version (to get the family, ...)
// For ORM, we need a parsed version (to get the family for the documentation during release).
// We use intervals to build with the latest ORM snapshot and this will fail version check.
// Because we don't need to publish or release anything we can disable the check in this case.
// Example:
// ./gradlew build -PhibernateOrmVersion='[5.4,5.5)' -PskipOrmVersionParsing
if ( project.hasProperty( 'skipOrmVersionParsing' ) ) {
// Default to true if the property is null
skipOrmVersionParsing = project.skipOrmVersionParsing ?: true
}
else {
skipOrmVersionParsing = false
}
if ( !Boolean.valueOf( project.skipOrmVersionParsing ) ) {
logger.lifecycle "Parsing ORM version"
hibernateOrmVersion = Version.parseProjectVersion( project.hibernateOrmVersion )
}
// Mainly, to allow CI to test the latest versions of Vert.X
// Example:
// ./gradlew build -PvertxVersion=4.0.0-SNAPSHOT
if ( !project.hasProperty('vertxVersion') ) {
vertxVersion = '4.3.8'
}
testcontainersVersion = '1.17.5'
logger.lifecycle "Hibernate ORM Version: " + project.hibernateOrmVersion
logger.lifecycle "Vert.x Version: " + project.vertxVersion
logger.lifecycle "Hibernate Reactive: " + project.version
}
// To release, see task ciRelease in release/build.gradle
// To publish snapshots:
// ./gradlew publishToJBossNexus closeAndReleaseJBossNexusStagingRepository -PjbossNexusUser="<YOUR USERNAME>" -PjbossNexusPassword="<YOUR PASSWORD>"
// To publish on Sonatype (Maven Central):
// ./gradlew publishToSonatype closeAndReleaseStagingRepository -PsonatypeOssrhUser="<YOUR USERNAME>" -PsonatypeOssrhPassword="<YOUR PASSWORD>"
nexusPublishing {
repositories {
sonatype {
username = project.sonatypeOssrhUser
password = project.sonatypeOssrhPassword
}
jBossNexus {
snapshotRepositoryUrl = uri('https://repository.jboss.org/nexus/content/repositories/snapshots')
username = project.jbossNexusUser
password = project.jbossNexusPassword
}
}
}
subprojects {
apply plugin: 'java-library'
apply plugin: 'com.diffplug.spotless'
// FIXME: Also setting the group and version here otherwise not all tasks will find them
group = projectGroup
version = projectVersion
spotless {
//Don't fail during the check: rather than enforcing guidelines, we use this plugin to fix mistakes automatically.
enforceCheck false
java {
licenseHeaderFile rootProject.file('spotless.license.java')
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
}
tasks.compileJava.dependsOn(spotlessApply)
repositories {
// Example: ./gradlew build -PenableMavenLocalRepo
if ( project.hasProperty('enableMavenLocalRepo') ) {
// Useful for local development, it should be disabled otherwise
mavenLocal()
}
// Example: ./gradlew build -PenableSonatypeOpenSourceSnapshotsRep
if ( project.hasProperty('enableSonatypeOpenSourceSnapshotsRep') ) {
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
}
mavenCentral()
// Example: ./gradlew build -PenableJBossSnapshotsRep
if ( project.hasProperty('enableJBossSnapshotsRep') ) {
// Used only for testing with the latest Hibernate ORM snapshots.
maven { url 'https://repository.jboss.org/nexus/content/repositories/snapshots' }
}
}
ext.publishScript = rootProject.rootDir.absolutePath + '/publish.gradle'
tasks.withType( JavaCompile ) {
options.encoding = 'UTF-8'
}
if ( !gradle.ext.javaToolchainEnabled ) {
sourceCompatibility = JavaVersion.toVersion( gradle.ext.baselineJavaVersion )
targetCompatibility = JavaVersion.toVersion( gradle.ext.baselineJavaVersion )
}
else {
// Configure generated bytecode
// "sourceCompatibility" is not supported with toolchains. We have to work around that limitation.
tasks.compileJava.configure {
options.release = gradle.ext.javaVersions.main.release.asInt()
}
tasks.compileTestJava.configure {
options.release = gradle.ext.javaVersions.test.release.asInt()
}
// Configure version of Java tools
java {
toolchain {
languageVersion = gradle.ext.javaVersions.main.compiler
}
}
tasks.compileTestJava {
javaCompiler = javaToolchains.compilerFor {
languageVersion = gradle.ext.javaVersions.test.compiler
}
}
tasks.test {
javaLauncher = javaToolchains.launcherFor {
languageVersion = gradle.ext.javaVersions.test.launcher
}
}
// Configure JVM Options
tasks.withType( JavaCompile ).configureEach {
options.forkOptions.jvmArgs.addAll( getProperty( 'toolchain.compiler.jvmargs' ).toString().split( ' ' ) )
}
tasks.withType( Javadoc ).configureEach {
options.setJFlags( getProperty( 'toolchain.javadoc.jvmargs' ).toString().split( ' ' ).toList().findAll( { !it.isEmpty() } ) )
}
tasks.test {
// Configure JVM Options
jvmArgs(getProperty('toolchain.launcher.jvmargs').toString().split(' '))
if ( project.hasProperty( 'test.jdk.launcher.args' ) ) {
jvmArgs( project.getProperty( 'test.jdk.launcher.args' ).toString().split( ' ' ) )
}
}
// Display version of Java tools
tasks.withType( JavaCompile ).configureEach {
doFirst {
logger.lifecycle "Compiling with '${javaCompiler.get().metadata.installationPath}'"
}
}
tasks.withType( Javadoc ).configureEach {
doFirst {
logger.lifecycle "Generating javadoc with '${javadocTool.get().metadata.installationPath}'"
}
}
tasks.test {
doFirst {
logger.lifecycle "Testing with '${javaLauncher.get().metadata.installationPath}'"
}
}
}
}
private static String readVersionFromProperties(File file) {
if ( !file.exists() ) {
throw new GradleException( "Version file $file.canonicalPath does not exists" )
}
Properties versionProperties = new Properties()
file.withInputStream {
stream -> versionProperties.load( stream )
}
return versionProperties.projectVersion
}
class Version {
private static final Pattern RELEASE_VERSION_PATTERN = ~/^(\d+)\.(\d+)\.(\d+)\.((?:Alpha\d+|Beta\d+|CR\d+)|Final)$/
private static final Pattern DEVELOPMENT_VERSION_PATTERN = ~/^(\d+)\.(\d+)\.(\d+)-SNAPSHOT$/
static Version parseReleaseVersion(String versionString) {
def matcher = (versionString =~ RELEASE_VERSION_PATTERN)
if ( !matcher.matches() ) {
throw new IllegalArgumentException(
"Invalid version number: '$versionString'." +
" Release version numbers must match /$RELEASE_VERSION_PATTERN/."
)
}
return new Version( matcher.group(1), matcher.group(2), matcher.group(3), matcher.group(4), false )
}
static Version parseDevelopmentVersion(String versionString) {
def matcher = (versionString =~ DEVELOPMENT_VERSION_PATTERN)
if ( !matcher.matches() ) {
throw new IllegalArgumentException(
"Invalid version number: '$versionString'." +
" Development version numbers must match /$DEVELOPMENT_VERSION_PATTERN/."
)
}
return new Version( matcher.group(1), matcher.group(2), matcher.group(3), null, true )
}
static Version parseProjectVersion(String versionString) {
if ( (versionString =~ RELEASE_VERSION_PATTERN).matches() ) {
return parseReleaseVersion( versionString )
}
if ( (versionString =~ DEVELOPMENT_VERSION_PATTERN).matches() ) {
return parseDevelopmentVersion( versionString )
}
throw new IllegalArgumentException(
"Invalid version number: '$versionString'." +
" Project version numbers must match either /$RELEASE_VERSION_PATTERN/ or /$DEVELOPMENT_VERSION_PATTERN/."
)
}
final String major
final String minor
final String micro
final String qualifier
final boolean snapshot
Version(String major, String minor, String micro, String qualifier, boolean snapshot) {
this.major = major
this.minor = minor
this.micro = micro
this.qualifier = qualifier
this.snapshot = snapshot
}
@Override
String toString() {
[major, minor, micro, qualifier].findAll({ it != null }).join('.') + (snapshot ? '-SNAPSHOT' : '')
}
String getFamily() {
"$major.$minor"
}
}