Skip to content

Commit

Permalink
Gradle build: Use tasks.register() and .confgureEach() throughout the…
Browse files Browse the repository at this point in the history
… build
  • Loading branch information
msgilligan committed Sep 28, 2023
1 parent 805f938 commit f3a645c
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 44 deletions.
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand All @@ -77,15 +77,15 @@ subprojects {
withSourcesJar()
}

tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.release = 11
}

compileJava {
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
Expand All @@ -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 }

3 changes: 1 addition & 2 deletions gradle/github-pages.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
2 changes: 1 addition & 1 deletion gradle/groovydoc.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions gradle/javadoc.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
45 changes: 25 additions & 20 deletions omnij-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {

ext.moduleName = 'foundation.omni.cli'

tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.release = 17
}

Expand Down Expand Up @@ -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'
]
}

Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion omnij-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion omnij-dsl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {

ext.moduleName = 'foundation.omni.dsl.groovy'

tasks.withType(GroovyCompile) {
tasks.withType(GroovyCompile).configureEach {
targetCompatibility = 1.8
}

Expand Down
2 changes: 1 addition & 1 deletion omnij-jsonrpc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies {
testImplementation project(':omnij-dsl')
}

tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.compilerArgs << '-parameters' // For use by jackson-databind
}

Expand Down
19 changes: 10 additions & 9 deletions omnij-rpc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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/**'
}
2 changes: 1 addition & 1 deletion omnij-tx-records/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id 'java-library'
}

tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.release = 17
}

Expand Down

0 comments on commit f3a645c

Please sign in to comment.