Skip to content

Commit

Permalink
Only add needed dependencies in the uber jar and add distPlugin task
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Di Fabio <[email protected]>
  • Loading branch information
fab-10 committed Dec 12, 2024
1 parent e83b8a3 commit 0ac7d74
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 53 deletions.
6 changes: 6 additions & 0 deletions acceptance-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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/
108 changes: 89 additions & 19 deletions gradle/dist.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
import de.undercouch.gradle.tasks.download.Download

tasks.register('sourcesJar', Jar) {
dependsOn classes
Expand All @@ -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(
Expand All @@ -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/
}
16 changes: 16 additions & 0 deletions gradle/java.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
19 changes: 1 addition & 18 deletions native/compress/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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'
}


Expand Down Expand Up @@ -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)
19 changes: 4 additions & 15 deletions sequencer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
}

0 comments on commit 0ac7d74

Please sign in to comment.