Skip to content
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

HHH-13682 Generate Java 11/13/14 bytecode for tests when building with JDK11/13/14 #3329

Merged
merged 6 commits into from
Apr 14, 2020
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ task release {
// Force to release with JDK 8. Releasing with JDK 11 is not supported yet:
// - the hibernate-orm-modules tests do not run due to an issue with the ASM version currently used by Gradle
doFirst {
if ( !JavaVersion.current().isJava8() ) {
if ( !JavaVersion.current().isJava8() || !gradle.ext.testedJavaVersionAsEnum.isJava8() ) {
throw new IllegalStateException( "Please use JDK 8 to perform the release." )
}
}
Expand Down
4 changes: 1 addition & 3 deletions documentation/documentation.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ task aggregateJavadocs(type: Javadoc) {
options.source = project.baselineJavaVersion
}

if ( JavaVersion.current().isJava8Compatible() ) {
options.addStringOption( 'Xdoclint:none', '-quiet' )
}
options.addStringOption( 'Xdoclint:none', '-quiet' )
}

// process each project, building up:
Expand Down
32 changes: 14 additions & 18 deletions gradle/java-module.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'de.thetaphi:forbiddenapis:2.6'
classpath 'de.thetaphi:forbiddenapis:2.7'
}
}

Expand Down Expand Up @@ -38,10 +38,6 @@ ext {
forbiddenAPITargetJDKCompatibility = '11'
}


sourceCompatibility = project.baselineJavaVersion
targetCompatibility = project.baselineJavaVersion

if ( !project.description ) {
project.description = "The Hibernate ORM $project.name module"
}
Expand Down Expand Up @@ -115,8 +111,20 @@ dependencies {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Compilation

tasks.withType(JavaCompile) {
tasks.withType( JavaCompile ) {
options.encoding = 'UTF-8'
sourceCompatibility = project.baselineJavaVersion
targetCompatibility = project.baselineJavaVersion
}

if ( project.baselineJavaVersion != gradle.ext.testedJavaVersion ) {
logger.info( "Forcing the target bytecode version for test classes to '$gradle.ext.testedJavaVersion'" )

tasks.compileTestJava {
// For *tests only*, generate bytecode matching the Java version currently in use.
// This allows testing bytecode enhancement on the latest Java versions (13, 14, ...).
targetCompatibility = gradle.ext.testedJavaVersion
}
}

task compile(dependsOn: [compileJava, processResources, compileTestJava, processTestResources] )
Expand Down Expand Up @@ -200,18 +208,6 @@ processTestResources {
}
}

// Enable the experimental features of ByteBuddy with JDK 12+
test {
//Only safe to attempt to parse the version as an integer since JDK11
if ( JavaVersion.current().isJava11Compatible() ) {
int majorJVMVersionInt = Integer.valueOf(JavaVersion.current().toString());
//Set the -Dnet.bytebuddy.experimental=true property only when we need it:
if (majorJVMVersionInt >= 12) {
systemProperty 'net.bytebuddy.experimental', true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer need this? Perhaps the check should be bumped to >= 15 ? It's kinda a pattern for ByteBuddy to only support the "work in progress" JDKs when this flag is on. I didn't check if the strategy changed.

}
}
}

test {
if ( project.findProperty( 'log-test-progress' )?.toString()?.toBoolean() ) {
// Log a statement for each test.
Expand Down
4 changes: 1 addition & 3 deletions gradle/published-java-module.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ javadoc {
options.source = project.baselineJavaVersion
}

if ( JavaVersion.current().isJava8Compatible() ) {
options.addStringOption( 'Xdoclint:none', '-quiet' )
}
options.addStringOption( 'Xdoclint:none', '-quiet' )

doFirst {
// ordering problems if we try to do this during config phase :(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
@SuppressWarnings({"unused", "WeakerAccess","ResultOfMethodCallIgnored"})
@TestForIssue( jiraKey = "HHH-13607" )
@RunWith( BytecodeEnhancerRunner.class )
@EnhancementOptions( lazyLoading = true )
@EnhancementOptions( lazyLoading = true, extendedEnhancement = true )
public class NaturalIdInUninitializedAssociationTest extends BaseNonConfigCoreFunctionalTestCase {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ apply from: rootProject.file( 'gradle/java-module.gradle' )
// so we have to use https://github.com/java9-modularity/gradle-modules-plugin
apply plugin: "org.javamodularity.moduleplugin"

// Override -source and -target
ext.baselineJavaVersion = 11
sourceCompatibility = project.baselineJavaVersion
targetCompatibility = project.baselineJavaVersion
// Override -source and -target to the version being tested (11+, since this module is enabled)
ext.baselineJavaVersion = gradle.ext.testedJavaVersion
tasks.withType( JavaCompile ) {
sourceCompatibility = project.baselineJavaVersion
targetCompatibility = project.baselineJavaVersion
}

// Checkstyle fails for module-info
checkstyleMain.exclude '**/module-info.java'
Expand Down
31 changes: 30 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,36 @@ plugins {
}

if ( !JavaVersion.current().java8Compatible ) {
throw new GradleException( "Gradle must be run with Java 8" )
throw new GradleException( "Gradle must be run with Java 8 or later" )
}

// Consume the property 'testedJavaVersion' here and
// set it on gradle.ext so that we can inspect the result in build.gradle.
// We wouldn't be able to do that if we consumed
// the property in base-information.gradle and set it on project.ext.

if ( hasProperty( 'testedJavaVersion' ) ) {
logger.warn( "[WARN] Targeting Java version '$testedJavaVersion' in tests." )
gradle.ext.testedJavaVersion = testedJavaVersion
gradle.ext.testedJavaVersionAsEnum = JavaVersion.toVersion( testedJavaVersion )
}
else {
// We will simply use Gradle's JDK for compilation, tests and javadoc generation.
def major
if ( JavaVersion.current() == JavaVersion.VERSION_HIGHER) {
logger.warn( "Gradle does not support this JDK, because it is too recent; build is likely to fail." +
" To avoid failures, you should specify an older Java version in the 'testedJavaVersion' parameter." +
" Just append the following to your gradle command:" +
" '-PtestedJavaVersion=<major version of your newer JDK, e.g. 14>'" )
// Use a hack to retrieve the major as a string.
// This only works for Java 9+ (we're at least on Java 18 here).
gradle.ext.testedJavaVersion = System.getProperty( 'java.specification.version' )
}
else {
gradle.ext.testedJavaVersion = JavaVersion.current().getMajorVersion()
}

gradle.ext.testedJavaVersionAsEnum = JavaVersion.current()
}

include 'hibernate-core'
Expand Down