2020-02-18 09:12:19 +00:00
|
|
|
import net.corda.gradle.jarfilter.JarFilterTask
|
|
|
|
import net.corda.gradle.jarfilter.MetaFixerTask
|
|
|
|
import proguard.gradle.ProGuardTask
|
|
|
|
import static org.gradle.api.JavaVersion.VERSION_1_8
|
2018-06-11 19:34:59 +00:00
|
|
|
|
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"
|
|
|
|
|
|
|
|
description 'Corda core (deterministic)'
|
2018-06-11 19:34:59 +00:00
|
|
|
|
|
|
|
evaluationDependsOn(":core")
|
|
|
|
|
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 {
|
2021-11-10 16:38:40 +00:00
|
|
|
deterministicLibraries {
|
|
|
|
canBeConsumed = false
|
|
|
|
extendsFrom api
|
|
|
|
}
|
2018-09-07 14:07:06 +00:00
|
|
|
deterministicArtifacts.extendsFrom deterministicLibraries
|
2018-06-11 19:34:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dependencies {
|
|
|
|
compileOnly project(':core')
|
|
|
|
|
|
|
|
// Configure these by hand. It should be a minimal subset of core's dependencies,
|
|
|
|
// and without any obviously non-deterministic ones such as Hibernate.
|
2019-06-21 13:01:59 +00:00
|
|
|
|
|
|
|
// These "api" dependencies will become "compile" scoped in our published POM.
|
|
|
|
api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
|
|
|
api "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
|
|
|
|
api "javax.persistence:javax.persistence-api:2.2"
|
|
|
|
api "com.google.code.findbugs:jsr305:$jsr305_version"
|
2019-11-06 16:49:27 +00:00
|
|
|
api "org.slf4j:slf4j-api:$slf4j_version"
|
2019-06-21 13:01:59 +00:00
|
|
|
|
|
|
|
// These dependencies will become "runtime" scoped in our published POM.
|
|
|
|
// See publish.dependenciesFrom.defaultScope.
|
2024-07-18 13:23:16 +00:00
|
|
|
deterministicLibraries "org.bouncycastle:bcprov-jdk18on:$bouncycastle_version"
|
|
|
|
deterministicLibraries "org.bouncycastle:bcpkix-jdk18on:$bouncycastle_version"
|
2018-09-07 14:07:06 +00:00
|
|
|
deterministicLibraries "net.i2p.crypto:eddsa:$eddsa_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 coreJarTask = project(':core').tasks.named('jar', Jar)
|
|
|
|
def originalJar = coreJarTask.map { it.outputs.files.singleFile }
|
2018-06-11 19:34:59 +00:00
|
|
|
|
2020-02-18 09:12:19 +00:00
|
|
|
def patchCore = tasks.register('patchCore', Zip) {
|
|
|
|
dependsOn coreJarTask
|
2021-11-10 16:38:40 +00:00
|
|
|
destinationDirectory = layout.buildDirectory.dir('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)) {
|
2019-12-09 14:17:48 +00:00
|
|
|
exclude 'net/corda/core/crypto/DelegatingSecureRandomService*.class'
|
2020-11-05 22:05:29 +00:00
|
|
|
exclude 'net/corda/core/crypto/DigestSupplier.class'
|
2018-06-11 19:34:59 +00:00
|
|
|
exclude 'net/corda/core/internal/*ToggleField*.class'
|
|
|
|
exclude 'net/corda/core/serialization/*SerializationFactory*.class'
|
2020-05-12 08:51:12 +00:00
|
|
|
exclude 'net/corda/core/serialization/internal/AttachmentsHolderImpl.class'
|
2018-09-19 13:23:29 +00:00
|
|
|
exclude 'net/corda/core/serialization/internal/CheckpointSerializationFactory*.class'
|
2018-11-26 16:02:32 +00:00
|
|
|
exclude 'net/corda/core/internal/rules/*.class'
|
2024-10-09 13:46:57 +00:00
|
|
|
exclude 'net/corda/core/contracts/CordaRotatedKeys.class'
|
|
|
|
exclude 'net/corda/core/contracts/RotatedKeysKt.class'
|
|
|
|
exclude 'net/corda/core/contracts/RotatedKeys.class'
|
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) {
|
2018-06-11 19:34:59 +00:00
|
|
|
injars patchCore
|
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 "$javaHome/lib/rt.jar"
|
|
|
|
libraryjars "$javaHome/lib/jce.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
|
2018-07-05 08:37:30 +00:00
|
|
|
dontwarn '**$1$1,org.hibernate.annotations.*'
|
2018-06-11 19:34:59 +00:00
|
|
|
dontpreverify
|
|
|
|
dontobfuscate
|
|
|
|
dontoptimize
|
2018-07-04 08:15:54 +00:00
|
|
|
dontnote
|
2018-06-11 19:34:59 +00:00
|
|
|
printseeds
|
|
|
|
verbose
|
|
|
|
|
|
|
|
keep '@interface net.corda.core.* { *; }'
|
|
|
|
keep '@interface net.corda.core.contracts.** { *; }'
|
|
|
|
keep '@interface net.corda.core.serialization.** { *; }'
|
|
|
|
keep '@net.corda.core.KeepForDJVM class * { *; }', includedescriptorclasses:true
|
|
|
|
keepclassmembers 'class net.corda.core.** { 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 = [
|
2018-07-05 08:37:30 +00:00
|
|
|
"co.paralleluniverse.fibers.Suspendable",
|
|
|
|
"org.hibernate.annotations.Immutable"
|
2018-06-11 19:34:59 +00:00
|
|
|
]
|
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 "$javaHome/lib/rt.jar"
|
|
|
|
libraryjars "$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 '@interface net.corda.core.CordaInternal { *; }'
|
|
|
|
keep '@interface net.corda.core.DoNotImplement { *; }'
|
|
|
|
keep '@interface net.corda.core.KeepForDJVM { *; }'
|
|
|
|
keep '@interface net.corda.core.contracts.** { *; }'
|
|
|
|
keep '@interface net.corda.core.serialization.** { *; }'
|
|
|
|
keep '@net.corda.core.KeepForDJVM class * { *; }', includedescriptorclasses:true
|
|
|
|
keepclassmembers 'class net.corda.core.** { public synthetic <methods>; }'
|
|
|
|
}
|
|
|
|
|
2020-07-13 09:33:23 +00:00
|
|
|
def checkDeterminism = tasks.register('checkDeterminism', ProGuardTask)
|
|
|
|
|
|
|
|
def metafix = tasks.register('metafix', MetaFixerTask) {
|
2021-11-10 16:38:40 +00:00
|
|
|
outputDir = layout.buildDirectory.dir('libs')
|
2018-06-11 19:34:59 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// DOCSTART 01
|
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 *'
|
|
|
|
}
|
|
|
|
// DOCEND 01
|
|
|
|
|
|
|
|
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 {
|
2018-09-07 14:07:06 +00:00
|
|
|
dependenciesFrom configurations.deterministicArtifacts
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|