Skip to content

Commit

Permalink
ENT-1463, ENT-1903: Refactor Gradle for deterministic modules (corda#…
Browse files Browse the repository at this point in the history
…3387)

* Export locations of both deterministic rt.jar and its JDK_HOME as properties.
* Refactor deterministic Java/Kotlin configuration into a script plugin.
  • Loading branch information
chrisr3 authored Jun 18, 2018
1 parent c2585e8 commit 9148d05
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 52 deletions.
19 changes: 2 additions & 17 deletions core-deterministic/build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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/**'
Expand Down
19 changes: 1 addition & 18 deletions core-deterministic/testing/common/build.gradle
Original file line number Diff line number Diff line change
@@ -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")) {
Expand Down
29 changes: 29 additions & 0 deletions deterministic.gradle
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions jdk8u-deterministic/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ repositories {

ext {
jdk_home = "$projectDir/jdk"
rt_jar = "$jdk_home/jre/lib/rt.jar".toString()
}

configurations {
Expand Down
19 changes: 2 additions & 17 deletions serialization-deterministic/build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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/**'
Expand Down

0 comments on commit 9148d05

Please sign in to comment.