From 9148d0529ad0e9e84a45305d763cfee485e6b5c3 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Mon, 18 Jun 2018 14:14:48 +0100 Subject: [PATCH] ENT-1463, ENT-1903: Refactor Gradle for deterministic modules (#3387) * Export locations of both deterministic rt.jar and its JDK_HOME as properties. * Refactor deterministic Java/Kotlin configuration into a script plugin. --- core-deterministic/build.gradle | 19 ++---------- .../testing/common/build.gradle | 19 +----------- deterministic.gradle | 29 +++++++++++++++++++ jdk8u-deterministic/build.gradle | 1 + serialization-deterministic/build.gradle | 19 ++---------- 5 files changed, 35 insertions(+), 52 deletions(-) create mode 100644 deterministic.gradle diff --git a/core-deterministic/build.gradle b/core-deterministic/build.gradle index 419a540adb..80a0232dbf 100644 --- a/core-deterministic/build.gradle +++ b/core-deterministic/build.gradle @@ -1,17 +1,14 @@ description 'Corda core (deterministic)' -apply plugin: 'kotlin' +apply from: '../deterministic.gradle' apply plugin: 'com.jfrog.artifactory' apply plugin: 'net.corda.plugins.publish-utils' apply plugin: 'idea' -evaluationDependsOn(':jdk8u-deterministic') evaluationDependsOn(":core") def javaHome = System.getProperty('java.home') def jarBaseName = "corda-${project.name}".toString() -def jdkTask = project(':jdk8u-deterministic').assemble -def deterministic_jdk_home = project(':jdk8u-deterministic').jdk_home configurations { runtimeLibraries @@ -36,18 +33,6 @@ dependencies { runtimeLibraries "org.slf4j:slf4j-api:$slf4j_version" } -tasks.withType(AbstractCompile) { - dependsOn jdkTask -} - -tasks.withType(JavaCompile) { - options.compilerArgs << '-bootclasspath' << "$deterministic_jdk_home/jre/lib/rt.jar".toString() -} - -tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) { - kotlinOptions.jdkHome = deterministic_jdk_home -} - jar { baseName 'DOES-NOT-EXIST' // Don't build a jar here because it would be the wrong one. @@ -162,7 +147,7 @@ task metafix(type: MetaFixerTask) { task checkDeterminism(type: ProGuardTask, dependsOn: jdkTask) { injars metafix - libraryjars "$deterministic_jdk_home/jre/lib/rt.jar" + libraryjars deterministic_rt_jar configurations.runtimeLibraries.forEach { libraryjars it.path, filter: '!META-INF/versions/**' diff --git a/core-deterministic/testing/common/build.gradle b/core-deterministic/testing/common/build.gradle index 4ef2891bda..f7c48a6c7a 100644 --- a/core-deterministic/testing/common/build.gradle +++ b/core-deterministic/testing/common/build.gradle @@ -1,29 +1,12 @@ -apply plugin: 'kotlin' +apply from: '../../../deterministic.gradle' apply plugin: 'idea' -evaluationDependsOn(':jdk8u-deterministic') - -def jdkTask = project(':jdk8u-deterministic').assemble -def deterministic_jdk_home = project(':jdk8u-deterministic').jdk_home - dependencies { compileOnly project(path: ':core-deterministic', configuration: 'runtimeArtifacts') compileOnly project(path: ':serialization-deterministic', configuration: 'runtimeArtifacts') compileOnly "junit:junit:$junit_version" } -tasks.withType(AbstractCompile) { - dependsOn jdkTask -} - -tasks.withType(JavaCompile) { - options.compilerArgs << '-bootclasspath' << "$deterministic_jdk_home/jre/lib/rt.jar".toString() -} - -tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) { - kotlinOptions.jdkHome = deterministic_jdk_home -} - idea { module { if (project.hasProperty("deterministic_idea_sdk")) { diff --git a/deterministic.gradle b/deterministic.gradle new file mode 100644 index 0000000000..fefca67c76 --- /dev/null +++ b/deterministic.gradle @@ -0,0 +1,29 @@ +/* + * Gradle script plugin: Configure a module such that the Java and Kotlin + * compilers use the deterministic rt.jar instead of the full JDK rt.jar. + */ +apply plugin: 'kotlin' + +evaluationDependsOn(':jdk8u-deterministic') + +def jdk8uDeterministic = project(':jdk8u-deterministic') + +ext { + jdkTask = jdk8uDeterministic.assemble + deterministic_jdk_home = jdk8uDeterministic.jdk_home + deterministic_rt_jar = jdk8uDeterministic.rt_jar +} + +tasks.withType(AbstractCompile) { + dependsOn jdkTask + + // This is a bit ugly, but Gradle isn't recognising the KotlinCompile task + // as it does the built-in JavaCompile task. + if (it.class.name.startsWith("org.jetbrains.kotlin.gradle.tasks.KotlinCompile")) { + kotlinOptions.jdkHome = deterministic_jdk_home + } +} + +tasks.withType(JavaCompile) { + options.compilerArgs << '-bootclasspath' << deterministic_rt_jar +} diff --git a/jdk8u-deterministic/build.gradle b/jdk8u-deterministic/build.gradle index b2810ab8bc..13f468581f 100644 --- a/jdk8u-deterministic/build.gradle +++ b/jdk8u-deterministic/build.gradle @@ -9,6 +9,7 @@ repositories { ext { jdk_home = "$projectDir/jdk" + rt_jar = "$jdk_home/jre/lib/rt.jar".toString() } configurations { diff --git a/serialization-deterministic/build.gradle b/serialization-deterministic/build.gradle index 06f89f6c65..97ef9f7076 100644 --- a/serialization-deterministic/build.gradle +++ b/serialization-deterministic/build.gradle @@ -1,17 +1,14 @@ description 'Corda serialization (deterministic)' -apply plugin: 'kotlin' +apply from: '../deterministic.gradle' apply plugin: 'com.jfrog.artifactory' apply plugin: 'net.corda.plugins.publish-utils' apply plugin: 'idea' -evaluationDependsOn(':jdk8u-deterministic') evaluationDependsOn(":serialization") def javaHome = System.getProperty('java.home') def jarBaseName = "corda-${project.name}".toString() -def jdkTask = project(':jdk8u-deterministic').assemble -def deterministic_jdk_home = project(':jdk8u-deterministic').jdk_home configurations { runtimeLibraries @@ -30,18 +27,6 @@ dependencies { runtimeLibraries "org.iq80.snappy:snappy:$snappy_version" } -tasks.withType(AbstractCompile) { - dependsOn jdkTask -} - -tasks.withType(JavaCompile) { - options.compilerArgs << "-bootclasspath" << "$deterministic_jdk_home/jre/lib/rt.jar".toString() -} - -tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) { - kotlinOptions.jdkHome = deterministic_jdk_home -} - jar { baseName 'DOES-NOT-EXIST' // Don't build a jar here because it would be the wrong one. @@ -150,7 +135,7 @@ task metafix(type: MetaFixerTask) { task checkDeterminism(type: ProGuardTask, dependsOn: jdkTask) { injars metafix - libraryjars "$deterministic_jdk_home/jre/lib/rt.jar" + libraryjars deterministic_rt_jar configurations.runtimeLibraries.forEach { libraryjars it.path, filter: '!META-INF/versions/**'