Skip to content

Commit

Permalink
A quick go at upgrading Gradle to 8.10.1 and to compile to Java 21. N…
Browse files Browse the repository at this point in the history
…ot tested.
  • Loading branch information
david-ry4n committed Oct 23, 2024
1 parent d891ee2 commit dc54931
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 94 deletions.
99 changes: 54 additions & 45 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
import org.ajoberstar.grgit.Grgit
import net.ltgt.gradle.errorprone.CheckSeverity
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import groovy.xml.XmlParser
import java.time.Instant
import java.time.ZoneId
import java.time.format.DateTimeFormatter
Expand All @@ -21,22 +23,22 @@ buildscript {
}

dependencies {
classpath "org.ajoberstar.grgit:grgit-core:5.2.1"
classpath "org.ajoberstar.grgit:grgit-core:5.3.0"
}
}

plugins {
id 'com.diffplug.spotless' version '6.22.0'
id 'net.ltgt.errorprone' version '3.1.0'
id 'org.springframework.boot' version '3.2.4'
id 'io.spring.dependency-management' version '1.1.3'
id 'com.diffplug.spotless' version '6.25.0'
id 'net.ltgt.errorprone' version '4.1.0'
id 'org.springframework.boot' version '3.3.4'
id 'io.spring.dependency-management' version '1.1.6'
id 'org.gradle.crypto.checksum' version '1.4.0'
id 'org.jetbrains.kotlin.jvm' version '1.9.23'
id 'org.jetbrains.kotlin.plugin.spring' version '1.9.23'
id 'org.jetbrains.kotlin.jvm' version '2.0.21'
id 'org.jetbrains.kotlin.plugin.spring' version '2.0.21'
id 'org.jetbrains.dokka' version '1.9.20'
id 'maven-publish'
id 'se.patrikerdes.use-latest-versions' version '0.2.18'
id 'com.github.ben-manes.versions' version '0.49.0'
id 'com.github.ben-manes.versions' version '0.51.0'
}

description = 'A set of libraries and other tools to aid development of blockchain and other decentralized software in Java and other JVM languages'
Expand Down Expand Up @@ -74,7 +76,7 @@ def expandedTaskList = []
gradle.startParameter.taskNames.each {
expandedTaskList << (buildAliases[it] ? buildAliases[it] : it)
}
gradle.startParameter.taskNames = expandedTaskList.flatten()
gradle.startParameter.taskNames = expandedTaskList.flatten() as Iterable<String>

ext {
gradleVersion = '7.6'
Expand All @@ -96,7 +98,7 @@ spotless {
}
}

task integrationTest(type: Test) {
tasks.register('integrationTest', Test) {
}

subprojects {
Expand Down Expand Up @@ -142,7 +144,7 @@ subprojects {
integrationTestRuntimeOnly 'ch.qos.logback:logback-classic'
}

task integrationTest(type: Test) {
tasks.register('integrationTest', Test) {
description = 'Runs integration tests.'
group = 'verification'

Expand All @@ -159,13 +161,13 @@ subprojects {
//////
// Parallel build execution

tasks.withType(Test) {
tasks.withType(Test).configureEach {
// If GRADLE_MAX_TEST_FORKS is not set, use half the available processors
maxParallelForks = (System.getenv('GRADLE_MAX_TEST_FORKS') ?:
(Runtime.runtime.availableProcessors().intdiv(2) ?: 1)).toInteger()
(Runtime.runtime.availableProcessors().intdiv(2) ?: 1)).toInteger()
}

tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.fork = true
options.incremental = true
options.encoding = 'UTF-8'
Expand Down Expand Up @@ -208,43 +210,44 @@ allprojects {

//////
// Compiler arguments

sourceCompatibility = '1.17'
targetCompatibility = '1.17'
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

dependencies {
errorprone 'com.google.errorprone:error_prone_core'
}

tasks.withType(AbstractArchiveTask) {
tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
}

tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.compilerArgs += [
'-Xlint:unchecked',
'-Xlint:cast',
'-Xlint:rawtypes',
'-Xlint:overloads',
'-Xlint:divzero',
'-Xlint:finally',
'-Xlint:static',
'-Werror'
'-Xlint:unchecked',
'-Xlint:cast',
'-Xlint:rawtypes',
'-Xlint:overloads',
'-Xlint:divzero',
'-Xlint:finally',
'-Xlint:static',
'-Werror'
]

options.errorprone {
excludedPaths = '.*/generated-src/.*'
check('FutureReturnValueIgnored', net.ltgt.gradle.errorprone.CheckSeverity.OFF)
check('UnnecessaryParentheses', net.ltgt.gradle.errorprone.CheckSeverity.OFF)
check('FutureReturnValueIgnored', CheckSeverity.OFF)
check('UnnecessaryParentheses', CheckSeverity.OFF)

disableWarningsInGeneratedCode = true
}
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = "17"
tasks.withType(KotlinCompile).configureEach {
compilerOptions {
//jvmTarget = JvmTarget.JVM_21
allWarningsAsErrors = true
freeCompilerArgs = [
'-Xjsr305=strict',
Expand All @@ -264,8 +267,8 @@ allprojects {

jacocoTestReport {
reports {
xml.enabled true
html.enabled true
xml.required = true
html.required = true
}
getExecutionData().setFrom(fileTree(buildDir).include("/jacoco/*.exec"))
}
Expand All @@ -278,16 +281,17 @@ allprojects {
destinationDirectory = file("${rootProject.buildDir}/libs")
}

task sourcesJar(type: Jar, dependsOn: classes) {
tasks.register('sourcesJar', Jar) {
dependsOn classes
destinationDirectory = file("${rootProject.buildDir}/src")
classifier = 'sources'
archiveClassifier = 'sources'
from sourceSets.main.allSource
}

//////
// Packaging and deployment

tasks.withType(Jar) {
tasks.withType(Jar).configureEach {
def moduleName = rootProject.name
if (rootProject == project) {
archiveBaseName = project.name
Expand All @@ -297,8 +301,8 @@ allprojects {
}
manifest {
attributes('Implementation-Title': archiveBaseName,
'Implementation-Version': project.version,
'Automatic-Module-Name': moduleName.replaceAll("-","_"))
'Implementation-Version': project.version,
'Automatic-Module-Name': moduleName.replaceAll("-", "_"))
}
from(rootProject.projectDir) {
include 'DISCLAIMER'
Expand All @@ -320,6 +324,11 @@ allprojects {
sign configurations.archives
}

tasks.register('sourceJar', Jar) {
from sourceSets.main.allJava
archiveClassifier = "source"
}

publishing {
repositories {
maven {
Expand All @@ -336,7 +345,7 @@ allprojects {
project.logger.info('Reading .m2/settings.xml')
def serverId = (project.properties['distMgmtServerId'] ?: isRelease
? 'apache.releases.https' : 'apache.snapshots.https')
def m2SettingCreds = new XmlSlurper().parse(settingsXml).servers.server.find { server -> serverId.equals(server.id.text()) }
def m2SettingCreds = new XmlParser().parse(settingsXml).servers.server.find { server -> (serverId == server.id.text()) }
if (m2SettingCreds) {
project.logger.info('Found matching credentials from .m2/settings.xml')
credentials {
Expand Down Expand Up @@ -370,7 +379,7 @@ allprojects {
MavenDeployment(MavenPublication) { publication ->
if (project != rootProject) {
from components.java
artifact sourcesJar { classifier 'sources' }
artifact sourceJar
}
groupId 'io.consensys.protocols'
artifactId 'tuweni-' + project.name
Expand Down Expand Up @@ -494,13 +503,13 @@ allprojects {
}
}

tasks.withType(Sign) {
tasks.withType(Sign).configureEach {
onlyIf {
System.getenv('ENABLE_SIGNING') == 'true'
}
}

tasks.withType(GenerateModuleMetadata) {
tasks.withType(GenerateModuleMetadata).configureEach {
enabled = false
}

Expand Down Expand Up @@ -573,7 +582,7 @@ dokkaHtml {
}
}

project.task("checkNotice") {
tasks.register('checkNotice') {
def lines = file("NOTICE").readLines()
def expected = "Copyright 2023-${LocalDate.now().getYear()} The Machine Consultancy LLC"
for (line in lines) {
Expand Down
2 changes: 1 addition & 1 deletion bytes/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies {
implementation 'org.connid:framework-internal'
compileOnly 'com.google.code.findbugs:jsr305'
compileOnly 'com.google.errorprone:error_prone_annotations'
compileOnly 'io.vertx:vertx-core'
api 'io.vertx:vertx-core'

testImplementation 'io.vertx:vertx-core'
testImplementation 'org.junit.jupiter:junit-jupiter-api'
Expand Down
6 changes: 3 additions & 3 deletions dependency-versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ dependencyManagement {
dependency('org.infinispan:infinispan-cachestore-rocksdb:15.0.0.Dev02')


dependency('org.jetbrains:annotations:23.1.0')
dependencySet(group: 'org.jetbrains.kotlin', version: '1.9.0-Beta') {
dependency('org.jetbrains:annotations:26.0.1')
dependencySet(group: 'org.jetbrains.kotlin', version: '2.0.21') {
entry 'kotlin-reflect'
entry 'kotlin-stdlib'
entry 'kotlin-stdlib-jdk8'
}
dependencySet(group: 'org.jetbrains.kotlinx', version: '1.7.3') {
dependencySet(group: 'org.jetbrains.kotlinx', version: '1.9.0') {
entry 'kotlinx-coroutines-core'
entry 'kotlinx-coroutines-jdk8'
}
Expand Down
5 changes: 2 additions & 3 deletions devp2p/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ dependencies {
implementation 'org.slf4j:slf4j-api'
implementation 'org.jetbrains.kotlin:kotlin-stdlib'


compileOnly 'org.bouncycastle:bcprov-jdk15on'

testImplementation project(':junit')
Expand All @@ -44,11 +43,11 @@ dependencies {
}

application {
mainClassName = 'org.apache.tuweni.devp2p.v5.ScraperApp'
mainClass = 'org.apache.tuweni.devp2p.v5.ScraperApp'
applicationName = 'scraper'
}

task v4ScraperApp(type: CreateStartScripts) {
tasks.register('v4ScraperApp', CreateStartScripts) {
mainClass = "org.apache.tuweni.devp2p.ScraperApp"
applicationName = "v4scraper"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ internal enum class PacketType(
}

init {
require(typeId <= PacketType.MAX_VALUE) { "Packet typeId must be in range [0x00, 0x80)" }
require(typeId <= 0x7F) { "Packet typeId must be in range [0x00, 0x80)" }
}

abstract fun decode(
Expand Down
10 changes: 5 additions & 5 deletions dist/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ apply plugin: 'distribution'

jar { enabled = false }

task createBinaryLicense {
tasks.register('createBinaryLicense') {
description "Create a LICENSE file with all dependencies"

doLast {
Expand All @@ -33,7 +33,7 @@ task createBinaryLicense {
}
}

task createBinaryNotice {
tasks.register('createBinaryNotice') {
description "Create a NOTICE file with all dependencies"

doLast {
Expand All @@ -52,7 +52,7 @@ static def mandatoryFiles(CopySpec spec) {
spec.into('license-reports') { from '../build/dependency-license' }
}

task builtGradleProperties() {
tasks.register('builtGradleProperties') {
doLast {
project.buildDir.mkdirs()
new File(project.buildDir, "gradle.properties").text = """
Expand Down Expand Up @@ -132,7 +132,7 @@ distributions {
from { project(':eth-crawler').startScripts.outputs.files }
from { project(':jsonrpc-app').startScripts.outputs.files }
from { project(':stratum-proxy').startScripts.outputs.files }
fileMode = 0755
dirPermissions { unix(0755) }
}
}
}
Expand Down Expand Up @@ -175,7 +175,7 @@ distributions {
}
}

task addDependencies() {
tasks.register('addDependencies') {
doLast {
def deps = []
rootProject.subprojects.each { s ->
Expand Down
6 changes: 4 additions & 2 deletions eth-client-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ dependencies {
}

application {
mainClassName = 'org.apache.tuweni.ethclient.EthereumClientAppKt'
mainClass = 'org.apache.tuweni.ethclient.EthereumClientAppKt'
applicationName = 'tuweni'
}

tasks.register("bootnode", CreateStartScripts) {
applicationName = "bootnode"
outputDir = file("build/scripts")
mainClassName = 'org.apache.tuweni.ethclient.BootnodeAppKt'
mainClass = 'org.apache.tuweni.ethclient.BootnodeAppKt'
classpath = project.tasks.getAt(JavaPlugin.JAR_TASK_NAME).outputs.files.plus(project.configurations.getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME))
}

distTar.dependsOn "bootnode"
distZip.dependsOn "bootnode"
assemble.dependsOn "bootnode"
2 changes: 1 addition & 1 deletion eth-crawler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ dependencies {
}

application {
mainClassName = 'org.apache.tuweni.eth.crawler.CrawlerApp'
mainClass = 'org.apache.tuweni.eth.crawler.CrawlerApp'
applicationName = 'crawler'
}
6 changes: 4 additions & 2 deletions eth-faucet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ bootJar {

jar {
enabled = true
classifier = ''
archiveClassifier = ''
}

mainClassName = 'org.apache.tuweni.faucet.FaucetApplicationKt'
application {
mainClass = 'org.apache.tuweni.faucet.FaucetApplicationKt'
}

dependencies {
implementation 'com.fasterxml.jackson.core:jackson-databind'
Expand Down
Loading

0 comments on commit dc54931

Please sign in to comment.