From 0ac7d745743eae16c392560309e9c1a043cb43e6 Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Thu, 12 Dec 2024 15:49:49 +0100 Subject: [PATCH] Only add needed dependencies in the uber jar and add `distPlugin` task Signed-off-by: Fabio Di Fabio --- acceptance-tests/build.gradle | 6 ++ gradle.properties | 2 +- gradle/dist.gradle | 108 ++++++++++++++++++++++++++++------ gradle/java.gradle | 16 +++++ native/compress/build.gradle | 19 +----- sequencer/build.gradle | 19 ++---- 6 files changed, 117 insertions(+), 53 deletions(-) diff --git a/acceptance-tests/build.gradle b/acceptance-tests/build.gradle index e84ef399..8ac63c63 100644 --- a/acceptance-tests/build.gradle +++ b/acceptance-tests/build.gradle @@ -55,7 +55,13 @@ dependencies { testImplementation project(":sequencer") + testImplementation "${besuArtifactGroup}:besu-datatypes" + testImplementation "${besuArtifactGroup}.internal:api" + testImplementation "${besuArtifactGroup}.internal:core" testImplementation "${besuArtifactGroup}.internal:dsl" + testImplementation "${besuArtifactGroup}.internal:eth" + testImplementation "${besuArtifactGroup}.internal:metrics-core" + testImplementation "${besuArtifactGroup}.internal:services" testImplementation 'net.consensys.linea.zktracer:arithmetization' diff --git a/gradle.properties b/gradle.properties index e253f431..20b3ab77 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ releaseVersion=0.8.0-rc8.3 besuVersion=24.12-delivery40 -arithmetizationVersion=0.8.0-rc8 +arithmetizationVersion=0.8.0-rc8-local besuArtifactGroup=io.consensys.linea-besu distributionIdentifier=linea-sequencer distributionBaseUrl=https://artifacts.consensys.net/public/linea-besu/raw/names/linea-besu.tar.gz/versions/ \ No newline at end of file diff --git a/gradle/dist.gradle b/gradle/dist.gradle index 93edbc7e..6c947c74 100644 --- a/gradle/dist.gradle +++ b/gradle/dist.gradle @@ -12,6 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ +import de.undercouch.gradle.tasks.download.Download tasks.register('sourcesJar', Jar) { dependsOn classes @@ -25,10 +26,72 @@ tasks.register('javadocJar', Jar) { from javadoc.destinationDir } -version = project.hasProperty('releaseVersion') ? project.getProperty('releaseVersion') : 'snapshot' +def lineaBesuDistTar = new File(new File(buildDir, "downloads"), rootProject.besuFilename) +tasks.register('downloadLineaBesu', Download) { + src rootProject.besuUrl + dest lineaBesuDistTar + onlyIfModified true +} + +tasks.register('copyLocalLineaBesu', Copy) { + onlyIf { + downloadLineaBesu.state.failure + } + def localLineaBesuDir = + project.hasProperty('useLocalLineaBesuDir') + ? file("${findProperty('useLocalLineaBesuDir')}".replaceFirst('^~', System.getProperty('user.home'))) + : new File(projectDir, "../../linea-besu") + + def localLineaBesuFile = new File("${localLineaBesuDir.absoluteFile}/build/distributions/${rootProject.besuFilename}") + doFirst { + if (!file(localLineaBesuFile).exists()) { + throw new GradleException("Could not download Linea Besu distribution from: " + rootProject.besuUrl + + ", and could not find it locally at ${localLineaBesuFile} either") + } + } + from localLineaBesuFile + into lineaBesuDistTar.parentFile +} + +task unTarLineaBesu(type: Copy) { + dependsOn downloadLineaBesu + dependsOn copyLocalLineaBesu + + from tarTree(lineaBesuDistTar) + into lineaBesuDistTar.parentFile +} + +def lineaBesuLibDir = new File(lineaBesuDistTar.parentFile, rootProject.besuIdentifier + '/lib') +def lineaBesuLibs = [] + +def excludeBesuProvidedDeps = { + if(lineaBesuLibs.isEmpty()) { + // Get all the dependencies that are provided by Besu + fileTree(dir: lineaBesuLibDir, include: '*.jar').visit { + FileVisitDetails details -> + lineaBesuLibs << details.file.name + } + } + // include the dependency in the jar only if it is not already provided by Besu + !lineaBesuLibs.any { artifactName -> + if(artifactName == it.name) { + return true + } + // exclude Besu group + if(it.toString().contains(besuArtifactGroup)) { + return true + } + // try ignoring the version + def libName = it.name =~ dependencyNamePattern() + def artName = artifactName =~ dependencyNamePattern() + libName[0][1] == artName[0][1] + } +} jar { + dependsOn unTarLineaBesu archiveBaseName = distributionIdentifier + version = calculateVersion() manifest { attributes( @@ -39,26 +102,33 @@ jar { ) } - from { - configurations.runtimeClasspath.filter( {! (it.name =~ /log4j.*\.jar/ )} ) - .collect {it.isDirectory() ? it : zipTree(it) } - } - exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA', 'ch.qos.logback' - duplicatesStrategy(DuplicatesStrategy.EXCLUDE) + from { + configurations.runtimeClasspath.filter(excludeBesuProvidedDeps).collect { + it.isDirectory() ? it : zipTree(it) + } + } + + duplicatesStrategy('exclude') } -// Takes the version, and if -SNAPSHOT is part of it replaces SNAPSHOT -// with the git commit version. -def calculateVersion() { - String version = rootProject.version - if (version.endsWith("-SNAPSHOT")) { - version = version.replace("-SNAPSHOT", "-dev-${getCheckedOutGitCommitHash()}") - } +/** + * Create a distribution of the plugin, that only contains the plugin jar and the + * dependencies that are not provided by Besu itself, so that is can be simply + * extracted in the Besu plugins dir. + */ +tasks.register('distPlugin', Zip) { + dependsOn installDist - return version -} + archiveBaseName = distributionIdentifier -static def getCheckedOutGitCommitHash() { - def hashLength = 8 - "git rev-parse HEAD".execute().text.take(hashLength) + from("${buildDir}/libs/${distributionIdentifier}-${calculateVersion()}.jar") + from { + configurations.runtimeClasspath.filter( + excludeBesuProvidedDeps) + + } } + +static def dependencyNamePattern() { + /(.*)(\-.*?)\.jar/ +} \ No newline at end of file diff --git a/gradle/java.gradle b/gradle/java.gradle index 01c62843..6d1a1e12 100644 --- a/gradle/java.gradle +++ b/gradle/java.gradle @@ -36,4 +36,20 @@ tasks.withType(JavaCompile) { ] options.encoding = 'UTF-8' +} + +// Takes the version, and if -SNAPSHOT is part of it replaces SNAPSHOT +// with the git commit version. +ext.calculateVersion = { -> + String version = rootProject.version + if (version.endsWith("-SNAPSHOT")) { + version = version.replace("-SNAPSHOT", "-dev-${getCheckedOutGitCommitHash()}") + } + + return version +} + +static def getCheckedOutGitCommitHash() { + def hashLength = 8 + "git rev-parse HEAD".execute().text.take(hashLength) } \ No newline at end of file diff --git a/native/compress/build.gradle b/native/compress/build.gradle index 6bb53628..ce09aa3b 100644 --- a/native/compress/build.gradle +++ b/native/compress/build.gradle @@ -24,10 +24,6 @@ apply from: rootProject.file('gradle/common-dependencies.gradle') apply from: rootProject.file("gradle/build-aliases.gradle") apply from: rootProject.file("gradle/lint.gradle") -repositories { - mavenCentral() -} - test { useJUnitPlatform() } @@ -52,11 +48,6 @@ compileJava{ dependencies { implementation 'io.tmio:tuweni-bytes' implementation 'net.java.dev.jna:jna' - - testImplementation 'org.assertj:assertj-core' - testImplementation 'org.junit.jupiter:junit-jupiter-api' - testImplementation 'org.junit.jupiter:junit-jupiter-engine' - testImplementation 'org.mockito:mockito-core' } @@ -92,16 +83,8 @@ processResources.dependsOn windowsLibCopy jar { archiveBaseName = 'linea-native-compress' + version = calculateVersion() includeEmptyDirs = false - manifest { - attributes( - 'Specification-Title': archiveBaseName, - 'Specification-Version': project.version, - 'Implementation-Title': archiveBaseName, - 'Implementation-Version': project.version, - 'Automatic-Module-Name': 'net.consensys.nativelib.compress' - ) - } } jar.dependsOn(buildJNI) diff --git a/sequencer/build.gradle b/sequencer/build.gradle index b50c552a..cebccb8d 100644 --- a/sequencer/build.gradle +++ b/sequencer/build.gradle @@ -15,11 +15,12 @@ plugins { id 'java' + id 'java-library-distribution' id 'common-plugins' + id 'de.undercouch.download' } group = 'net.consensys.linea.besu.plugin' -version = rootProject.version apply from: rootProject.file("gradle/java.gradle") apply from: rootProject.file("gradle/dependency-management.gradle") @@ -46,31 +47,19 @@ dependencies { implementation 'com.google.code.gson:gson' - implementation 'info.picocli:picocli' - implementation 'io.tmio:tuweni-bytes' implementation 'io.tmio:tuweni-units' implementation 'io.tmio:tuweni-toml' + implementation 'info.picocli:picocli' + implementation 'net.consensys.linea.zktracer:arithmetization' implementation 'org.hibernate.validator:hibernate-validator' testImplementation "${besuArtifactGroup}.internal:besu" - - testImplementation 'org.awaitility:awaitility' } -configurations { - installedJars { - transitive = false - } -} - apply from: rootProject.file("gradle/dist.gradle") - -jar { - zip64=true -}