forked from hibernate/hibernate-reactive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
244 lines (213 loc) · 9.09 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
import java.util.regex.Pattern
plugins {
id 'java-library'
id 'maven-publish'
id 'com.diffplug.gradle.spotless' version '4.0.1'
id 'nu.studer.credentials' version '2.1' apply false
id 'com.jfrog.bintray' version '1.8.5' apply false
id 'org.asciidoctor.convert' version '1.5.7' apply false
}
ext {
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 )
}
}
// 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.4.30-SNAPSHOT
ext {
if ( !project.hasProperty('hibernateOrmVersion') ) {
hibernateOrmVersion = '5.4.29.Final'
}
// 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 = '3.9.6'
}
testcontainersVersion = '1.15.2'
logger.lifecycle "Hibernate ORM Version: " + project.hibernateOrmVersion
logger.lifecycle "Vert.x Version: " + project.vertxVersion
}
subprojects {
apply plugin: 'java-library'
apply plugin: 'com.diffplug.gradle.spotless'
group = 'org.hibernate.reactive'
version = projectVersion
repositories {
// Only enable these for local development, never push it:
// mavenLocal()
// jcenter()
// maven { url 'https://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 {
if ( project.gradle.ext.javaVersions.main.compiler.asInt() < 9 ) {
options.compilerArgs << '-source'
options.compilerArgs << gradle.ext.javaVersions.main.release.toString()
options.compilerArgs << '-target'
options.compilerArgs << gradle.ext.javaVersions.main.release.toString()
} else {
options.release = gradle.ext.javaVersions.main.release.asInt()
}
}
tasks.compileTestJava.configure {
if ( project.gradle.ext.javaVersions.test.compiler.asInt() < 9 ) {
options.compilerArgs << '-source'
options.compilerArgs << gradle.ext.javaVersions.test.release.toString()
options.compilerArgs << '-target'
options.compilerArgs << gradle.ext.javaVersions.test.release.toString()
} else {
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(' '))
}
// 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+)\.((?<=\.0\.)(?: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"
}
}