HHH-14709 Move to Gradle's built-in way of testing Java modules

This commit is contained in:
Yoann Rodière 2021-07-06 09:49:35 +02:00
parent 15f30bd338
commit c78a0a2b16
8 changed files with 48 additions and 77 deletions

View File

@ -7,57 +7,22 @@
description = 'Integration tests for running Hibernate ORM in the Java module path'
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.javamodularity:moduleplugin:1.5.0"
}
}
apply from: rootProject.file( 'gradle/java-module.gradle' )
// No first-class, built-in support for Java modules in Gradle yet,
// so we have to use https://github.com/java9-modularity/gradle-modules-plugin
apply plugin: "org.javamodularity.moduleplugin"
// In this module, the "main" code is actually just test code that happens
// to be built independently so as to generate a Java module.
// So, let's override settings for compilation of the main code, just for this particular case.
def testJavaVersions = gradle.ext.javaVersions.test
tasks.compileJava {
if ( !gradle.ext.javaToolchainEnabled ) {
sourceCompatibility = JavaVersion.toVersion( testJavaVersions.release )
targetCompatibility = JavaVersion.toVersion( testJavaVersions.release )
}
else {
javaCompiler = javaToolchains.compilerFor {
languageVersion = testJavaVersions.compiler
}
// Remove JDK8-only options (if any) that are incompatible with options.release
for ( it = options.compilerArgs.listIterator(); it.hasNext(); ) {
if ( it.next() in ['-source', '-target'] ) {
it.remove()
it.next()
it.remove()
}
}
options.release = testJavaVersions.release.asInt()
}
// See https://docs.gradle.org/6.7.1/userguide/java_testing.html#blackbox_integration_testing
// See https://docs.gradle.org/6.7.1/samples/sample_java_modules_multi_project_with_integration_tests.html
java {
modularity.inferModulePath = true
}
// Checkstyle fails for module-info
checkstyleMain.exclude '**/module-info.java'
dependencies {
compile( project( ':hibernate-core' ) )
compile( project( ':hibernate-envers' ) )
compile( libraries.jpa )
testCompile( project( ':hibernate-core' ) )
testCompile( project( ':hibernate-envers' ) )
testCompile( libraries.jpa )
testCompile( libraries.junit )
}
test {

View File

@ -1,28 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
module org.hibernate.orm.integrationtest.java.module {
exports org.hibernate.orm.integrationtest.java.module.service;
opens org.hibernate.orm.integrationtest.java.module.entity to
org.hibernate.orm.core,
javassist; // Necessary for javassist, but not for bytebuddy (the default)
requires java.persistence;
/*
* IDEA will not find the modules below because it apparently doesn't support automatic module names
* for modules in the current project.
* Everything should work fine when building from the command line, though.
*/
requires org.hibernate.orm.core;
requires org.hibernate.orm.envers;
/*
* This is necessary in order to use SessionFactory,
* which extends "javax.naming.Referenceable".
* Without this, compilation as a Java module fails.
*/
requires java.naming;
}

View File

@ -0,0 +1,34 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
module org.hibernate.orm.integrationtest.java.module.test {
/*
* Main configuration, necessary for real client applications.
*/
opens org.hibernate.orm.integrationtest.java.module.test.entity to
org.hibernate.orm.core,
javassist; // Necessary for javassist, but not for bytebuddy (the default)
requires java.persistence;
// IDEA will not find the modules below because it apparently doesn't support automatic module names
// for modules in the current project.
// Everything should work fine when building from the command line, though.
requires org.hibernate.orm.core;
requires org.hibernate.orm.envers;
// Transitive dependencies that leak through the Hibernate ORM API
requires java.sql;
requires java.naming; // SessionFactory extends "javax.naming.Referenceable"
/*
* Test-only configuration.
*/
opens org.hibernate.orm.integrationtest.java.module.test to junit;
requires junit;
}

View File

@ -11,7 +11,7 @@ import java.util.Arrays;
import org.hibernate.Session;
import org.hibernate.envers.boot.internal.EnversIntegrator;
import org.hibernate.orm.integrationtest.java.module.service.AuthorService;
import org.hibernate.orm.integrationtest.java.module.test.service.AuthorService;
import org.junit.Assert;
import org.junit.Test;

View File

@ -15,7 +15,7 @@ import org.hibernate.boot.archive.scan.internal.StandardScanParameters;
import org.hibernate.boot.archive.scan.internal.StandardScanner;
import org.hibernate.boot.archive.scan.spi.ClassDescriptor;
import org.hibernate.boot.archive.scan.spi.ScanResult;
import org.hibernate.orm.integrationtest.java.module.entity.Author;
import org.hibernate.orm.integrationtest.java.module.test.entity.Author;
import org.junit.Assert;
import org.junit.Test;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.orm.integrationtest.java.module.entity;
package org.hibernate.orm.integrationtest.java.module.test.entity;
import javax.persistence.Basic;
import javax.persistence.Entity;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.orm.integrationtest.java.module.service;
package org.hibernate.orm.integrationtest.java.module.test.service;
import java.util.List;
@ -14,7 +14,7 @@ import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.envers.AuditReader;
import org.hibernate.envers.AuditReaderFactory;
import org.hibernate.orm.integrationtest.java.module.entity.Author;
import org.hibernate.orm.integrationtest.java.module.test.entity.Author;
public class AuthorService implements AutoCloseable {

View File

@ -10,7 +10,7 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="primaryPU">
<class>org.hibernate.orm.integrationtest.java.module.entity.Author</class>
<class>org.hibernate.orm.integrationtest.java.module.test.entity.Author</class>
<properties>
<property name="hibernate.connection.driver_class" value="org.h2.Driver"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>