diff --git a/cj-btc-cli/build.gradle b/cj-btc-cli/build.gradle index 24358ace..58f6ac0b 100644 --- a/cj-btc-cli/build.gradle +++ b/cj-btc-cli/build.gradle @@ -4,12 +4,6 @@ */ plugins { id 'java-library' - // Instead of using 'org.graalvm.buildtools.native' directly we need to include - // the micronaut application plugin to avoid a Gradle bug: - // See: https://github.com/micronaut-projects/micronaut-gradle-plugin/issues/706 - // and: https://github.com/gradle/gradle/issues/17559 - //id 'org.graalvm.buildtools.native' version '0.9.28' - id("io.micronaut.application") version "${micronautAppGradlePluginVersion}" } ext.moduleName = 'org.consensusj.bitcoin.cli' @@ -29,7 +23,7 @@ dependencies { api project(':cj-btc-jsonrpc') // Add SLF4J runtime adapter for JDK logging for GraalVM native-image build of bitcoin CLI tool - nativeImageClasspath "org.slf4j:slf4j-jdk14:${slf4jVersion}" + nativeToolImplementation "org.slf4j:slf4j-jdk14:${slf4jVersion}" testImplementation "org.apache.groovy:groovy:${groovyVersion}" @@ -47,22 +41,25 @@ jar { } } -graalvmNative { - binaries { - main { - mainClass = mainClassName - imageName = 'cj-bitcoin-cli' - } - test { - imageName = 'cj-bitcoin-cli-dbg' - } - } - binaries.all { - sharedLibrary = false - buildArgs.add('--verbose') - } + +// Compile a native image using GraalVM's native-image tool +// Graal must be installed at $JAVA_HOME +tasks.register('nativeCompile', Exec) { + dependsOn jar + workingDir = projectDir + executable = "${System.env.JAVA_HOME}/bin/native-image" + args = ['--verbose', + '--no-fallback', + '-cp', "${-> configurations.nativeToolImplementation.asPath}", // Lazy configuration resolution + '-jar', jar.archiveFile.get(), + '-H:Path=build', + '-H:Name=cj-bitcoin-cli', + '-H:EnableURLProtocols=http,https', + '-H:+ReportUnsupportedElementsAtRuntime' + ] } + // Test Structure sourceSets { integrationTest { diff --git a/consensusj-jsonrpc-cli/build.gradle b/consensusj-jsonrpc-cli/build.gradle index afbfdbe2..368d2b1c 100644 --- a/consensusj-jsonrpc-cli/build.gradle +++ b/consensusj-jsonrpc-cli/build.gradle @@ -4,12 +4,6 @@ */ plugins { id 'java-library' - // Instead of using 'org.graalvm.buildtools.native' directly we need to include - // the micronaut application plugin to avoid a Gradle bug: - // See: https://github.com/micronaut-projects/micronaut-gradle-plugin/issues/706 - // and: https://github.com/gradle/gradle/issues/17559 - //id 'org.graalvm.buildtools.native' version '0.9.28' - id("io.micronaut.application") version "${micronautAppGradlePluginVersion}" } tasks.withType(JavaCompile).configureEach { @@ -26,7 +20,7 @@ dependencies { api 'commons-cli:commons-cli:1.6.0' // Add SLF4J runtime adapter for JDK logging for GraalVM native-image build of jsonrpc tool - nativeImageClasspath "org.slf4j:slf4j-jdk14:${slf4jVersion}" + nativeToolImplementation "org.slf4j:slf4j-jdk14:${slf4jVersion}" testImplementation "org.apache.groovy:groovy:${groovyVersion}" @@ -45,19 +39,22 @@ jar { } } -graalvmNative { - binaries { - main { - mainClass = mainClassName - imageName = 'jsonrpc' - } - test { - imageName = 'jsonrpc-dbg' - } - } - binaries.all { - sharedLibrary = false - buildArgs.add('--initialize-at-build-time=com.fasterxml.jackson.annotation.JsonProperty$Access') - buildArgs.add('--verbose') - } +// Compile a native image using GraalVM's native-image tool +// Graal must be installed at $JAVA_HOME +tasks.register('nativeCompile', Exec) { + dependsOn jar + workingDir = projectDir + executable = "${System.env.JAVA_HOME}/bin/native-image" + args = ['--verbose', + '--no-fallback', + '-cp', "${-> configurations.nativeToolImplementation.asPath}", // Lazy configuration resolution + '-jar', jar.archiveFile.get(), + '-H:Path=build', + '-H:Name=jsonrpc', + '--initialize-at-build-time=com.fasterxml.jackson.annotation.JsonProperty$Access', + '-H:IncludeResources=logging.properties', + '-H:EnableURLProtocols=http,https', + '-H:+ReportUnsupportedElementsAtRuntime', + '-H:+ReportExceptionStackTraces' + ] } diff --git a/consensusj-jsonrpc/build.gradle b/consensusj-jsonrpc/build.gradle index c8b948e2..50445d73 100644 --- a/consensusj-jsonrpc/build.gradle +++ b/consensusj-jsonrpc/build.gradle @@ -1,11 +1,5 @@ plugins { id 'java-library' - // Instead of using 'org.graalvm.buildtools.native' directly we need to include - // the micronaut application plugin to avoid a Gradle bug: - // See: https://github.com/micronaut-projects/micronaut-gradle-plugin/issues/706 - // and: https://github.com/gradle/gradle/issues/17559 - //id 'org.graalvm.buildtools.native' version '0.9.28' - id("io.micronaut.application") version "${micronautAppGradlePluginVersion}" } configurations { @@ -17,7 +11,7 @@ dependencies { api "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}" // Add SLF4J runtime adapter for JDK logging for GraalVM native-image build of MathService/Tool - nativeImageClasspath "org.slf4j:slf4j-jdk14:${slf4jVersion}" + nativeSampleImplementation "org.slf4j:slf4j-jdk14:${slf4jVersion}" testImplementation project(':cj-btc-jsonrpc') @@ -50,18 +44,20 @@ test { } } -graalvmNative { - binaries { - main { - mainClass = mainClassName - imageName = 'MathTool' - } - test { - imageName = 'MathTool-dbg' - } - } - binaries.all { - sharedLibrary = false - buildArgs.add('--verbose') - } +// Compile a native image of the MathService tool sample using Graal's native-image tool +// Graal must be installed at $JAVA_HOME +tasks.register('nativeCompile', Exec) { + dependsOn jar + workingDir = projectDir + executable = "${System.env.JAVA_HOME}/bin/native-image" + args = ['--verbose', + '--no-fallback', + '-cp', "${-> configurations.nativeSampleImplementation.asPath}", // Lazy configuration resolution + '-jar', jar.archiveFile.get(), + '-H:Path=build', + '-H:Name=MathTool', + '-H:+AllowIncompleteClasspath', + '-H:+ReportUnsupportedElementsAtRuntime', + '-H:+ReportExceptionStackTraces' + ] }