diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2c14b54021..6257388b5a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,24 +11,16 @@ on: jobs: test: runs-on: ubuntu-latest - strategy: - matrix: - include: - - java: 8 - - java: 11 - upload_reports: true - - java: 17 - fail-fast: false steps: - uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3 with: submodules: recursive - uses: gradle/wrapper-validation-action@5188e9b5527a0a094cee21e2fe9a8ca44b4629af # v3.3.1 - - name: Use java ${{ matrix.java }} + - name: Setup Java uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: distribution: 'corretto' - java-version: ${{ matrix.java }} + java-version: 8 - uses: gradle/gradle-build-action@e2097ccd7e8ed48671dc068ac4efa86d25745b39 # v3.3.1 with: arguments: build @@ -37,8 +29,7 @@ jobs: with: arguments: minifyTest - run: ./ion-test-driver-run version - - if: ${{ matrix.upload_reports }} - uses: codecov/codecov-action@84508663e988701840491b86de86b666e8a86bed # v4.3.0 + - uses: codecov/codecov-action@84508663e988701840491b86de86b666e8a86bed # v4.3.0 with: files: build/reports/jacoco/test/jacocoTestReport.xml - uses: actions/upload-artifact@1eb3cb2b3e0f29609092a73eb033bb759a334595 # v4.1.0 diff --git a/build.gradle.kts b/build.gradle.kts index 8b92773b51..794b534490 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -55,6 +55,19 @@ repositories { google() } +// This list should be kept up to date to include all LTS versions of Corretto. +// These are the versions that we guarantee are supported by `ion-java`, though it can probably run on other versions too. +val SUPPORTED_JRE_VERSIONS = listOf(8, 11, 17, 21) + +java { + toolchain { + // Always build with the minimum supported Java version so that builds are reproducible, + // and so it automatically targets the min supported version. + languageVersion.set(JavaLanguageVersion.of(SUPPORTED_JRE_VERSIONS.min())) + vendor.set(JvmVendorSpec.AMAZON) + } +} + dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.0") @@ -78,9 +91,6 @@ val isReleaseVersion: Boolean = !version.toString().endsWith("SNAPSHOT") // The name we're checking for corresponds to the name that is set in the `publish-release-artifacts.yml` file. val isReleaseWorkflow: Boolean = System.getenv("GITHUB_WORKFLOW") == "Publish Release Artifacts" val generatedResourcesDir = "$buildDir/generated/main/resources" -lateinit var sourcesJar: AbstractArchiveTask -lateinit var javadocJar: AbstractArchiveTask -lateinit var minifyJar: ProGuardTask sourceSets { main { @@ -175,14 +185,14 @@ spotless { } } +// Tasks that must be visible outside the tasks block +lateinit var sourcesJar: AbstractArchiveTask +lateinit var javadocJar: AbstractArchiveTask +lateinit var minifyJar: ProGuardTask + tasks { withType { options.encoding = "UTF-8" - // The `release` option is not available for the Java 8 compiler, but if we're building with Java 8 we don't - // need it anyway. - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { - options.release.set(8) - } } withType> { kotlinOptions { @@ -451,28 +461,46 @@ tasks { maxHeapSize = "1g" // When this line was added Xmx 512m was the default, and we saw OOMs maxParallelForks = Math.max(1, Runtime.getRuntime().availableProcessors() / 2) useJUnitPlatform() - // report is always generated after tests run - finalizedBy(jacocoTestReport) } test { applyCommonTestConfig() + // report is always generated after tests run + finalizedBy(jacocoTestReport) } - /** Runs the JUnit test on the minified jar. */ - register("minifyTest") { - applyCommonTestConfig() - classpath = project.configurations.testRuntimeClasspath.get() + project.sourceSets.test.get().output + minifyJar.outputs.files - dependsOn(minifyJar) - } - - /** Runs the JUnit test on the shadow jar. */ + /** + * Runs the JUnit test on the shadow jar. + * Potentially useful for debugging issues that are not reproducible in the standard `test` task. + */ register("shadowTest") { applyCommonTestConfig() classpath = project.configurations.testRuntimeClasspath.get() + project.sourceSets.test.get().output + shadowJar.get().outputs.files dependsOn(minifyJar) } + /** + * Umbrella task for the JUnit tests on the minified jar for all supported JRE versions. + * + * This ensures that the built JAR will run properly on all the supported JREs. It is time consuming + * to run all tests for each JRE, so they are not included in the `build` task when running locally. + * However, they are included in the `build` task for a CI environment, and they are mandatory as a + * prerequisite for publishing any release. + */ + val minifyTest = register("minifyTest") { group = "verification" } + + publish { dependsOn(minifyTest) } + if (isCI) build { dependsOn(minifyTest) } + + SUPPORTED_JRE_VERSIONS.map { + register("minifyTest$it") { + javaLauncher.set(project.javaToolchains.launcherFor { languageVersion.set(JavaLanguageVersion.of(it)) }) + applyCommonTestConfig() + classpath = project.configurations.testRuntimeClasspath.get() + project.sourceSets.test.get().output + minifyJar.outputs.files + dependsOn(minifyJar) + } + }.forEach { minifyTest { dependsOn(it) } } + withType { setOnlyIf { isReleaseVersion && gradle.taskGraph.hasTask(":publish") } } @@ -523,7 +551,7 @@ nexusPublishing { // Documentation for this plugin, see https://github.com/gradle-nexus/publish-plugin/blob/v1.3.0/README.md this.repositories { sonatype { - nexusUrl.set(uri("https://aws.oss.sonatype.org/service/local/staging/deploy/maven2/")) + nexusUrl.set(uri("https://aws.oss.sonatype.org/service/local/")) // For CI environments, the username and password should be stored in // ORG_GRADLE_PROJECT_sonatypeUsername and ORG_GRADLE_PROJECT_sonatypePassword respectively. if (!isCI) { diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index ccebba7710..d64cd49177 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 37aef8d3f0..b82aa23a4f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 79a61d421c..1aa94a4269 100755 --- a/gradlew +++ b/gradlew @@ -83,10 +83,8 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,10 +131,13 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. @@ -144,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -152,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -197,11 +198,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/gradlew.bat b/gradlew.bat index 6689b85bee..7101f8e467 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/settings.gradle.kts b/settings.gradle.kts index 06a2b7f50d..054e32e32e 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,2 +1,8 @@ + +// Automatically resolve and download any missing JDK versions +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version("0.8.0") +} + rootProject.name = "ion-java" include("ion-java-cli")