2020-02-18 09:12:19 +00:00
|
|
|
import net.corda.gradle.jarfilter.JarFilterTask
|
|
|
|
import net.corda.gradle.jarfilter.MetaFixerTask
|
|
|
|
import proguard.gradle.ProGuardTask
|
2019-09-20 14:10:15 +00:00
|
|
|
import static org.gradle.api.JavaVersion.VERSION_1_8
|
|
|
|
|
2020-02-18 09:12:19 +00:00
|
|
|
plugins {
|
2020-02-20 17:01:24 +00:00
|
|
|
id 'org.jetbrains.kotlin.jvm'
|
2020-02-18 09:12:19 +00:00
|
|
|
id 'net.corda.plugins.publish-utils'
|
|
|
|
id 'com.jfrog.artifactory'
|
|
|
|
id 'java-library'
|
|
|
|
id 'idea'
|
|
|
|
}
|
|
|
|
apply from: "${rootProject.projectDir}/deterministic.gradle"
|
2018-06-11 19:34:59 +00:00
|
|
|
|
2020-02-18 09:12:19 +00:00
|
|
|
description 'Corda serialization (deterministic)'
|
2018-06-11 19:34:59 +00:00
|
|
|
|
|
|
|
evaluationDependsOn(":serialization")
|
|
|
|
|
2019-09-20 14:10:15 +00:00
|
|
|
// required by DJVM and Avian JVM (for running inside the SGX enclave) which only supports Java 8.
|
|
|
|
targetCompatibility = VERSION_1_8
|
|
|
|
|
2018-06-11 19:34:59 +00:00
|
|
|
def javaHome = System.getProperty('java.home')
|
|
|
|
def jarBaseName = "corda-${project.name}".toString()
|
|
|
|
|
|
|
|
configurations {
|
2019-06-21 13:01:59 +00:00
|
|
|
deterministicLibraries.extendsFrom implementation
|
2018-09-07 14:07:06 +00:00
|
|
|
deterministicArtifacts.extendsFrom deterministicLibraries
|
2018-06-11 19:34:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dependencies {
|
|
|
|
compileOnly project(':serialization')
|
|
|
|
|
|
|
|
// Configure these by hand. It should be a minimal subset of dependencies,
|
|
|
|
// and without any obviously non-deterministic ones such as Hibernate.
|
2019-06-21 13:01:59 +00:00
|
|
|
|
2019-08-12 17:12:58 +00:00
|
|
|
// These dependencies will become "compile" scoped in our published POM.
|
2019-06-21 13:01:59 +00:00
|
|
|
// See publish.dependenciesFrom.defaultScope.
|
2018-09-07 14:07:06 +00:00
|
|
|
deterministicLibraries project(path: ':core-deterministic', configuration: 'deterministicArtifacts')
|
2019-08-12 17:12:58 +00:00
|
|
|
deterministicLibraries "org.apache.qpid:proton-j:$protonj_version"
|
2019-06-21 13:01:59 +00:00
|
|
|
|
|
|
|
// These "implementation" dependencies will become "runtime" scoped in our published POM.
|
|
|
|
implementation "org.iq80.snappy:snappy:$snappy_version"
|
|
|
|
implementation "com.google.guava:guava:$guava_version"
|
2018-06-11 19:34:59 +00:00
|
|
|
}
|
|
|
|
|
2020-02-20 17:01:24 +00:00
|
|
|
tasks.named('jar', Jar) {
|
2019-06-21 13:01:59 +00:00
|
|
|
archiveBaseName = 'DOES-NOT-EXIST'
|
2018-06-11 19:34:59 +00:00
|
|
|
// Don't build a jar here because it would be the wrong one.
|
|
|
|
// The jar we really want will be built by the metafix task.
|
|
|
|
enabled = false
|
|
|
|
}
|
|
|
|
|
2020-07-13 09:33:23 +00:00
|
|
|
def serializationJarTask = project(':serialization').tasks.named('jar', Jar)
|
|
|
|
def originalJar = serializationJarTask.map { it.outputs.files.singleFile }
|
2018-06-11 19:34:59 +00:00
|
|
|
|
2020-02-18 09:12:19 +00:00
|
|
|
def patchSerialization = tasks.register('patchSerialization', Zip) {
|
|
|
|
dependsOn serializationJarTask
|
2019-06-21 13:01:59 +00:00
|
|
|
destinationDirectory = file("$buildDir/source-libs")
|
2018-06-11 19:34:59 +00:00
|
|
|
metadataCharset 'UTF-8'
|
2019-06-21 13:01:59 +00:00
|
|
|
archiveClassifier = 'transient'
|
|
|
|
archiveExtension = 'jar'
|
2018-06-11 19:34:59 +00:00
|
|
|
|
|
|
|
from(compileKotlin)
|
2019-11-05 13:44:18 +00:00
|
|
|
from(processResources)
|
2018-06-11 19:34:59 +00:00
|
|
|
from(zipTree(originalJar)) {
|
|
|
|
exclude 'net/corda/serialization/internal/AttachmentsClassLoaderBuilder*'
|
|
|
|
exclude 'net/corda/serialization/internal/ByteBufferStreams*'
|
|
|
|
exclude 'net/corda/serialization/internal/DefaultWhitelist*'
|
|
|
|
exclude 'net/corda/serialization/internal/amqp/AMQPSerializerFactories*'
|
|
|
|
exclude 'net/corda/serialization/internal/amqp/AMQPStreams*'
|
2018-07-11 12:28:01 +00:00
|
|
|
exclude 'net/corda/serialization/internal/amqp/AMQPSerializationThreadContext*'
|
2018-11-07 13:48:45 +00:00
|
|
|
exclude 'net/corda/serialization/internal/model/DefaultCacheProvider*'
|
2018-06-11 19:34:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reproducibleFileOrder = true
|
|
|
|
includeEmptyDirs = false
|
|
|
|
}
|
|
|
|
|
2020-02-18 09:12:19 +00:00
|
|
|
def predeterminise = tasks.register('predeterminise', ProGuardTask) {
|
2020-07-13 09:33:23 +00:00
|
|
|
dependsOn project(':core-deterministic').tasks.named('assemble')
|
2018-06-11 19:34:59 +00:00
|
|
|
injars patchSerialization
|
2018-07-24 12:52:45 +00:00
|
|
|
outjars file("$buildDir/proguard/pre-deterministic-${project.version}.jar")
|
2018-06-11 19:34:59 +00:00
|
|
|
|
2019-09-20 14:10:15 +00:00
|
|
|
if (JavaVersion.current().isJava9Compatible()) {
|
|
|
|
libraryjars "$javaHome/jmods"
|
|
|
|
} else {
|
|
|
|
libraryjars file("$javaHome/lib/rt.jar")
|
|
|
|
libraryjars file("$javaHome/lib/jce.jar")
|
|
|
|
libraryjars file("$javaHome/lib/ext/sunec.jar")
|
|
|
|
}
|
2019-06-21 13:01:59 +00:00
|
|
|
configurations.compileClasspath.forEach {
|
2018-07-24 12:52:45 +00:00
|
|
|
if (originalJar != it) {
|
|
|
|
libraryjars it, filter: '!META-INF/versions/**'
|
2018-06-11 19:34:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
keepattributes '*'
|
|
|
|
keepdirectories
|
|
|
|
dontpreverify
|
|
|
|
dontobfuscate
|
|
|
|
dontoptimize
|
2018-07-04 08:15:54 +00:00
|
|
|
dontnote
|
2018-06-11 19:34:59 +00:00
|
|
|
printseeds
|
|
|
|
verbose
|
|
|
|
|
|
|
|
keep '@net.corda.core.KeepForDJVM class * { *; }', includedescriptorclasses:true
|
|
|
|
keepclassmembers 'class net.corda.serialization.** { public synthetic <methods>; }'
|
|
|
|
}
|
|
|
|
|
2020-02-18 09:12:19 +00:00
|
|
|
def jarFilter = tasks.register('jarFilter', JarFilterTask) {
|
2018-06-11 19:34:59 +00:00
|
|
|
jars predeterminise
|
|
|
|
annotations {
|
|
|
|
forDelete = [
|
|
|
|
"net.corda.core.DeleteForDJVM"
|
|
|
|
]
|
|
|
|
forStub = [
|
|
|
|
"net.corda.core.StubOutForDJVM"
|
|
|
|
]
|
|
|
|
forRemove = [
|
|
|
|
"co.paralleluniverse.fibers.Suspendable"
|
|
|
|
]
|
2018-07-05 15:14:56 +00:00
|
|
|
forSanitise = [
|
|
|
|
"net.corda.core.DeleteForDJVM"
|
|
|
|
]
|
2018-06-11 19:34:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-13 09:33:23 +00:00
|
|
|
def determinise = tasks.register('determinise', ProGuardTask) {
|
2018-06-11 19:34:59 +00:00
|
|
|
injars jarFilter
|
2018-07-24 12:52:45 +00:00
|
|
|
outjars file("$buildDir/proguard/$jarBaseName-${project.version}.jar")
|
2018-06-11 19:34:59 +00:00
|
|
|
|
2019-09-20 14:10:15 +00:00
|
|
|
if (JavaVersion.current().isJava9Compatible()) {
|
|
|
|
libraryjars "$javaHome/jmods"
|
|
|
|
} else {
|
|
|
|
libraryjars file("$javaHome/lib/rt.jar")
|
|
|
|
libraryjars file("$javaHome/lib/jce.jar")
|
|
|
|
}
|
2018-09-07 14:07:06 +00:00
|
|
|
configurations.deterministicLibraries.forEach {
|
2018-07-24 12:52:45 +00:00
|
|
|
libraryjars it, filter: '!META-INF/versions/**'
|
2018-06-11 19:34:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Analyse the JAR for dead code, and remove (some of) it.
|
|
|
|
optimizations 'code/removal/simple,code/removal/advanced'
|
|
|
|
printconfiguration
|
|
|
|
|
|
|
|
keepattributes '*'
|
|
|
|
keepdirectories
|
|
|
|
dontobfuscate
|
2018-07-04 08:15:54 +00:00
|
|
|
dontnote
|
2018-06-11 19:34:59 +00:00
|
|
|
printseeds
|
|
|
|
verbose
|
|
|
|
|
|
|
|
keep '@net.corda.core.KeepForDJVM class * { *; }', includedescriptorclasses:true
|
|
|
|
keepclassmembers 'class net.corda.serialization.** { public synthetic <methods>; }'
|
|
|
|
}
|
|
|
|
|
2020-07-13 09:33:23 +00:00
|
|
|
def checkDeterminism = tasks.register('checkDeterminism', ProGuardTask)
|
|
|
|
|
|
|
|
def metafix = tasks.register('metafix', MetaFixerTask) {
|
2018-06-11 19:34:59 +00:00
|
|
|
outputDir file("$buildDir/libs")
|
|
|
|
jars determinise
|
|
|
|
suffix ""
|
|
|
|
|
|
|
|
// Strip timestamps from the JAR to make it reproducible.
|
|
|
|
preserveTimestamps = false
|
2020-07-13 09:33:23 +00:00
|
|
|
finalizedBy checkDeterminism
|
2018-06-11 19:34:59 +00:00
|
|
|
}
|
|
|
|
|
2020-07-13 09:33:23 +00:00
|
|
|
checkDeterminism.configure {
|
2020-02-18 09:12:19 +00:00
|
|
|
dependsOn jdkTask
|
2018-06-11 19:34:59 +00:00
|
|
|
injars metafix
|
|
|
|
|
2018-06-18 13:14:48 +00:00
|
|
|
libraryjars deterministic_rt_jar
|
2018-06-11 19:34:59 +00:00
|
|
|
|
2018-09-07 14:07:06 +00:00
|
|
|
configurations.deterministicLibraries.forEach {
|
2018-07-24 12:52:45 +00:00
|
|
|
libraryjars it, filter: '!META-INF/versions/**'
|
2018-06-11 19:34:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
keepattributes '*'
|
|
|
|
dontpreverify
|
|
|
|
dontobfuscate
|
|
|
|
dontoptimize
|
|
|
|
verbose
|
|
|
|
|
|
|
|
keep 'class *'
|
|
|
|
}
|
|
|
|
|
|
|
|
defaultTasks "determinise"
|
2020-07-13 09:33:23 +00:00
|
|
|
determinise.configure {
|
|
|
|
finalizedBy metafix
|
|
|
|
}
|
|
|
|
tasks.named('assemble') {
|
|
|
|
dependsOn checkDeterminism
|
|
|
|
}
|
2018-06-11 19:34:59 +00:00
|
|
|
|
2020-07-13 09:33:23 +00:00
|
|
|
def deterministicJar = metafix.map { it.outputs.files.singleFile }
|
2018-06-11 19:34:59 +00:00
|
|
|
artifacts {
|
2020-07-13 09:33:23 +00:00
|
|
|
deterministicArtifacts deterministicJar
|
|
|
|
publish deterministicJar
|
2018-06-11 19:34:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 19:38:51 +00:00
|
|
|
tasks.named('sourceJar', Jar) {
|
|
|
|
from 'README.md'
|
|
|
|
include 'README.md'
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.named('javadocJar', Jar) {
|
|
|
|
from 'README.md'
|
|
|
|
include 'README.md'
|
|
|
|
}
|
|
|
|
|
2018-06-11 19:34:59 +00:00
|
|
|
publish {
|
2019-06-21 13:01:59 +00:00
|
|
|
dependenciesFrom(configurations.deterministicArtifacts) {
|
|
|
|
defaultScope = 'compile'
|
|
|
|
}
|
2018-06-11 19:34:59 +00:00
|
|
|
name jarBaseName
|
|
|
|
}
|
|
|
|
|
2018-06-18 11:40:35 +00:00
|
|
|
idea {
|
|
|
|
module {
|
|
|
|
if (project.hasProperty("deterministic_idea_sdk")) {
|
|
|
|
jdkName project.property("deterministic_idea_sdk") as String
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|