From 4cf5fe55dd3674fe632d9bb87a93fe9649aa4e50 Mon Sep 17 00:00:00 2001 From: Shams Asari Date: Wed, 6 Dec 2023 09:46:29 +0000 Subject: [PATCH] ENT-11099: Update Java compile source & target to 17 (#7594) And removed unused `jdkClassifier` in build files. --- build.gradle | 50 +++++++------------ constants.properties | 1 - .../net/corda/core/internal/InternalUtils.kt | 4 +- .../internal/AttachmentsClassLoader.kt | 6 +-- node/capsule/build.gradle | 16 +++--- .../cordapp/JarScanningCordappLoader.kt | 4 +- testing/testserver/testcapsule/build.gradle | 18 +++---- tools/explorer/build.gradle | 2 - tools/explorer/capsule/build.gradle | 10 ++-- tools/network-builder/build.gradle | 5 +- 10 files changed, 47 insertions(+), 69 deletions(-) diff --git a/build.gradle b/build.gradle index b49e20b9e4..7bdd1871cb 100644 --- a/build.gradle +++ b/build.gradle @@ -1,9 +1,11 @@ import com.r3.testing.DistributeTestsBy import com.r3.testing.PodLogLevel +import net.corda.plugins.apiscanner.GenerateApi +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import static org.gradle.api.JavaVersion.VERSION_11 +import static org.gradle.api.JavaVersion.VERSION_17 +import static org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 import static org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_8 -import static org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11 buildscript { // For sharing constants between builds @@ -28,8 +30,6 @@ buildscript { // Set version of Quasar according to version of Java used: ext.quasar_version = constants.getProperty("quasarVersion") ext.quasar_classifier = constants.getProperty("quasarClassifier") - ext.jdkClassifier = constants.getProperty("jdkClassifier") - ext.cordaScanApiClassifier = jdkClassifier ext.quasar_exclusions = [ 'co.paralleluniverse**', 'groovy**', @@ -238,21 +238,11 @@ if (ext.versionSuffix != ""){ ext.corda_release_version = "${ext.baseVersion}".toString() } -// We need the following three lines even though they're inside an allprojects {} block below because otherwise -// IntelliJ gets confused when importing the project and ends up erasing and recreating the .idea directory, along -// with the run configurations. It also doesn't realise that the project is a Java 8 project and misconfigures -// the resulting import. This fixes it. -apply plugin: 'java' - -logger.lifecycle("Java version: {}", JavaVersion.current()) -sourceCompatibility = VERSION_11 -targetCompatibility = VERSION_11 -logger.lifecycle("Java source compatibility: {}", sourceCompatibility) -logger.lifecycle("Java target compatibility: {}", targetCompatibility) +logger.lifecycle("JDK: {}", System.getProperty("java.home")) logger.lifecycle("Quasar version: {}", quasar_version) logger.lifecycle("Quasar classifier: {}", quasar_classifier.toString()) logger.lifecycle("Building Corda version: {}", corda_release_version) -logger.lifecycle("User Home: |{}|", System.getProperty('user.home')) +logger.lifecycle("User home: {}", System.getProperty('user.home')) allprojects { apply plugin: 'org.jetbrains.kotlin.jvm' @@ -283,8 +273,9 @@ allprojects { nugetconfEnabled = false } } - sourceCompatibility = VERSION_11 - targetCompatibility = VERSION_11 + + sourceCompatibility = VERSION_17 + targetCompatibility = VERSION_17 jacoco { // JDK11 official support (https://github.com/jacoco/jacoco/releases/tag/v0.8.3) @@ -308,11 +299,11 @@ allprojects { options.encoding = 'UTF-8' } - tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { + tasks.withType(KotlinCompile).configureEach { compilerOptions { languageVersion = KOTLIN_1_8 apiVersion = KOTLIN_1_8 - jvmTarget = JVM_11 + jvmTarget = JVM_17 javaParameters = true // Useful for reflection. freeCompilerArgs = ['-Xjvm-default=all-compatibility'] allWarningsAsErrors = warnings_as_errors @@ -366,13 +357,6 @@ allprojects { } } - if (jdkClassifier) { - jar { - // JDK11 built and published artifacts to include classifier - archiveClassifier = jdkClassifier - } - } - group 'net.corda' version "$corda_release_version" @@ -561,7 +545,7 @@ jar { enabled = false } -task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) { +tasks.register('jacocoRootReport', JacocoReport) { dependsOn = subprojects.test // additionalSourceDirs = files(subprojects.sourceSets.main.allSource.srcDirs) // sourceDirectories = files(subprojects.sourceSets.main.allSource.srcDirs) @@ -590,13 +574,13 @@ tasks.register('detekt', JavaExec) { def plugins = detektPluginsJar.outputs.files.singleFile def params = ['-i', input, '-c', config, '-b', baseline, '--plugins', plugins] inputs.files(detektPluginsJar, config, baseline) - main = "io.gitlab.arturbosch.detekt.cli.Main" + mainClass = "io.gitlab.arturbosch.detekt.cli.Main" classpath = configurations.detekt args(params) } tasks.register('detektBaseline', JavaExec) { - main = "io.gitlab.arturbosch.detekt.cli.Main" + mainClass = "io.gitlab.arturbosch.detekt.cli.Main" classpath = configurations.detekt def input = "$projectDir" def config = "$projectDir/detekt-config.yml, $projectDir/detekt-baseline-config.yml" @@ -609,7 +593,7 @@ tasks.withType(Test).configureEach { reports.html.destination = file("${reporting.baseDir}/${name}") } -task testReport(type: TestReport) { +tasks.register('testReport', TestReport) { destinationDir = file("$buildDir/reports/allTests") // Include the results from the `test` task in all subprojects reportOn subprojects*.test @@ -617,7 +601,7 @@ task testReport(type: TestReport) { // Note: corda.jar is used at runtime so no runtime ZIP is necessary. // Resulting ZIP can be found in "build/distributions" -task buildCordappDependenciesZip(type: Zip) { +tasks.register('buildCordappDependenciesZip', Zip) { baseName 'corda-deps' from configurations.runtimeOnly from configurations.implementation @@ -627,7 +611,7 @@ task buildCordappDependenciesZip(type: Zip) { duplicatesStrategy = DuplicatesStrategy.EXCLUDE } -tasks.register('generateApi', net.corda.plugins.apiscanner.GenerateApi) { +tasks.register('generateApi', GenerateApi) { baseName = "api-corda" } diff --git a/constants.properties b/constants.properties index 4b26cce0db..253479c6f3 100644 --- a/constants.properties +++ b/constants.properties @@ -19,7 +19,6 @@ openTelemetrySemConvVersion=1.20.1-alpha guavaVersion=28.0-jre # Quasar version to use with Java 8: quasarVersion=0.9.0_r3 -jdkClassifier11=jdk11 dockerJavaVersion=3.2.5 proguardVersion=7.3.1 // bouncy castle version must not be changed on a patch release. Needs a full release test cycle to flush out any issues. diff --git a/core/src/main/kotlin/net/corda/core/internal/InternalUtils.kt b/core/src/main/kotlin/net/corda/core/internal/InternalUtils.kt index 2d050bfc12..7ad05fe75c 100644 --- a/core/src/main/kotlin/net/corda/core/internal/InternalUtils.kt +++ b/core/src/main/kotlin/net/corda/core/internal/InternalUtils.kt @@ -616,5 +616,5 @@ fun Logger.warnOnce(warning: String) { } } -const val JDK1_2_CLASS_FILE_FORMAT_MAJOR_VERSION = 46 -const val JDK11_CLASS_FILE_FORMAT_MAJOR_VERSION = 55 +const val JAVA_1_2_CLASS_FILE_FORMAT_MAJOR_VERSION = 46 +const val JAVA_17_CLASS_FILE_FORMAT_MAJOR_VERSION = 61 diff --git a/core/src/main/kotlin/net/corda/core/serialization/internal/AttachmentsClassLoader.kt b/core/src/main/kotlin/net/corda/core/serialization/internal/AttachmentsClassLoader.kt index c58e4283d1..9fb84cb85c 100644 --- a/core/src/main/kotlin/net/corda/core/serialization/internal/AttachmentsClassLoader.kt +++ b/core/src/main/kotlin/net/corda/core/serialization/internal/AttachmentsClassLoader.kt @@ -8,8 +8,8 @@ import net.corda.core.contracts.TransactionVerificationException import net.corda.core.contracts.TransactionVerificationException.OverlappingAttachmentsException import net.corda.core.contracts.TransactionVerificationException.PackageOwnershipException import net.corda.core.crypto.SecureHash -import net.corda.core.internal.JDK1_2_CLASS_FILE_FORMAT_MAJOR_VERSION -import net.corda.core.internal.JDK11_CLASS_FILE_FORMAT_MAJOR_VERSION +import net.corda.core.internal.JAVA_1_2_CLASS_FILE_FORMAT_MAJOR_VERSION +import net.corda.core.internal.JAVA_17_CLASS_FILE_FORMAT_MAJOR_VERSION import net.corda.core.internal.JarSignatureCollector import net.corda.core.internal.NamedCacheFactory import net.corda.core.internal.PlatformVersionSwitches @@ -363,7 +363,7 @@ object AttachmentsClassLoaderBuilder { val transactionClassLoader = AttachmentsClassLoader(attachments, key.params, txId, isAttachmentTrusted, parent) val serializers = try { createInstancesOfClassesImplementing(transactionClassLoader, SerializationCustomSerializer::class.java, - JDK1_2_CLASS_FILE_FORMAT_MAJOR_VERSION..JDK11_CLASS_FILE_FORMAT_MAJOR_VERSION) + JAVA_1_2_CLASS_FILE_FORMAT_MAJOR_VERSION..JAVA_17_CLASS_FILE_FORMAT_MAJOR_VERSION) } catch (ex: UnsupportedClassVersionError) { throw TransactionVerificationException.UnsupportedClassVersionError(txId, ex.message!!, ex) } diff --git a/node/capsule/build.gradle b/node/capsule/build.gradle index 1e0f9a5aeb..d012d8e46e 100644 --- a/node/capsule/build.gradle +++ b/node/capsule/build.gradle @@ -40,20 +40,18 @@ capsule { def nodeProject = project(':node') configurations.runtimeOnly.canBeResolved = true -task buildCordaJAR(type: FatCapsule, dependsOn: [ - nodeProject.tasks.named('jar'), - ]) { +tasks.register('buildCordaJAR', FatCapsule) { + dependsOn(nodeProject.tasks.named('jar')) applicationClass 'net.corda.node.Corda' archiveBaseName = 'corda' archiveVersion = corda_release_version - archiveClassifier = jdkClassifier archiveName = archiveFileName.get() applicationSource = files( - nodeProject.configurations.runtimeClasspath, - nodeProject.tasks.jar, - nodeProject.buildDir.toString() + '/resources/main/corda-reference.conf', - "$rootDir/config/dev/log4j2.xml", - 'NOTICE' // Copy CDDL notice + nodeProject.configurations.runtimeClasspath, + nodeProject.tasks.jar, + nodeProject.buildDir.toString() + '/resources/main/corda-reference.conf', + "$rootDir/config/dev/log4j2.xml", + 'NOTICE' // Copy CDDL notice ) from configurations.capsuleRuntime.files.collect { zipTree(it) } with jar diff --git a/node/src/main/kotlin/net/corda/node/internal/cordapp/JarScanningCordappLoader.kt b/node/src/main/kotlin/net/corda/node/internal/cordapp/JarScanningCordappLoader.kt index c5e2ee9ea7..8fb8e8c671 100644 --- a/node/src/main/kotlin/net/corda/node/internal/cordapp/JarScanningCordappLoader.kt +++ b/node/src/main/kotlin/net/corda/node/internal/cordapp/JarScanningCordappLoader.kt @@ -461,8 +461,8 @@ class JarScanningCordappLoader private constructor(private val cordappJarPaths: } private fun validateClassFileVersion(classInfo: ClassInfo) { - if (classInfo.classfileMajorVersion < JDK1_2_CLASS_FILE_FORMAT_MAJOR_VERSION || - classInfo.classfileMajorVersion > JDK11_CLASS_FILE_FORMAT_MAJOR_VERSION) + if (classInfo.classfileMajorVersion < JAVA_1_2_CLASS_FILE_FORMAT_MAJOR_VERSION || + classInfo.classfileMajorVersion > JAVA_17_CLASS_FILE_FORMAT_MAJOR_VERSION) throw IllegalStateException("Class ${classInfo.name} from jar file ${cordappJarPath.url} has an invalid version of " + "${classInfo.classfileMajorVersion}") } diff --git a/testing/testserver/testcapsule/build.gradle b/testing/testserver/testcapsule/build.gradle index 0ff9a0a662..2566200495 100644 --- a/testing/testserver/testcapsule/build.gradle +++ b/testing/testserver/testcapsule/build.gradle @@ -24,20 +24,20 @@ capsule { } configurations.runtimeOnly.canBeResolved = true -task buildWebserverJar(type: FatCapsule, dependsOn: project(':node').tasks.jar) { +tasks.register('buildWebserverJar', FatCapsule) { + dependsOn project(':node').tasks.jar applicationClass 'net.corda.webserver.WebServer' archiveBaseName = 'corda-testserver' archiveVersion = corda_release_version - archiveClassifier = jdkClassifier archiveName = archiveFileName.get() applicationSource = files( - project(':testing:testserver').configurations.runtimeClasspath, - project(':testing:testserver').tasks.jar, - project(':testing:testserver').sourceSets.main.java.outputDir.toString() + '/CordaWebserverCaplet.class', - project(':testing:testserver').sourceSets.main.java.outputDir.toString() + '/CordaWebserverCaplet$1.class', - project(':node').buildDir.toString() + '/resources/main/corda-reference.conf', - "$rootDir/config/dev/log4j2.xml", - project(':node:capsule').projectDir.toString() + '/NOTICE' // Copy CDDL notice + project(':testing:testserver').configurations.runtimeClasspath, + project(':testing:testserver').tasks.jar, + project(':testing:testserver').sourceSets.main.java.outputDir.toString() + '/CordaWebserverCaplet.class', + project(':testing:testserver').sourceSets.main.java.outputDir.toString() + '/CordaWebserverCaplet$1.class', + project(':node').buildDir.toString() + '/resources/main/corda-reference.conf', + "$rootDir/config/dev/log4j2.xml", + project(':node:capsule').projectDir.toString() + '/NOTICE' // Copy CDDL notice ) from configurations.capsuleRuntime.files.collect { zipTree(it) } diff --git a/tools/explorer/build.gradle b/tools/explorer/build.gradle index bb8353ca7b..f0bbc84f06 100644 --- a/tools/explorer/build.gradle +++ b/tools/explorer/build.gradle @@ -13,11 +13,9 @@ javafx { ] } -apply plugin: 'java' apply plugin: 'org.jetbrains.kotlin.jvm' apply plugin: 'application' -sourceCompatibility = 1.8 mainClassName = 'net.corda.explorer.Main' dependencies { diff --git a/tools/explorer/capsule/build.gradle b/tools/explorer/capsule/build.gradle index c03d1d89bb..add8010d28 100644 --- a/tools/explorer/capsule/build.gradle +++ b/tools/explorer/capsule/build.gradle @@ -15,16 +15,16 @@ capsule { } configurations.runtimeOnly.canBeResolved = true -task buildExplorerJAR(type: FatCapsule, dependsOn: project(':tools:explorer').tasks.jar) { +tasks.register('buildExplorerJAR', FatCapsule) { + dependsOn project(':tools:explorer').tasks.jar applicationClass 'net.corda.explorer.Main' archiveBaseName = 'node-explorer' archiveVersion = corda_release_version - archiveClassifier = jdkClassifier archiveName = archiveFileName.get() applicationSource = files( - project(':tools:explorer').configurations.runtimeClasspath, - project(':tools:explorer').tasks.jar, - project(':tools:explorer').sourceSets.main.java.outputDir.toString() + '/ExplorerCaplet.class' + project(':tools:explorer').configurations.runtimeClasspath, + project(':tools:explorer').tasks.jar, + project(':tools:explorer').sourceSets.main.java.outputDir.toString() + '/ExplorerCaplet.class' ) capsuleManifest { diff --git a/tools/network-builder/build.gradle b/tools/network-builder/build.gradle index 366609047d..dc72c205d8 100644 --- a/tools/network-builder/build.gradle +++ b/tools/network-builder/build.gradle @@ -77,9 +77,8 @@ processResources { } shadowJar { - baseName = 'network-builder' - archiveClassifier = jdkClassifier - version = null + archiveBaseName = 'network-builder' + archiveVersion = null zip64 true }