diff --git a/build.gradle b/build.gradle index d6a172b6f..7a45d616b 100644 --- a/build.gradle +++ b/build.gradle @@ -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') diff --git a/documentation/build.gradle b/documentation/build.gradle index 95c3dcb2b..01c67f967 100644 --- a/documentation/build.gradle +++ b/documentation/build.gradle @@ -4,6 +4,7 @@ import java.time.Year plugins { id "org.asciidoctor.jvm.convert" + id "hr-java-library" } ext { diff --git a/examples/native-sql-example/build.gradle b/examples/native-sql-example/build.gradle index 7c3b1d875..c1239deeb 100644 --- a/examples/native-sql-example/build.gradle +++ b/examples/native-sql-example/build.gradle @@ -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) } @@ -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 -} - diff --git a/examples/session-example/build.gradle b/examples/session-example/build.gradle index 2fb7837b6..795fc3fb0 100644 --- a/examples/session-example/build.gradle +++ b/examples/session-example/build.gradle @@ -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) } @@ -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 -} diff --git a/hibernate-reactive-core/build.gradle b/hibernate-reactive-core/build.gradle index 91ee72f89..97c1b8bd8 100644 --- a/hibernate-reactive-core/build.gradle +++ b/hibernate-reactive-core/build.gradle @@ -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' @@ -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 -// and run the tests on the selected db -// Example: -// gradle testDbMySQL testDbDB2 -tasks.addRule( "Pattern testDb" ) { 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 -} diff --git a/integration-tests/bytecode-enhancements-it/build.gradle b/integration-tests/bytecode-enhancements-it/build.gradle index a796557dd..74ee2d563 100644 --- a/integration-tests/bytecode-enhancements-it/build.gradle +++ b/integration-tests/bytecode-enhancements-it/build.gradle @@ -10,6 +10,9 @@ buildscript { } plugins { + id "hr-java-library" + id "hr-test-containers" + alias(libs.plugins.org.hibernate.orm) } @@ -40,72 +43,3 @@ dependencies { // Optional: enable the bytecode enhancements hibernate { enhancement } - -// Print a summary of the results of the tests (number of failures, successes and skipped) -// This is the same as the one in hibernate-reactive-core -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 { - displayGranularity 1 - showStandardStreams = project.hasProperty('showStandardOutput') - showStackTraces = true - exceptionFormat = 'full' - 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 - } - } -} - -// Rule to recognize calls to testDb -// and run the tests on the selected db -// Example: -// gradle testDbMySQL testDbDB2 -tasks.addRule( "Pattern testDb" ) { String taskName -> - if ( taskName.startsWith( "testDb" ) ) { - tasks.register( taskName, Test ) { - def dbName = taskName.substring( "testDb".length() ) - description = "Run tests for ${dbName}" - - // We only want to test this on Postgres - onlyIf { dbName.toLowerCase().startsWith( 'p' ) } - doFirst() { - systemProperty 'db', dbName - } - afterSuite { desc, result -> - loggingSummary( dbName, result, desc ) - } - - } - } -} \ No newline at end of file diff --git a/integration-tests/hibernate-validator-postgres-it/build.gradle b/integration-tests/hibernate-validator-postgres-it/build.gradle index 38165df4d..aae2818e6 100644 --- a/integration-tests/hibernate-validator-postgres-it/build.gradle +++ b/integration-tests/hibernate-validator-postgres-it/build.gradle @@ -10,9 +10,17 @@ buildscript { } plugins { + id "hr-java-library" + id "hr-test-containers" + alias(libs.plugins.org.hibernate.orm) } +test { + def db = project.properties['db'] + enabled = db == null || db.equals( 'PostgreSQL' ) +} + description = 'Quarkus QE integration tests' dependencies { @@ -43,72 +51,3 @@ dependencies { // Optional: enable the bytecode enhancements //hibernate { enhancement } -// Print a summary of the results of the tests (number of failures, successes and skipped) -// This is the same as the one in hibernate-reactive-core -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 { - displayGranularity 1 - showStandardStreams = project.hasProperty('showStandardOutput') - showStackTraces = true - exceptionFormat = 'full' - 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 - } - } -} - - -// Rule to recognize calls to testDb -// and run the tests on the selected db -// Example: -// gradle testDbMySQL testDbDB2 -tasks.addRule( "Pattern testDb" ) { String taskName -> - if ( taskName.startsWith( "testDb" ) ) { - tasks.register( taskName, Test ) { - def dbName = taskName.substring( "testDb".length() ) - description = "Run tests for ${dbName}" - - // We only want to test this on Postgres - onlyIf { dbName.toLowerCase().startsWith( 'p' ) } - doFirst() { - systemProperty 'db', dbName - } - afterSuite { desc, result -> - loggingSummary( dbName, result, desc ) - } - - } - } -} \ No newline at end of file diff --git a/integration-tests/techempower-postgres-it/build.gradle b/integration-tests/techempower-postgres-it/build.gradle index b5f74f4d2..b44b3f7a6 100644 --- a/integration-tests/techempower-postgres-it/build.gradle +++ b/integration-tests/techempower-postgres-it/build.gradle @@ -9,6 +9,16 @@ buildscript { } } +plugins { + id "hr-java-library" + id "hr-test-containers" +} + +test { + def db = project.properties['db'] + enabled = db == null || db.equals( 'PostgreSQL' ) +} + description = 'TechEmpower integration tests' dependencies { @@ -32,51 +42,6 @@ dependencies { testImplementation(libs.io.vertx.vertx.junit5) } -// 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'] - } - - // We need a to use an instance of PostgreSQL with a specific configuration. - // So, for this particular integration-test module, we default to true unless docker is disabled. - systemProperty 'docker', project.hasProperty('docker') - systemProperty 'org.hibernate.reactive.common.InternalStateAssertions.ENFORCE', 'true' - - if ( project.hasProperty( 'includeTests' ) ) { - // Example: ./gradlew testAll -PincludeTests=DefaultPortTest - filter { - includeTestsMatching project.properties['includeTests'] ?: '*' as String - } - } -} - -// Print a summary of the results of the tests (number of failures, successes and skipped) -// This is the same as the one in hibernate-reactive-core -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) - } -} - -test { - doFirst { - systemProperty 'db', 'PostgreSQL' - } - // We only want to test this on Postgres - afterSuite { desc, result -> - loggingSummary( 'PostgreSQL', result, desc ) - } -} - def javaMainClass = "org.hibernate.reactive.it.techempower.VertxServer" jar { dependsOn = [':hibernate-reactive-core:jar'] diff --git a/integration-tests/verticle-postgres-it/build.gradle b/integration-tests/verticle-postgres-it/build.gradle index 7d2322306..f8622ab95 100644 --- a/integration-tests/verticle-postgres-it/build.gradle +++ b/integration-tests/verticle-postgres-it/build.gradle @@ -9,6 +9,16 @@ buildscript { } } +plugins { + id 'hr-java-library' + id 'hr-test-containers' +} + +test { + def db = project.properties['db'] + enabled = db == null || db.equals( 'PostgreSQL' ) +} + description = 'Bytecode enhancements integration tests' dependencies { @@ -32,75 +42,6 @@ dependencies { testImplementation(libs.io.vertx.vertx.junit5) } -// 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' ) - systemProperty 'org.hibernate.reactive.common.InternalStateAssertions.ENFORCE', 'true' - - if ( project.hasProperty( 'includeTests' ) ) { - // Example: ./gradlew testAll -PincludeTests=DefaultPortTest - filter { - includeTestsMatching project.getProperty( 'includeTests' ) ?: '*' - } - } -} - -// Print a summary of the results of the tests (number of failures, successes and skipped) -// This is the same as the one in hibernate-reactive-core -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 ) - } -} - -// Rule to recognize calls to testDb -// and run the tests on the selected db -// Example: -// gradle testDbMySQL testDbDB2 -tasks.addRule( "Pattern testDb" ) { String taskName -> - if ( taskName.startsWith( "testDb" ) ) { - tasks.register( taskName, Test ) { - def dbName = taskName.substring( "testDb".length() ) - description = "Run tests for ${dbName}" - - // We only want to test this on Postgres - onlyIf { dbName.toLowerCase().startsWith( 'p' ) } - doFirst() { - systemProperty 'db', dbName - } - afterSuite { desc, result -> - loggingSummary( dbName, result, desc ) - } - - } - } -} - tasks.register( "startVertx", JavaExec ) { description = "Starts the Vert.x Server app" classpath = sourceSets.main.runtimeClasspath diff --git a/local-build-plugins/build.gradle b/local-build-plugins/build.gradle index 7cc4db2f9..2389343d6 100644 --- a/local-build-plugins/build.gradle +++ b/local-build-plugins/build.gradle @@ -1,5 +1,6 @@ plugins { id "java-gradle-plugin" + id 'groovy-gradle-plugin' } repositories { diff --git a/local-build-plugins/src/main/groovy/hr-java-library.gradle b/local-build-plugins/src/main/groovy/hr-java-library.gradle new file mode 100644 index 000000000..4f372fe21 --- /dev/null +++ b/local-build-plugins/src/main/groovy/hr-java-library.gradle @@ -0,0 +1,110 @@ +plugins{ + id 'java-library' + id '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}'" + } + } +} diff --git a/local-build-plugins/src/main/groovy/hr-print-resolved-version.gradle b/local-build-plugins/src/main/groovy/hr-print-resolved-version.gradle new file mode 100644 index 000000000..9dea09b82 --- /dev/null +++ b/local-build-plugins/src/main/groovy/hr-print-resolved-version.gradle @@ -0,0 +1,31 @@ +// 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 +} \ No newline at end of file diff --git a/local-build-plugins/src/main/groovy/hr-test-containers.gradle b/local-build-plugins/src/main/groovy/hr-test-containers.gradle new file mode 100644 index 000000000..fad66398f --- /dev/null +++ b/local-build-plugins/src/main/groovy/hr-test-containers.gradle @@ -0,0 +1,79 @@ +// 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 + + doFirst { + selectedDb = project.hasProperty( 'db' ) + ? project.properties['db'] + : 'PostgreSQL' + 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 +// and run the tests on the selected db +// Example: +// gradle testDbMySQL testDbDB2 +tasks.addRule( "Pattern testDb" ) { 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}" } +} diff --git a/local-build-plugins/src/main/java/org/hibernate/reactive/env/VersionsPlugin.java b/local-build-plugins/src/main/java/org/hibernate/reactive/env/VersionsPlugin.java index c34a4b479..883317d4a 100644 --- a/local-build-plugins/src/main/java/org/hibernate/reactive/env/VersionsPlugin.java +++ b/local-build-plugins/src/main/java/org/hibernate/reactive/env/VersionsPlugin.java @@ -58,7 +58,7 @@ public void apply(Project project) { project.getLogger().lifecycle( "Development version: n/a" ); } - final VersionsTomlParser tomlParser = new VersionsTomlParser( RELATIVE_CATALOG ); + final VersionsTomlParser tomlParser = new VersionsTomlParser( project.getRootProject().file( RELATIVE_CATALOG ) ); final String ormVersionString = determineOrmVersion( project, tomlParser ); final Object ormVersion = resolveOrmVersion( ormVersionString, project ); project.getLogger().lifecycle( "ORM version: {}", ormVersion ); diff --git a/local-build-plugins/src/main/java/org/hibernate/reactive/env/VersionsTomlParser.java b/local-build-plugins/src/main/java/org/hibernate/reactive/env/VersionsTomlParser.java index b0adafd6d..8833de6a6 100644 --- a/local-build-plugins/src/main/java/org/hibernate/reactive/env/VersionsTomlParser.java +++ b/local-build-plugins/src/main/java/org/hibernate/reactive/env/VersionsTomlParser.java @@ -1,6 +1,7 @@ package org.hibernate.reactive.env; import java.io.BufferedReader; +import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.HashMap; @@ -13,11 +14,12 @@ public class VersionsTomlParser { private final Map data = new HashMap<>(); - public VersionsTomlParser(String filePath) { + public VersionsTomlParser(File filePath) { parse( filePath ); } - private void parse(String filePath) { + private void parse(File filePath) { + try ( BufferedReader reader = new BufferedReader( new FileReader( filePath ) ) ) { String line; String currentSection = null; diff --git a/release/build.gradle b/release/build.gradle index 690534750..4e5321f9a 100644 --- a/release/build.gradle +++ b/release/build.gradle @@ -1,5 +1,8 @@ import java.nio.charset.StandardCharsets +plugins { + id "hr-java-library" +} ext { // Select which repository to use for publishing the documentation // Example: