-
-
Notifications
You must be signed in to change notification settings - Fork 951
/
build.gradle
546 lines (471 loc) · 20.4 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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "io.github.gradle-nexus:publish-plugin:$gradleNexusPublishPluginVersion"
classpath "com.netflix.nebula:gradle-extra-configurations-plugin:$gradleExtraConfigurationsPluginVersion"
classpath "com.bmuschko:gradle-nexus-plugin:$gradleNexusPluginVersion"
classpath "gradle.plugin.com.hierynomus.gradle.plugins:license-gradle-plugin:$gradleLicensePluginVersion"
}
}
apply plugin: 'idea'
ext {
isJava8Compatible = org.gradle.api.JavaVersion.current().isJava8Compatible()
grailsVersion = project.projectVersion
isCiBuild = System.getenv().get("CI") as Boolean
isGitHubRepoPublish = System.getenv("GITHUB_PUBLISH") == 'true'
isGrailsRepoPublish = grailsVersion.endsWith("-SNAPSHOT") && !isGitHubRepoPublish
isReleaseVersion = !isGrailsRepoPublish && !isGitHubRepoPublish
springLoadedCommonOptions = "-Xverify:none -Dspringloaded.synchronize=true -Djdk.reflect.allowGetCallerClass=true"
nexusUsername = System.getenv("SONATYPE_USERNAME") ?: project.hasProperty("sonatypeOssUsername") ? project.sonatypeOssUsername : ''
nexusPassword = System.getenv("SONATYPE_PASSWORD") ?: project.hasProperty("sonatypeOssPassword") ? project.sonatypeOssPassword : ''
// Directories created during the build which are related
// to turning the workspace root into a GRAILS_HOME
distInstallDir = layout.buildDirectory.dir('dist-tmp')
homeDistDir = layout.projectDirectory.dir('dist')
homeBinDir = layout.projectDirectory.dir('bin')
homeConfDir = layout.projectDirectory.dir('conf')
homeLibDir = layout.projectDirectory.dir('lib')
homeSrcDir = layout.projectDirectory.dir('src')
}
version = grailsVersion
group = "org.grails"
// Groovy is added as a dependency to both the 'groovy' and 'compile'
// configurations, so place the dependency in a shared variable. The
// 'compile' is required so that Groovy appears as a dependency in the
// artifacts' POMs.
ext.jointBuildGroovyJarProperty = System.getProperty('groovy.jar')
ext.groovyDependency = null
ext."signing.keyId" = System.getenv("SIGNING_KEY") ?: project.hasProperty("signing.keyId") ? project.getProperty('signing.keyId') : null
ext."signing.password" = System.getenv("SIGNING_PASSPHRASE") ?: project.hasProperty("signing.password") ? project.getProperty('signing.password') : null
ext."signing.secretKeyRingFile" = project.hasProperty("signing.secretKeyRingFile") ? project.getProperty('signing.secretKeyRingFile') : null
if (jointBuildGroovyJarProperty) {
def jointBuildGroovyJar = file(jointBuildGroovyJarProperty)
if (jointBuildGroovyJar.exists()) {
groovyDependency = dependencies.create(files(jointBuildGroovyJar))
} else {
throw new GradleException("The groovy.jar system property points to ${jointBuildGroovyJar.absolutePath} which does not exist.")
}
} else {
groovyDependency = dependencies.create("org.apache.groovy:groovy:${groovyVersion}")
}
if (isReleaseVersion) {
apply plugin: 'maven-publish'
apply plugin: "io.github.gradle-nexus.publish-plugin"
nexusPublishing {
repositories {
sonatype {
def ossUser = System.getenv("SONATYPE_USERNAME") ?: project.hasProperty("sonatypeOssUsername") ? project.sonatypeOssUsername : ''
def ossPass = System.getenv("SONATYPE_PASSWORD") ?: project.hasProperty("sonatypeOssPassword") ? project.sonatypeOssPassword : ''
def ossStagingProfileId = System.getenv("SONATYPE_STAGING_PROFILE_ID") ?: project.hasProperty("sonatypeOssStagingProfileId") ? project.sonatypeOssStagingProfileId : ''
nexusUrl = uri("https://s01.oss.sonatype.org/service/local/")
username = ossUser
password = ossPass
stagingProfileId = ossStagingProfileId
}
}
transitionCheckOptions {
maxRetries.set(40)
delayBetween.set(java.time.Duration.ofMillis(5000))
}
}
}
allprojects {
if (project.name == 'grails-bom') return
// FORCE UPGRADE OF GROOVY IN DEPENDENCIES TO GROOVY 4
// except in projects that will be run by Gradle during the build
if (!compiledByGradleGroovyVersion(project)) {
configurations.configureEach {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'org.codehaus.groovy' && details.requested.name != 'groovy-bom') {
details.useTarget(group: 'org.apache.groovy', name: details.requested.name, version: groovyVersion)
}
}
}
}
repositories {
mavenCentral()
maven { url = 'https://repo.grails.org/grails/core' }
maven { url = 'https://oss.sonatype.org/content/repositories/snapshots' }
// mavenLocal() // Keep, this will be uncommented and used by CI (groovy-joint-workflow)
}
configurations {
all {
resolutionStrategy {
def cacheHours = isCiBuild ? 0 : 24
cacheDynamicVersionsFor cacheHours, 'hours'
cacheChangingModulesFor cacheHours, 'hours'
eachDependency { DependencyResolveDetails details ->
//specifying a fixed version for all libraries with 'org.gradle' group
if (details.requested.group == 'org.apache.groovy') {
details.useVersion(groovyVersion)
}
if (details.requested.group == "org.spockframework") {
details.useVersion(project['spock.version'])
}
}
}
}
}
[Javadoc, Groovydoc].each {
tasks.withType(it).all {
// exclude problematic jar file from javadoc classpath
// https://www.adam-bien.com/roller/abien/entry/trouble_with_crippled_java_ee
if (classpath) {
classpath -= classpath.filter { it.name == 'javaee-web-api-6.0.jar' }
}
// this will apply the javadoc fix tool to all generated javadocs
// we use it to make sure that the javadocs are not vulnerable independently of the JDK used to build
doLast {
def javadocFix = new JavadocFixTool()
javadocFix.recursive = true
javadocFix.doPatch = true
javadocFix.searchAndPatch(destinationDir)
}
}
}
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
}
// This added to prevent remote cache miss, because project JAR include manifest file with Build-By and Created-By properties which might be different for CI vs Local.
normalization {
runtimeClasspath {
metaInf {
ignoreAttribute("Built-By")
ignoreAttribute("Created-By")
}
}
}
apply from: rootProject.layout.projectDirectory.file('gradle/dependency-licenses.gradle')
}
apply from: "gradle/idea.gradle"
subprojects { subproject ->
version = grailsVersion
group = "org.grails"
ext.isTestSuite = subproject.name.startsWith("grails-test-suite")
ext.isCiBuild = subproject.hasProperty("isCiBuild") || System.getenv().get("CI") as Boolean
ext.pomInfo = {
delegate.name 'Grails® framework'
delegate.description 'Grails Web Application Framework'
delegate.url 'https://grails.org/'
delegate.licenses {
delegate.license {
delegate.name 'The Apache Software License, Version 2.0'
delegate.url 'https://www.apache.org/licenses/LICENSE-2.0.txt'
delegate.distribution 'repo'
}
}
delegate.scm {
delegate.url 'scm:git@github.com:grails/grails-core.git'
delegate.connection 'scm:git@github.com:grails/grails-core.git'
delegate.developerConnection 'scm:git@github.com:grails/grails-core.git'
}
delegate.developers {
delegate.developer {
delegate.id 'graemerocher'
delegate.name 'Graeme Rocher'
delegate.email 'grails-build@users.noreply.github.com'
}
}
}
if (subproject.name != 'grails-bom') {
apply plugin: 'java-library'
apply plugin: 'groovy'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'project-report'
}
if (!isTestSuite) {
apply plugin: 'maven-publish'
apply plugin: 'signing'
if (subproject.name != 'grails-bom') {
java {
withJavadocJar()
withSourcesJar()
}
}
publishing {
if (isGrailsRepoPublish || isGitHubRepoPublish) {
repositories {
maven {
credentials {
if (isGrailsRepoPublish) {
def u = subproject.hasProperty("artifactoryPublishUsername") ? subproject.getProperty('artifactoryPublishUsername') : System.getenv("ARTIFACTORY_USERNAME")
def p = subproject.hasProperty("artifactoryPublishPassword") ? subproject.getProperty('artifactoryPublishPassword') : System.getenv("ARTIFACTORY_PASSWORD")
username = u
password = p
} else {
def u = System.getenv('GITHUB_USERNAME') ?: ''
def p = System.getenv('GITHUB_PASSWORD') ?: ''
username = u
password = p
}
}
if (isGrailsRepoPublish) {
url "https://repo.grails.org/grails/libs-snapshots-local"
} else {
url 'https://maven.pkg.github.com/grails/grails-core'
}
}
}
}
if (subproject.name == 'grails-dependencies') return
publications {
maven(MavenPublication) {
pom {
name = 'Grails® framework'
description = 'Grails Web Application Framework'
url = 'https://grails.org/'
licenses {
license {
name = 'The Apache Software License, Version 2.0'
url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
distribution = 'repo'
}
}
scm {
url = 'scm:git@github.com:grails/grails-core.git'
connection = 'scm:git@github.com:grails/grails-core.git'
developerConnection = 'scm:git@github.com:grails/grails-core.git'
}
developers {
developer {
id = 'graemerocher'
name = 'Graeme Rocher'
email = 'grails-build@users.noreply.github.com'
}
}
}
if (subproject.name != 'grails-bom') {
from components.java
}
}
}
}
afterEvaluate {
signing {
required { (isReleaseVersion || isGitHubRepoPublish) && gradle.taskGraph.hasTask("publish") }
sign publishing.publications.maven
}
}
tasks.withType(Sign) {
onlyIf { isReleaseVersion || isGitHubRepoPublish }
}
//do not generate extra load on Nexus with new staging repository if signing fails
if (isReleaseVersion) {
tasks.withType(io.github.gradlenexus.publishplugin.InitializeNexusStagingRepository).configureEach {
shouldRunAfter(tasks.withType(Sign))
}
}
}
if (subproject.name in ['grails-dependencies', 'grails-bom']) return
dependencies {
api platform(project(':grails-bom'))
}
if (subproject.name =~ /^(grails-web|grails-plugin-|grails-test-suite|grails-test)/) {
dependencies {
compileOnly "jakarta.servlet:jakarta.servlet-api"
testImplementation "jakarta.servlet:jakarta.servlet-api"
// MockHttpServletRequest/Response/Context used in many classes
compileOnly "org.springframework:spring-test"
testImplementation "org.springframework:spring-test"
}
}
if (subproject.name =~ /^(grails-plugin-datasource|grails-test-suite)/) {
dependencies {
testImplementation "com.h2database:h2"
}
}
jar {
manifest.mainAttributes(
"Built-By": System.properties['user.name'],
"Created-By": System.properties['java.vm.version'] + " (" + System.properties['java.vm.vendor'] + ")",
"Implementation-Title": "Grails",
"Implementation-Version": grailsVersion,
"Implementation-Vendor": 'grails.org')
}
configurations {
documentation
meta
published.extendsFrom archives, meta
}
dependencies {
documentation platform(project(':grails-bom'))
documentation "org.fusesource.jansi:jansi"
documentation "jline:jline"
documentation "com.github.javaparser:javaparser-core"
if (compiledByGradleGroovyVersion(subproject)) {
documentation "org.codehaus.groovy:groovy:$GroovySystem.version"
documentation "org.codehaus.groovy:groovy-ant:$GroovySystem.version"
documentation "org.codehaus.groovy:groovy-cli-picocli:$GroovySystem.version"
} else {
api groovyDependency
documentation "org.apache.groovy:groovy"
documentation "org.apache.groovy:groovy-ant"
documentation "org.apache.groovy:groovy-cli-picocli"
}
testImplementation "org.apache.groovy:groovy-test-junit5"
testImplementation "org.junit.jupiter:junit-jupiter-api"
testImplementation "org.junit.platform:junit-platform-runner"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine"
compileOnly "com.github.spotbugs:spotbugs-annotations"
if (subproject.name != "grails-docs") {
// Logging
api "org.slf4j:slf4j-api"
api "org.slf4j:jcl-over-slf4j"
// Testing
testImplementation "org.slf4j:slf4j-simple"
testImplementation("org.spockframework:spock-core") { transitive = false }
// Required by Spock's Mocking
testRuntimeOnly "net.bytebuddy:byte-buddy"
testImplementation "org.objenesis:objenesis"
}
}
def debugArguments = [
'-Xmx2g', '-Xdebug', '-Xnoagent', '-Djava.compiler=NONE',
'-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005'
]
def java17moduleReflectionCompatibilityArguments = [
'--add-opens=java.base/java.lang=ALL-UNNAMED',
'--add-opens=java.base/java.util=ALL-UNNAMED'
]
tasks.withType(Test).configureEach {
useJUnitPlatform()
jvmArgs += java17moduleReflectionCompatibilityArguments
}
tasks.withType(Jar) {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
// Add the Groovy compiler options
tasks.withType(GroovyCompile).configureEach {
groovyOptions.fork(memoryInitialSize: '128M', memoryMaximumSize: '1G')
groovyOptions.encoding = "UTF-8"
options.encoding = "UTF-8"
}
tasks.withType(Groovydoc).configureEach {
onlyIf { !isTestSuite }
classpath += configurations.documentation
access = GroovydocAccess.PRIVATE
includeAuthor = true
includeMainForScripts = false
processScripts = false
}
tasks.withType(Javadoc).configureEach {
onlyIf { !isTestSuite }
classpath += configurations.documentation
// Using options.jFlags instead of closure otherwise it fails with MinimalJavadocOptions
options.encoding "UTF-8"
options.docEncoding "UTF-8"
options.charSet "UTF-8"
options.jFlags "-Xms64M", "-Xmx512M"
}
configure(javadoc) {
onlyIf { !isTestSuite }
classpath += configurations.documentation
// Using options.jFlags instead of closure otherwise it fails with MinimalJavadocOptions
options.encoding "UTF-8"
options.docEncoding "UTF-8"
options.charSet "UTF-8"
options.jFlags "-Xms64M", "-Xmx512M"
}
// task for running a single test with -DsingleTest.single=TestName singleTest
tasks.register("singleTest", Test) {
if (System.getProperty("debug.tests")) {
jvmArgs += debugArguments
}
}
test {
develocity {
testRetry {
maxRetries = 2
maxFailures = 20
failOnPassedAfterRetry = true
}
}
testLogging {
events "passed", "skipped", "failed"
showExceptions true
exceptionFormat "full"
showCauses true
showStackTraces true
}
excludes = ["**/*TestCase.class", "**/*\$*.class"]
if (isCiBuild) {
maxParallelForks = 2
maxHeapSize = '768m'
afterSuite {
System.out.print('.')
System.out.flush()
}
} else {
maxHeapSize = '1024m'
}
if (System.getProperty("debug.tests")) {
jvmArgs += debugArguments
}
}
compileJava.options.release = 17
if (!isTestSuite) {
tasks.register('installToHomeDist', Copy) {
dependsOn 'jar', 'sourcesJar', 'javadocJar'
from layout.buildDirectory.dir('libs')
into distInstallDir
}
tasks.withType(PublishToMavenLocal).configureEach {
dependsOn 'installToHomeDist'
doLast {
ant.copy(todir: homeDistDir.asFile, flatten: true, includeEmptyDirs: false) {
fileset dir: distInstallDir.get().asFile
}
}
}
}
}
tasks.register('clean', Delete) {
group = 'build'
delete layout.buildDirectory, homeBinDir, homeConfDir, homeDistDir, homeLibDir, homeSrcDir
}
// From this point on we need the subprojects to be fully configured, so force their full evaluation
subprojects.each {
if (it.tasks.findByName('install') && it.tasks.findByName('publishToMavenLocal')) {
it.tasks.findByName('install').finalizedBy(it.tasks.findByName('publishToMavenLocal'))
}
evaluationDependsOn it.path
}
apply {
from 'gradle/docs.gradle' // tasks for building the documentation (e.g. user guide, javadocs)
from 'gradle/assemble.gradle' // tasks for creating an installation or distribution
from 'gradle/findbugs.gradle'
}
// Add a task to list the buildscript dependencies
tasks.register('buildscriptDependencies', org.gradle.api.tasks.diagnostics.DependencyReportTask) {
configurations = project.buildscript.configurations
}
[Javadoc, Groovydoc].each {
tasks.withType(it).all {
// exclude problematic jar file from javadoc classpath
// https://www.adam-bien.com/roller/abien/entry/trouble_with_crippled_java_ee
if (classpath) {
classpath -= classpath.filter { it.name == 'javaee-web-api-6.0.jar' }
}
}
}
// Ensure that no insecure HTTP-based Maven repositories are defined
project.afterEvaluate {
allprojects.repositories.each { handler ->
handler.each {
if (it.url.toString().startsWith("http://")) {
throw new RuntimeException("Build should not define insecure HTTP-based Maven repostories")
}
}
}
}
// compile with the Groovy version provided by Gradle
// to ensure build compatibility with Gradle, currently Groovy 3.0.x
// when used by grails-gradle-plugin
// see: https://docs.gradle.org/current/userguide/compatibility.html#groovy
boolean compiledByGradleGroovyVersion(Project currentProject) {
currentProject.name in ['grails-bootstrap', 'grails-gradle-model', 'grails-shell']
}