Skip to content

Consider moving away from subprojects block for subproject configuration #2388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 0 additions & 111 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,117 +11,6 @@ group = "org.hibernate.reactive"
// leverage the ProjectVersion which comes from the `local.versions` plugin
version = project.projectVersion.fullName

subprojects {
apply plugin: 'java-library'
apply plugin: 'com.diffplug.spotless'

group = rootProject.group
version = rootProject.version

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 -PenableCentralSonatypeSnapshotsRep
if ( project.hasProperty('enableCentralSonatypeSnapshotsRep') ) {
maven { url 'https://central.sonatype.com/repository/maven-snapshots/' }
}

mavenCentral()
}

ext.publishScript = rootProject.rootDir.absolutePath + '/publish.gradle'

tasks.withType( JavaCompile ).configureEach {
options.encoding = 'UTF-8'
}

// Configure test tasks for all subprojects
tasks.withType( Test ).configureEach {
// Set the project root for finding Docker files - available to all modules
systemProperty 'hibernate.reactive.project.root', rootProject.projectDir.absolutePath
}

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}'"
}
}
}
}

rootProject.afterEvaluate {
// Workaround since "libs.versions.NAME" notation cannot be used here
def libs = project.extensions.getByType(VersionCatalogsExtension).named('libs')
Expand Down
1 change: 1 addition & 0 deletions documentation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import java.time.Year

plugins {
id "org.asciidoctor.jvm.convert"
id "hr-java-library"
}

ext {
Expand Down
36 changes: 3 additions & 33 deletions examples/native-sql-example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ buildscript {
}

plugins {
id "hr-java-library"
id "hr-print-resolved-version"

// Optional: Hibernate Gradle plugin to enable bytecode enhancements
alias(libs.plugins.org.hibernate.orm)
}
Expand Down Expand Up @@ -75,36 +78,3 @@ tasks.register( "runAllExamples" ) {
dependsOn = ["runAllExamplesOnPostgreSQL"]
description = "Run all examples on ${dbs}"
}

// Optional: Task to print the resolved versions of Hibernate ORM and Vert.x
tasks.register( "printResolvedVersions" ) {
description = "Print the resolved hibernate-orm-core and vert.x versions"
doLast {
def hibernateCoreVersion = "n/a"
def vertxVersion = "n/a"

// Resolve Hibernate Core and Vert.x versions from compile classpath
configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.each { artifact ->
if (artifact.moduleVersion.id.name == 'hibernate-core') {
hibernateCoreVersion = artifact.moduleVersion.id.version
}
if (artifact.moduleVersion.id.group == 'io.vertx' && artifact.moduleVersion.id.name == 'vertx-sql-client') {
vertxVersion = artifact.moduleVersion.id.version
}
}

// Print the resolved versions
println "Resolved Hibernate ORM Core Version: ${hibernateCoreVersion}"
println "Resolved Vert.x SQL client Version: ${vertxVersion}"
}
}

// Make the version printing task run before tests and JavaExec tasks
tasks.withType( Test ).configureEach {
dependsOn printResolvedVersions
}

tasks.withType( JavaExec ).configureEach {
dependsOn printResolvedVersions
}

35 changes: 3 additions & 32 deletions examples/session-example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ buildscript {
}

plugins {
id "hr-java-library"
id "hr-print-resolved-version"

// Optional: Hibernate Gradle plugin to enable bytecode enhancements
alias(libs.plugins.org.hibernate.orm)
}
Expand Down Expand Up @@ -81,35 +84,3 @@ tasks.register( "runAllExamples" ) {
dependsOn = ["runAllExamplesOnPostgreSQL", "runAllExamplesOnMySQL"]
description = "Run all examples on ${dbs}"
}

// Optional: Task to print the resolved versions of Hibernate ORM and Vert.x
tasks.register( "printResolvedVersions" ) {
description = "Print the resolved hibernate-orm-core and vert.x versions"
doLast {
def hibernateCoreVersion = "n/a"
def vertxVersion = "n/a"

// Resolve Hibernate Core and Vert.x versions from compile classpath
configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.each { artifact ->
if (artifact.moduleVersion.id.name == 'hibernate-core') {
hibernateCoreVersion = artifact.moduleVersion.id.version
}
if (artifact.moduleVersion.id.group == 'io.vertx' && artifact.moduleVersion.id.name == 'vertx-sql-client') {
vertxVersion = artifact.moduleVersion.id.version
}
}

// Print the resolved versions
println "Resolved Hibernate ORM Core Version: ${hibernateCoreVersion}"
println "Resolved Vert.x SQL client Version: ${vertxVersion}"
}
}

// Make the version printing task run before tests and JavaExec tasks
tasks.withType( Test ).configureEach {
dependsOn printResolvedVersions
}

tasks.withType( JavaExec ).configureEach {
dependsOn printResolvedVersions
}
118 changes: 7 additions & 111 deletions hibernate-reactive-core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
plugins {
id "hr-java-library"
id "hr-test-containers"
id "hr-print-resolved-version"
}

ext {
mavenPomName = 'Hibernate Reactive Core'
mavenPomName = 'Hibernate Reactive Core'
}

description = 'The core module of Hibernate Reactive'
Expand Down Expand Up @@ -90,113 +96,3 @@ tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
}

// Print a summary of the results of the tests (number of failures, successes and skipped)
def loggingSummary(db, result, desc) {
if ( !desc.parent ) { // will match the outermost suite
def output = "${db} results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} passed, ${result.failedTestCount} failed, ${result.skippedTestCount} skipped)"
def repeatLength = output.length() + 1
logger.lifecycle '\n' + ('-' * repeatLength) + '\n' + output + '\n' + ('-' * repeatLength)
}
}

// Example:
// gradle test -Pdb=MySQL
test {
def selectedDb = project.hasProperty( 'db' )
? project.properties['db']
: 'PostgreSQL'
doFirst {
systemProperty 'db', selectedDb
}
afterSuite { desc, result ->
loggingSummary( selectedDb, result, desc )
}
}

// Configuration for the tests
tasks.withType( Test ).configureEach {
defaultCharacterEncoding = "UTF-8"
useJUnitPlatform()
testLogging {
showStandardStreams = project.hasProperty('showStandardOutput')
showStackTraces = true
exceptionFormat = 'full'
displayGranularity = 1
events = ['PASSED', 'FAILED', 'SKIPPED']
}
systemProperty 'docker', project.hasProperty( 'docker' ) ? 'true' : 'false'
systemProperty 'org.hibernate.reactive.common.InternalStateAssertions.ENFORCE', 'true'

if ( project.hasProperty( 'includeTests' ) ) {
// Example: ./gradlew testAll -PincludeTests=DefaultPortTest
filter {
includeTestsMatching project.properties['includeTests'] ?: '*' as String
}
}
}

def createTestDbTask(dbName) {
tasks.register( "testDb${dbName}", Test ) {
description = "Run tests for ${dbName}"

doFirst() {
systemProperty 'db', dbName
}
afterSuite { desc, result ->
loggingSummary( dbName, result, desc )
}
}
}

// Rule to recognize calls to testDb<dbName>
// and run the tests on the selected db
// Example:
// gradle testDbMySQL testDbDB2
tasks.addRule( "Pattern testDb<id>" ) { String taskName ->
if ( taskName.startsWith( "testDb" ) ) {
def dbName = taskName.substring( "testDb".length() )
createTestDbTask( dbName )
}
}

// The dbs we want to test when running testAll
def dbs = ['MariaDB', 'MySQL', 'PostgreSQL', 'DB2', 'CockroachDB', 'MSSQLServer', 'Oracle']
dbs.forEach { createTestDbTask it }

tasks.register( "testAll", Test ) {
description = "Run tests for ${dbs}"
dependsOn = dbs.collect( [] as HashSet ) { db -> "testDb${db}" }
}

// Task to print the resolved versions of Hibernate ORM and Vert.x
tasks.register( "printResolvedVersions" ) {
description = "Print the resolved hibernate-orm-core and vert.x versions"
doLast {
def hibernateCoreVersion = "n/a"
def vertxVersion = "n/a"

// Resolve Hibernate Core and Vert.x versions from compile classpath
configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.each { artifact ->
if (artifact.moduleVersion.id.name == 'hibernate-core') {
hibernateCoreVersion = artifact.moduleVersion.id.version
}
if (artifact.moduleVersion.id.group == 'io.vertx' && artifact.moduleVersion.id.name == 'vertx-sql-client') {
vertxVersion = artifact.moduleVersion.id.version
}
}

// Print the resolved versions
println "Resolved Hibernate ORM Core Version: ${hibernateCoreVersion}"
println "Resolved Vert.x SQL client Version: ${vertxVersion}"
}
}

// Make the version printing task run before tests and JavaExec tasks
tasks.withType( Test ).configureEach {
dependsOn printResolvedVersions
}

tasks.withType( JavaExec ).configureEach {
dependsOn printResolvedVersions
}
Loading
Loading