Skip to content

Commit b0be42d

Browse files
dreab8DavideD
authored andcommitted
[#1990] Consider moving away from subprojects block for subproject configuration
1 parent 154be85 commit b0be42d

File tree

14 files changed

+259
-539
lines changed

14 files changed

+259
-539
lines changed

build.gradle

Lines changed: 0 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -11,117 +11,6 @@ group = "org.hibernate.reactive"
1111
// leverage the ProjectVersion which comes from the `local.versions` plugin
1212
version = project.projectVersion.fullName
1313

14-
subprojects {
15-
apply plugin: 'java-library'
16-
apply plugin: 'com.diffplug.spotless'
17-
18-
group = rootProject.group
19-
version = rootProject.version
20-
21-
spotless {
22-
//Don't fail during the check: rather than enforcing guidelines, we use this plugin to fix mistakes automatically.
23-
enforceCheck false
24-
java {
25-
licenseHeaderFile rootProject.file('spotless.license.java')
26-
removeUnusedImports()
27-
trimTrailingWhitespace()
28-
endWithNewline()
29-
}
30-
}
31-
32-
tasks.compileJava.dependsOn(spotlessApply)
33-
34-
repositories {
35-
// Example: ./gradlew build -PenableMavenLocalRepo
36-
if ( project.hasProperty('enableMavenLocalRepo') ) {
37-
// Useful for local development, it should be disabled otherwise
38-
mavenLocal()
39-
}
40-
// Example: ./gradlew build -PenableCentralSonatypeSnapshotsRep
41-
if ( project.hasProperty('enableCentralSonatypeSnapshotsRep') ) {
42-
maven { url 'https://central.sonatype.com/repository/maven-snapshots/' }
43-
}
44-
45-
mavenCentral()
46-
}
47-
48-
ext.publishScript = rootProject.rootDir.absolutePath + '/publish.gradle'
49-
50-
tasks.withType( JavaCompile ).configureEach {
51-
options.encoding = 'UTF-8'
52-
}
53-
54-
// Configure test tasks for all subprojects
55-
tasks.withType( Test ).configureEach {
56-
// Set the project root for finding Docker files - available to all modules
57-
systemProperty 'hibernate.reactive.project.root', rootProject.projectDir.absolutePath
58-
}
59-
60-
if ( !gradle.ext.javaToolchainEnabled ) {
61-
sourceCompatibility = JavaVersion.toVersion( gradle.ext.baselineJavaVersion )
62-
targetCompatibility = JavaVersion.toVersion( gradle.ext.baselineJavaVersion )
63-
}
64-
else {
65-
// Configure generated bytecode
66-
// "sourceCompatibility" is not supported with toolchains. We have to work around that limitation.
67-
tasks.compileJava.configure {
68-
options.release = gradle.ext.javaVersions.main.release.asInt()
69-
}
70-
tasks.compileTestJava.configure {
71-
options.release = gradle.ext.javaVersions.test.release.asInt()
72-
}
73-
74-
// Configure version of Java tools
75-
java {
76-
toolchain {
77-
languageVersion = gradle.ext.javaVersions.main.compiler
78-
}
79-
}
80-
tasks.compileTestJava {
81-
javaCompiler = javaToolchains.compilerFor {
82-
languageVersion = gradle.ext.javaVersions.test.compiler
83-
}
84-
}
85-
tasks.test {
86-
javaLauncher = javaToolchains.launcherFor {
87-
languageVersion = gradle.ext.javaVersions.test.launcher
88-
}
89-
}
90-
91-
// Configure JVM Options
92-
tasks.withType( JavaCompile ).configureEach {
93-
options.forkOptions.jvmArgs.addAll( getProperty( 'toolchain.compiler.jvmargs' ).toString().split( ' ' ) )
94-
}
95-
tasks.withType( Javadoc ).configureEach {
96-
options.setJFlags( getProperty( 'toolchain.javadoc.jvmargs' ).toString().split( ' ' ).toList().findAll( { !it.isEmpty() } ) )
97-
}
98-
tasks.test {
99-
// Configure JVM Options
100-
jvmArgs(getProperty('toolchain.launcher.jvmargs').toString().split(' '))
101-
if ( project.hasProperty( 'test.jdk.launcher.args' ) ) {
102-
jvmArgs( project.getProperty( 'test.jdk.launcher.args' ).toString().split( ' ' ) )
103-
}
104-
}
105-
106-
// Display version of Java tools
107-
tasks.withType( JavaCompile ).configureEach {
108-
doFirst {
109-
logger.lifecycle "Compiling with '${javaCompiler.get().metadata.installationPath}'"
110-
}
111-
}
112-
tasks.withType( Javadoc ).configureEach {
113-
doFirst {
114-
logger.lifecycle "Generating javadoc with '${javadocTool.get().metadata.installationPath}'"
115-
}
116-
}
117-
tasks.test {
118-
doFirst {
119-
logger.lifecycle "Testing with '${javaLauncher.get().metadata.installationPath}'"
120-
}
121-
}
122-
}
123-
}
124-
12514
rootProject.afterEvaluate {
12615
// Workaround since "libs.versions.NAME" notation cannot be used here
12716
def libs = project.extensions.getByType(VersionCatalogsExtension).named('libs')

documentation/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import java.time.Year
44

55
plugins {
66
id "org.asciidoctor.jvm.convert"
7+
id "hr-java-library"
78
}
89

910
ext {

examples/native-sql-example/build.gradle

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ buildscript {
1717
}
1818

1919
plugins {
20+
id "hr-java-library"
21+
id "hr-print-resolved-version"
22+
2023
// Optional: Hibernate Gradle plugin to enable bytecode enhancements
2124
alias(libs.plugins.org.hibernate.orm)
2225
}
@@ -75,36 +78,3 @@ tasks.register( "runAllExamples" ) {
7578
dependsOn = ["runAllExamplesOnPostgreSQL"]
7679
description = "Run all examples on ${dbs}"
7780
}
78-
79-
// Optional: Task to print the resolved versions of Hibernate ORM and Vert.x
80-
tasks.register( "printResolvedVersions" ) {
81-
description = "Print the resolved hibernate-orm-core and vert.x versions"
82-
doLast {
83-
def hibernateCoreVersion = "n/a"
84-
def vertxVersion = "n/a"
85-
86-
// Resolve Hibernate Core and Vert.x versions from compile classpath
87-
configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.each { artifact ->
88-
if (artifact.moduleVersion.id.name == 'hibernate-core') {
89-
hibernateCoreVersion = artifact.moduleVersion.id.version
90-
}
91-
if (artifact.moduleVersion.id.group == 'io.vertx' && artifact.moduleVersion.id.name == 'vertx-sql-client') {
92-
vertxVersion = artifact.moduleVersion.id.version
93-
}
94-
}
95-
96-
// Print the resolved versions
97-
println "Resolved Hibernate ORM Core Version: ${hibernateCoreVersion}"
98-
println "Resolved Vert.x SQL client Version: ${vertxVersion}"
99-
}
100-
}
101-
102-
// Make the version printing task run before tests and JavaExec tasks
103-
tasks.withType( Test ).configureEach {
104-
dependsOn printResolvedVersions
105-
}
106-
107-
tasks.withType( JavaExec ).configureEach {
108-
dependsOn printResolvedVersions
109-
}
110-

examples/session-example/build.gradle

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ buildscript {
1717
}
1818

1919
plugins {
20+
id "hr-java-library"
21+
id "hr-print-resolved-version"
22+
2023
// Optional: Hibernate Gradle plugin to enable bytecode enhancements
2124
alias(libs.plugins.org.hibernate.orm)
2225
}
@@ -81,35 +84,3 @@ tasks.register( "runAllExamples" ) {
8184
dependsOn = ["runAllExamplesOnPostgreSQL", "runAllExamplesOnMySQL"]
8285
description = "Run all examples on ${dbs}"
8386
}
84-
85-
// Optional: Task to print the resolved versions of Hibernate ORM and Vert.x
86-
tasks.register( "printResolvedVersions" ) {
87-
description = "Print the resolved hibernate-orm-core and vert.x versions"
88-
doLast {
89-
def hibernateCoreVersion = "n/a"
90-
def vertxVersion = "n/a"
91-
92-
// Resolve Hibernate Core and Vert.x versions from compile classpath
93-
configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.each { artifact ->
94-
if (artifact.moduleVersion.id.name == 'hibernate-core') {
95-
hibernateCoreVersion = artifact.moduleVersion.id.version
96-
}
97-
if (artifact.moduleVersion.id.group == 'io.vertx' && artifact.moduleVersion.id.name == 'vertx-sql-client') {
98-
vertxVersion = artifact.moduleVersion.id.version
99-
}
100-
}
101-
102-
// Print the resolved versions
103-
println "Resolved Hibernate ORM Core Version: ${hibernateCoreVersion}"
104-
println "Resolved Vert.x SQL client Version: ${vertxVersion}"
105-
}
106-
}
107-
108-
// Make the version printing task run before tests and JavaExec tasks
109-
tasks.withType( Test ).configureEach {
110-
dependsOn printResolvedVersions
111-
}
112-
113-
tasks.withType( JavaExec ).configureEach {
114-
dependsOn printResolvedVersions
115-
}

hibernate-reactive-core/build.gradle

Lines changed: 7 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
plugins {
2+
id "hr-java-library"
3+
id "hr-test-containers"
4+
id "hr-print-resolved-version"
5+
}
6+
17
ext {
2-
mavenPomName = 'Hibernate Reactive Core'
8+
mavenPomName = 'Hibernate Reactive Core'
39
}
410

511
description = 'The core module of Hibernate Reactive'
@@ -90,113 +96,3 @@ tasks.withType(AbstractArchiveTask).configureEach {
9096
preserveFileTimestamps = false
9197
reproducibleFileOrder = true
9298
}
93-
94-
// Print a summary of the results of the tests (number of failures, successes and skipped)
95-
def loggingSummary(db, result, desc) {
96-
if ( !desc.parent ) { // will match the outermost suite
97-
def output = "${db} results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} passed, ${result.failedTestCount} failed, ${result.skippedTestCount} skipped)"
98-
def repeatLength = output.length() + 1
99-
logger.lifecycle '\n' + ('-' * repeatLength) + '\n' + output + '\n' + ('-' * repeatLength)
100-
}
101-
}
102-
103-
// Example:
104-
// gradle test -Pdb=MySQL
105-
test {
106-
def selectedDb = project.hasProperty( 'db' )
107-
? project.properties['db']
108-
: 'PostgreSQL'
109-
doFirst {
110-
systemProperty 'db', selectedDb
111-
}
112-
afterSuite { desc, result ->
113-
loggingSummary( selectedDb, result, desc )
114-
}
115-
}
116-
117-
// Configuration for the tests
118-
tasks.withType( Test ).configureEach {
119-
defaultCharacterEncoding = "UTF-8"
120-
useJUnitPlatform()
121-
testLogging {
122-
showStandardStreams = project.hasProperty('showStandardOutput')
123-
showStackTraces = true
124-
exceptionFormat = 'full'
125-
displayGranularity = 1
126-
events = ['PASSED', 'FAILED', 'SKIPPED']
127-
}
128-
systemProperty 'docker', project.hasProperty( 'docker' ) ? 'true' : 'false'
129-
systemProperty 'org.hibernate.reactive.common.InternalStateAssertions.ENFORCE', 'true'
130-
131-
if ( project.hasProperty( 'includeTests' ) ) {
132-
// Example: ./gradlew testAll -PincludeTests=DefaultPortTest
133-
filter {
134-
includeTestsMatching project.properties['includeTests'] ?: '*' as String
135-
}
136-
}
137-
}
138-
139-
def createTestDbTask(dbName) {
140-
tasks.register( "testDb${dbName}", Test ) {
141-
description = "Run tests for ${dbName}"
142-
143-
doFirst() {
144-
systemProperty 'db', dbName
145-
}
146-
afterSuite { desc, result ->
147-
loggingSummary( dbName, result, desc )
148-
}
149-
}
150-
}
151-
152-
// Rule to recognize calls to testDb<dbName>
153-
// and run the tests on the selected db
154-
// Example:
155-
// gradle testDbMySQL testDbDB2
156-
tasks.addRule( "Pattern testDb<id>" ) { String taskName ->
157-
if ( taskName.startsWith( "testDb" ) ) {
158-
def dbName = taskName.substring( "testDb".length() )
159-
createTestDbTask( dbName )
160-
}
161-
}
162-
163-
// The dbs we want to test when running testAll
164-
def dbs = ['MariaDB', 'MySQL', 'PostgreSQL', 'DB2', 'CockroachDB', 'MSSQLServer', 'Oracle']
165-
dbs.forEach { createTestDbTask it }
166-
167-
tasks.register( "testAll", Test ) {
168-
description = "Run tests for ${dbs}"
169-
dependsOn = dbs.collect( [] as HashSet ) { db -> "testDb${db}" }
170-
}
171-
172-
// Task to print the resolved versions of Hibernate ORM and Vert.x
173-
tasks.register( "printResolvedVersions" ) {
174-
description = "Print the resolved hibernate-orm-core and vert.x versions"
175-
doLast {
176-
def hibernateCoreVersion = "n/a"
177-
def vertxVersion = "n/a"
178-
179-
// Resolve Hibernate Core and Vert.x versions from compile classpath
180-
configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.each { artifact ->
181-
if (artifact.moduleVersion.id.name == 'hibernate-core') {
182-
hibernateCoreVersion = artifact.moduleVersion.id.version
183-
}
184-
if (artifact.moduleVersion.id.group == 'io.vertx' && artifact.moduleVersion.id.name == 'vertx-sql-client') {
185-
vertxVersion = artifact.moduleVersion.id.version
186-
}
187-
}
188-
189-
// Print the resolved versions
190-
println "Resolved Hibernate ORM Core Version: ${hibernateCoreVersion}"
191-
println "Resolved Vert.x SQL client Version: ${vertxVersion}"
192-
}
193-
}
194-
195-
// Make the version printing task run before tests and JavaExec tasks
196-
tasks.withType( Test ).configureEach {
197-
dependsOn printResolvedVersions
198-
}
199-
200-
tasks.withType( JavaExec ).configureEach {
201-
dependsOn printResolvedVersions
202-
}

0 commit comments

Comments
 (0)