Skip to content

Commit

Permalink
Set Java toolchain for gradle build and fix Sonatype URL
Browse files Browse the repository at this point in the history
  • Loading branch information
popematt committed Apr 26, 2024
1 parent 2a87e2b commit 5409778
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 74 deletions.
59 changes: 36 additions & 23 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,55 @@ on:


jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- java: 8
- java: 11
upload_reports: true
- java: 17
fail-fast: false
build-and-test:
runs-on: "codebuild-ion-java-${{ github.run_id }}-${{ github.run_attempt }}-arm-3.0-large"
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 }}
- uses: gradle/gradle-build-action@e2097ccd7e8ed48671dc068ac4efa86d25745b39 # v3.3.1
with:
arguments: build
- name: Test minified JAR
uses: gradle/gradle-build-action@e2097ccd7e8ed48671dc068ac4efa86d25745b39 # v3.3.1
java-version: 22
- name: Setup Gradle
uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43
with:
arguments: minifyTest
- run: ./ion-test-driver-run version
- if: ${{ matrix.upload_reports }}
uses: codecov/codecov-action@84508663e988701840491b86de86b666e8a86bed # v4.3.0
validate-wrappers: true
- run: ./gradlew build
- uses: codecov/codecov-action@84508663e988701840491b86de86b666e8a86bed # v4.3.0
with:
files: build/reports/jacoco/test/jacocoTestReport.xml
- uses: actions/upload-artifact@1eb3cb2b3e0f29609092a73eb033bb759a334595 # v4.1.0
with:
name: spotbugs-report-${{ matrix.runs-on }}-java-${{ matrix.java }}
name: spotbugs-report
path: build/reports/spotbugs/
- name: ion-java-cli sanity check
run: ./ion-test-driver-run version

verify-jre-compatibility:
strategy:
fail-fast: false
matrix:
java: [8, 11, 17, 21]
runs-on: "codebuild-ion-java-${{ github.run_id }}-${{ github.run_attempt }}-arm-3.0-large"
steps:
- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
with:
submodules: recursive
- name: Setup Java
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: 'corretto'
java-version: |
8
${{matrix.java}}
- name: Setup Gradle
uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43
with:
cache-read-only: true
validate-wrappers: true
- run: ./gradlew minifyTest${{matrix.java}}

check-version:
# Ensures that the version is not a release (i.e. -SNAPSHOT) or if it is a release version,
Expand Down
23 changes: 14 additions & 9 deletions .github/workflows/publish-release-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,23 @@ jobs:
echo "Project Version: $PROJECT_VERSION"
echo "Release Tag: $RELEASE_TAG"
[ "$PROJECT_VERSION" = "$RELEASE_TAG" ] || exit 1
- name: Build Release Artifacts
uses: gradle/gradle-build-action@e2097ccd7e8ed48671dc068ac4efa86d25745b39 # v3.3.1
- uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
arguments: build cyclonedxBom
- name: Publish to Sonatype
uses: gradle/gradle-build-action@e2097ccd7e8ed48671dc068ac4efa86d25745b39 # v3.3.1
distribution: 'corretto'
java-version: |
8
11
17
21
- uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43
with:
arguments: publishToSonatype
validate-wrappers: true
- name: Build Release Artifacts
run: ./gradlew build cyclonedxBom
- name: Publish to Sonatype
run: ./gradlew publishToSonatype
- name: Close and Release Sonatype Staging Repository
uses: gradle/gradle-build-action@e2097ccd7e8ed48671dc068ac4efa86d25745b39 # v3.3.1
with:
arguments: closeAndReleaseSonatypeStagingRepository
run: ./gradlew closeAndReleaseSonatypeStagingRepository
- name: Upload Artifacts to GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
76 changes: 57 additions & 19 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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 {
Expand Down Expand Up @@ -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<JavaCompile> {
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<KotlinCompile<KotlinJvmOptions>> {
kotlinOptions {
Expand Down Expand Up @@ -451,28 +461,56 @@ 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<Test>("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<Test>("shadowTest") {
applyCommonTestConfig()
classpath = project.configurations.testRuntimeClasspath.get() + project.sourceSets.test.get().output + shadowJar.get().outputs.files
dependsOn(minifyJar)
}

val jvmSpecificMinifyTests = SUPPORTED_JRE_VERSIONS.map {
// Run the JUnit tests on the minified jar using the given java version for setting up the JRE
register<Test>("minifyTest$it") {
javaLauncher.set(
project.javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(it))
vendor.set(JvmVendorSpec.AMAZON)
}
)
applyCommonTestConfig()
classpath = project.configurations.testRuntimeClasspath.get() + project.sourceSets.test.get().output + minifyJar.outputs.files
dependsOn(minifyJar)
}
}.toTypedArray()

/**
* 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. However, they are
* mandatory as a prerequisite for publishing any release.
*
* They should all be run in the CI workflow for every PR, but it is best if they run concurrently
* in separate workflow steps.
*/
val minifyTest = register<Task>("minifyTest") {
group = "verification"
dependsOn(jvmSpecificMinifyTests)
}

publish { dependsOn(minifyTest) }

withType<Sign> {
setOnlyIf { isReleaseVersion && gradle.taskGraph.hasTask(":publish") }
}
Expand Down Expand Up @@ -523,7 +561,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) {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
29 changes: 17 additions & 12 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -133,26 +131,29 @@ 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.
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
case $MAX_FD in #(
'' | 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
Expand Down Expand Up @@ -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" \
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
6 changes: 6 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 5409778

Please sign in to comment.