Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only add needed dependencies in the uber jar #924

Merged
merged 7 commits into from
Dec 2, 2024
Merged
39 changes: 14 additions & 25 deletions arithmetization/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

plugins {
id 'java'
id 'java-library-distribution'
id 'common-plugins'
id 'com.github.hierynomus.license'
id "de.undercouch.download"
Expand All @@ -34,51 +35,39 @@ apply from: rootProject.file("gradle/lint.gradle")
apply from: rootProject.file("gradle/trace-files.gradle")

dependencies {
/**
* Use pluginImplementation for dependencies that are specific to this plugin
* and are not already provided by Besu.
* These dependencies are the only ones that are included in the final jar.
*/
pluginImplementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml'

// annotationProcessor generates the file META-INF/services/org.hyperledger.besu.plugin.BesuPlugin
annotationProcessor 'com.google.auto.service:auto-service'
compileOnly "${besuArtifactGroup}:evm"
compileOnly 'com.google.auto.service:auto-service'
compileOnly 'com.google.auto.service:auto-service-annotations'

implementation "${besuArtifactGroup}:besu-datatypes"
implementation "${besuArtifactGroup}:evm"
implementation "${besuArtifactGroup}:plugin-api"
implementation "${besuArtifactGroup}:besu-datatypes"
implementation "${besuArtifactGroup}.internal:algorithms"
implementation "${besuArtifactGroup}.internal:api"
implementation "${besuArtifactGroup}.internal:clique"
implementation "${besuArtifactGroup}.internal:core"
implementation "${besuArtifactGroup}.internal:rlp"
implementation "${besuArtifactGroup}.internal:algorithms"

implementation 'info.picocli:picocli'
implementation 'com.google.auto.service:auto-service'

implementation 'io.vertx:vertx-core'
implementation 'io.vertx:vertx-web'

implementation 'com.fasterxml.jackson.core:jackson-databind'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml'
implementation 'info.picocli:picocli'

implementation 'io.tmio:tuweni-bytes'
implementation 'io.tmio:tuweni-units'
implementation 'io.tmio:tuweni-toml'
implementation 'org.bouncycastle:bcprov-jdk18on'
implementation 'org.hibernate.validator:hibernate-validator'

implementation 'io.vertx:vertx-web'

testImplementation project(path: ':testing')

testImplementation "${besuArtifactGroup}:evm"
testImplementation "${besuArtifactGroup}:besu-datatypes"
testImplementation "${besuArtifactGroup}.internal:core"
testImplementation "${besuArtifactGroup}.internal:rlp"
testImplementation "${besuArtifactGroup}.internal:core"
testImplementation "${besuArtifactGroup}.internal:referencetests"
testImplementation 'org.junit.platform:junit-platform-launcher'
}

configurations {
installedJars {
transitive = false
}
}

apply from: rootProject.file("gradle/dist.gradle")
apply from: rootProject.file("gradle/publishing.gradle")
16 changes: 9 additions & 7 deletions gradle/dependency-management.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ repositories {
url 'https://artifacts.consensys.net/public/maven/maven/'
content { includeGroupByRegex('tech\\.pegasys(\\..*)?') }
}
maven {
url 'https://splunk.jfrog.io/splunk/ext-releases-local'
content { includeGroupByRegex('com\\.splunk\\..*') }
}
mavenCentral()
mavenLocal()
fab-10 marked this conversation as resolved.
Show resolved Hide resolved
}

configurations.all {
resolutionStrategy {
cacheChangingModulesFor 0, 'seconds'
configurations {
pluginImplementation
resolvable('pluginClasspath') {
extendsFrom(pluginImplementation)
}
}

sourceSets.main.compileClasspath += configurations.pluginImplementation
sourceSets.main.runtimeClasspath += configurations.pluginImplementation

apply plugin: 'io.spring.dependency-management'

dependencyManagement {
Expand All @@ -58,6 +58,8 @@ dependencyManagement {
entry 'logback-classic'
}

dependency 'com.google.code.gson:gson:2.11.0'

dependency 'com.slack.api:slack-api-client:1.32.1'
}
}
83 changes: 77 additions & 6 deletions gradle/dist.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import de.undercouch.gradle.tasks.download.Download

/*
* Copyright Consensys Software Inc.
*
Expand All @@ -14,6 +12,7 @@ import de.undercouch.gradle.tasks.download.Download
*
* SPDX-License-Identifier: Apache-2.0
*/
import de.undercouch.gradle.tasks.download.Download

tasks.register('sourcesJar', Jar) {
dependsOn classes
Expand All @@ -29,7 +28,59 @@ tasks.register('javadocJar', Jar) {

version = project.hasProperty('releaseVersion') ? project.getProperty('releaseVersion') : 'snapshot'

def lineaBesuDistTar = new File(new File(buildDir, "tmp"), 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
}

// Get all the dependencies that are provided by Besu, removing the version and suffix
def lineaBesuLibDir = new File(lineaBesuDistTar.parentFile, rootProject.besuIdentifier + '/lib')
def lineaBesuLibs = []
fileTree(dir: lineaBesuLibDir, include: '*.jar').visit {
FileVisitDetails details ->
def libPrefix = details.file.name =~ dependencyNamePattern()
lineaBesuLibs << libPrefix[0][1]
}

def excludeBesuProvidedDeps = {
// include the dependency in the jar only if it is not already provided by Besu
def libName = it.name =~ dependencyNamePattern()
def libPrefix = libName[0][1]
!lineaBesuLibs.contains(libPrefix)
}

jar {
dependsOn unTarLineaBesu
archiveBaseName = distributionIdentifier

manifest {
Expand All @@ -41,12 +92,12 @@ jar {
)
}


from {
configurations.runtimeClasspath.filter( {! (it.name =~ /log4j.*\.jar/ ) && ! (it.name =~ /vertx.*\.jar/ ) && it.name != 'jc-kzg-4844-2.0.0.jar'} )
.collect {it.isDirectory() ? it : zipTree(it) }
configurations.pluginClasspath.filter(excludeBesuProvidedDeps
).collect {it.isDirectory() ? it : zipTree(it) }
}
exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA', 'ch.qos.logback'
duplicatesStrategy(DuplicatesStrategy.INCLUDE)
duplicatesStrategy('exclude')
}

// Takes the version, and if -SNAPSHOT is part of it replaces SNAPSHOT
Expand All @@ -60,7 +111,27 @@ def calculateVersion() {
return version
}

/**
* 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

from("${buildDir}/libs")
from {
configurations.pluginClasspath.filter(
excludeBesuProvidedDeps)

}
}

static def getCheckedOutGitCommitHash() {
def hashLength = 8
"git rev-parse HEAD".execute().text.take(hashLength)
}

static def dependencyNamePattern() {
/(.*)(\-.*?)\.jar/
}
13 changes: 5 additions & 8 deletions testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ apply from: rootProject.file("gradle/lint.gradle")

dependencies {
implementation project(path: ':arithmetization')

implementation "${besuArtifactGroup}:besu-datatypes"
implementation "${besuArtifactGroup}:evm"
implementation "${besuArtifactGroup}:plugin-api"
implementation "${besuArtifactGroup}.internal:clique"
implementation "${besuArtifactGroup}.internal:common"
implementation "${besuArtifactGroup}.internal:config"
Expand All @@ -28,17 +30,12 @@ dependencies {
implementation "${besuArtifactGroup}.internal:services"
implementation "${besuArtifactGroup}.internal:testutil"
implementation "${besuArtifactGroup}.internal:algorithms"
implementation "${besuArtifactGroup}:plugin-api"

implementation 'org.junit.platform:junit-platform-launcher'
implementation 'org.junit.jupiter:junit-jupiter-api'
runtimeOnly 'org.junit.jupiter:junit-jupiter-engine'
implementation 'org.junit.jupiter:junit-jupiter-params'
runtimeOnly 'org.junit.vintage:junit-vintage-engine'
implementation 'com.google.code.gson:gson'
implementation 'com.google.guava:guava'

implementation 'org.mockito:mockito-core'
implementation 'org.mockito:mockito-junit-jupiter'
implementation 'org.assertj:assertj-core'
implementation 'org.junit.jupiter:junit-jupiter-api'
}

node {
Expand Down
Loading