From f3a645c26fd14cf0b6c74d18152b88670744972a Mon Sep 17 00:00:00 2001 From: Sean Gilligan Date: Thu, 28 Sep 2023 12:53:15 -0700 Subject: [PATCH] Gradle build: Use tasks.register() and .confgureEach() throughout the build --- build.gradle | 10 ++++---- gradle/github-pages.gradle | 3 +-- gradle/groovydoc.gradle | 2 +- gradle/javadoc.gradle | 6 ++--- omnij-cli/build.gradle | 45 +++++++++++++++++++---------------- omnij-core/build.gradle | 2 +- omnij-dsl/build.gradle | 2 +- omnij-jsonrpc/build.gradle | 2 +- omnij-rpc/build.gradle | 19 ++++++++------- omnij-tx-records/build.gradle | 2 +- 10 files changed, 49 insertions(+), 44 deletions(-) diff --git a/build.gradle b/build.gradle index d1efade6..19eb741a 100644 --- a/build.gradle +++ b/build.gradle @@ -63,7 +63,7 @@ subprojects { testRuntimeOnly "org.slf4j:slf4j-jdk14:${slf4jVersion}" // Runtime implementation of slf4j for tests } - configurations.all { + configurations.configureEach { // Ensure usage of Groovy 4.0 which has new Maven co-ordinates resolutionStrategy.capabilitiesResolution.all { if (capability.group.equals("org.codehaus.groovy")) { @@ -77,7 +77,7 @@ subprojects { withSourcesJar() } - tasks.withType(JavaCompile) { + tasks.withType(JavaCompile).configureEach { options.release = 11 } @@ -85,7 +85,7 @@ subprojects { options.compilerArgs << '-Xlint:deprecation' << '-Xlint:unchecked' } - tasks.withType(AbstractArchiveTask) { + tasks.withType(AbstractArchiveTask).configureEach { // This should result in reproducible JAR builds // See: https://docs.gradle.org/current/userguide/working_with_files.html#sec:reproducible_archives preserveFileTimestamps = false @@ -106,11 +106,11 @@ apply from: 'gradle/asciidoctor.gradle' apply from: 'gradle/maven-publish.gradle' apply from: 'gradle/github-pages.gradle' -task testReport(type: TestReport) { +tasks.register('testReport', TestReport) { destinationDir = file("$buildDir/reports/allTests") // Include the results from the `test` task in all subprojects reportOn subprojects*.test } -task buildCI(dependsOn: [build, testReport, javadocAll, groovydocAll, asciidoctor]) +tasks.register('buildCI') { dependsOn build, testReport, javadocAll, groovydocAll, asciidoctor } diff --git a/gradle/github-pages.gradle b/gradle/github-pages.gradle index 0198e5e9..e3529d08 100644 --- a/gradle/github-pages.gradle +++ b/gradle/github-pages.gradle @@ -31,5 +31,4 @@ gitPublish { gitPublishCopy.dependsOn javadocAll, groovydocAll, asciidoctor -task publishSite(dependsOn: gitPublishPush, group: 'render', - description: "Publishes ${siteDir}, JavaDocs, and GroovyDocs to Github Pages on 'gh-pages' branch") +tasks.register('publishSite') { dependsOn gitPublishPush } diff --git a/gradle/groovydoc.gradle b/gradle/groovydoc.gradle index 39709458..6db5beb9 100644 --- a/gradle/groovydoc.gradle +++ b/gradle/groovydoc.gradle @@ -31,7 +31,7 @@ allprojects { groovydoc groovydocSpec } -task groovydocAll(type: Groovydoc) +tasks.register('groovydocAll', Groovydoc) groovydocAll { destinationDir = new File(buildDir, 'docs/groovydoc') source = groovydoc.source diff --git a/gradle/javadoc.gradle b/gradle/javadoc.gradle index 4e62ab90..65339c47 100644 --- a/gradle/javadoc.gradle +++ b/gradle/javadoc.gradle @@ -20,9 +20,9 @@ allprojects { javadoc javadocSpec } -task javadocAll(type: Javadoc) { - source subprojects.collect {project -> project.sourceSets.main.allJava } - classpath = files(subprojects.collect {project -> project.sourceSets.main.compileClasspath}) +tasks.register('javadocAll', Javadoc) { + source subprojects.collect { project -> project.sourceSets.main.allJava } + classpath = files(subprojects.collect { project -> project.sourceSets.main.compileClasspath }) } javadocAll javadocSpec << { options.overview = rootProject.file('src/main/java/overview.html').toPath() diff --git a/omnij-cli/build.gradle b/omnij-cli/build.gradle index 23ab1678..eb3e958d 100644 --- a/omnij-cli/build.gradle +++ b/omnij-cli/build.gradle @@ -5,7 +5,7 @@ plugins { ext.moduleName = 'foundation.omni.cli' -tasks.withType(JavaCompile) { +tasks.withType(JavaCompile).configureEach { options.release = 17 } @@ -59,20 +59,21 @@ jar { // Compile a native image using GraalVM's native-image tool // Graal must be installed at $GRAALVM_HOME -task nativeCompile(type:Exec, dependsOn: jar) { +tasks.register('nativeCompile', Exec) { + dependsOn jar workingDir = projectDir executable = "${System.env.GRAALVM_HOME}/bin/native-image" - args = [ '--verbose', - '--no-fallback', - '-cp', "${-> configurations.runtimeClasspath.asPath}", // Lazy configuration resolution - '-jar', jar.archiveFile.get(), - '-H:Path=build', - '-H:Name=omnij-consensus-tool', - '--initialize-at-build-time=com.fasterxml.jackson.annotation.JsonProperty$Access', - '-H:IncludeResources=logging.properties', - '-H:ReflectionConfigurationFiles=graal-reflection-config.json', - '-H:EnableURLProtocols=http,https', - '-H:+ReportUnsupportedElementsAtRuntime' + args = ['--verbose', + '--no-fallback', + '-cp', "${-> configurations.runtimeClasspath.asPath}", // Lazy configuration resolution + '-jar', jar.archiveFile.get(), + '-H:Path=build', + '-H:Name=omnij-consensus-tool', + '--initialize-at-build-time=com.fasterxml.jackson.annotation.JsonProperty$Access', + '-H:IncludeResources=logging.properties', + '-H:ReflectionConfigurationFiles=graal-reflection-config.json', + '-H:EnableURLProtocols=http,https', + '-H:+ReportUnsupportedElementsAtRuntime' ] } @@ -93,7 +94,7 @@ sourceSets { } } -task regTest(type: Test) { +tasks.register('regTest', Test) { useJUnitPlatform() testClassesDirs = project.sourceSets.integrationTest.output.classesDirs classpath = project.sourceSets.integrationTest.runtimeClasspath @@ -110,33 +111,37 @@ task regTest(type: Test) { systemProperty 'regtest', true systemProperty 'java.util.logging.config.file', "${project.projectDir}/src/integ/logging.properties" - systemProperties ([ "omni.test.rpcTestUser": rpcTestUser, - "omni.test.rpcTestPassword": rpcTestPassword, + systemProperties(["omni.test.rpcTestUser" : rpcTestUser, + "omni.test.rpcTestPassword": rpcTestPassword, ]) include 'foundation/omni/cli/**' } def currencyID = 1 -task getCoreConsensus(dependsOn: 'classes', type: JavaExec) { +tasks.register('getCoreConsensus', JavaExec) { + dependsOn 'classes' main = 'foundation.omni.consensus.OmniCoreConsensusTool' args = [currencyID, 'build/mastercore_consensus.txt'] classpath = sourceSets.main.runtimeClasspath } -task getOmniConsensus(dependsOn: 'classes', type: JavaExec) { +tasks.register('getOmniConsensus', JavaExec) { + dependsOn 'classes' main = 'foundation.omni.consensus.OmniwalletConsensusTool' args = [currencyID, 'build/omniwallet_consensus.txt'] classpath = sourceSets.main.runtimeClasspath } -task getConsensus(dependsOn: ['getCoreConsensus', 'getOmniConsensus']) { +tasks.register('getConsensus') { + dependsOn 'getCoreConsensus', 'getOmniConsensus' doLast { logger.info "Consensus files are in build/*_consensus.txt" } } -task runOmniConsensusCLI(dependsOn: 'classes', type: JavaExec) { +tasks.register('runOmniConsensusCLI', JavaExec) { + dependsOn 'classes' main = 'foundation.omni.cli.ConsensusCLI' args = ['-regtest', '-rpcwait', '-rpcconnect=127.0.0.1', "-property=${currencyID}"] classpath = sourceSets.main.runtimeClasspath diff --git a/omnij-core/build.gradle b/omnij-core/build.gradle index d51b4a9f..fe995dbc 100644 --- a/omnij-core/build.gradle +++ b/omnij-core/build.gradle @@ -9,7 +9,7 @@ dependencies { api 'javax.money:money-api:1.1' } -tasks.withType(JavaCompile) { +tasks.withType(JavaCompile).configureEach { options.compilerArgs << '-parameters' // For use by jackson-databind } diff --git a/omnij-dsl/build.gradle b/omnij-dsl/build.gradle index 05bdf1d2..5eaa198b 100644 --- a/omnij-dsl/build.gradle +++ b/omnij-dsl/build.gradle @@ -4,7 +4,7 @@ plugins { ext.moduleName = 'foundation.omni.dsl.groovy' -tasks.withType(GroovyCompile) { +tasks.withType(GroovyCompile).configureEach { targetCompatibility = 1.8 } diff --git a/omnij-jsonrpc/build.gradle b/omnij-jsonrpc/build.gradle index 5600936c..120c851e 100644 --- a/omnij-jsonrpc/build.gradle +++ b/omnij-jsonrpc/build.gradle @@ -20,7 +20,7 @@ dependencies { testImplementation project(':omnij-dsl') } -tasks.withType(JavaCompile) { +tasks.withType(JavaCompile).configureEach { options.compilerArgs << '-parameters' // For use by jackson-databind } diff --git a/omnij-rpc/build.gradle b/omnij-rpc/build.gradle index 8c195fb3..330639c4 100644 --- a/omnij-rpc/build.gradle +++ b/omnij-rpc/build.gradle @@ -89,32 +89,33 @@ class RegTest extends IntegrationTest { } } -task integrationTest(type: IntegrationTest) { +tasks.register('integrationTest', IntegrationTest) { description = 'Runs Bitcoin and Omni Core integration tests.' } -task activationRegTest(type: RegTest) { +tasks.register('activationRegTest', RegTest) { description = 'Tests Omni Protocol feature activations in regtest mode.' include 'foundation/omni/test/rpc/activation/*' } -task regTest(type: RegTest, dependsOn: 'activationRegTest') { +tasks.register('regTest', RegTest) { + dependsOn 'activationRegTest' description = 'Tests Omni Core RPC calls against an instance of omnicored running in regtest mode.' include 'foundation/omni/test/rpc/**', 'foundation/omni/test/scripts/**', 'foundation/omni/test/tx/**' exclude 'foundation/omni/test/rpc/activation/*' } -task consensusTest(type: IntegrationTest) { +tasks.register('consensusTest', IntegrationTest) { description = 'Compares balances for multiple Omni Protocol currencies against public data providers.' systemProperty 'regtest', false - systemProperties ([ "omni.test.rpcTestUser": rpcTestUser, - "omni.test.rpcTestPassword": rpcTestPassword, - "omni.test.stableOmniRpcHost": stableOmniRpcHost, - "omni.test.stableOmniRpcUser": stableOmniRpcUser, - "omni.test.stableOmniRpcPassword": stableOmniRpcPassword + systemProperties(["omni.test.rpcTestUser" : rpcTestUser, + "omni.test.rpcTestPassword" : rpcTestPassword, + "omni.test.stableOmniRpcHost" : stableOmniRpcHost, + "omni.test.stableOmniRpcUser" : stableOmniRpcUser, + "omni.test.stableOmniRpcPassword": stableOmniRpcPassword ]) include 'foundation/omni/test/consensus/**' } diff --git a/omnij-tx-records/build.gradle b/omnij-tx-records/build.gradle index dabc45a1..566b4fd6 100644 --- a/omnij-tx-records/build.gradle +++ b/omnij-tx-records/build.gradle @@ -2,7 +2,7 @@ plugins { id 'java-library' } -tasks.withType(JavaCompile) { +tasks.withType(JavaCompile).configureEach { options.release = 17 }