Skip to content

Commit

Permalink
ci: using JDK 11+ to compile and JDK 8 to run junit (8) (#1870)
Browse files Browse the repository at this point in the history
  • Loading branch information
suztomo authored May 25, 2022
1 parent 27f6482 commit 4143583
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 4 deletions.
32 changes: 30 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java: [8, 11, 17]
java: [11, 17]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
Expand All @@ -36,14 +36,42 @@ jobs:
- run: .kokoro/build.sh
env:
JOB_TYPE: test
units-java8:
name: "units (8)"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: 8
distribution: zulu
- run: echo "JAVA8_HOME=${JAVA_HOME}" >> $GITHUB_ENV
shell: bash
- uses: actions/setup-java@v3
with:
java-version: 11
distribution: zulu
- run: echo "JAVA11_HOME=${JAVA_HOME}" >> $GITHUB_ENV
shell: bash
- run: .kokoro/build.sh
env:
JOB_TYPE: test
windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 8
distribution: zulu
- run: echo "JAVA8_HOME=${JAVA_HOME}" >> $GITHUB_ENV
shell: bash
- uses: actions/setup-java@v3
with:
java-version: 11
distribution: zulu
- run: echo "JAVA11_HOME=${JAVA_HOME}" >> $GITHUB_ENV
shell: bash
- run: java -version
- run: .kokoro/build.bat
env:
Expand Down
20 changes: 19 additions & 1 deletion .kokoro/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ cd ${scriptDir}/..
# include common functions
source ${scriptDir}/common.sh

function setJava() {
export JAVA_HOME=$1
export PATH=${JAVA_HOME}/bin:$PATH
}

# units-java8 uses both JDK 11 and JDK 8. GraalVM dependencies require JDK 11 to
# compile the classes touching GraalVM classes.
if [ ! -z "${JAVA11_HOME}" ]; then
setJava "${JAVA11_HOME}"
fi

# Print out Maven & Java version
mvn -version
echo ${JOB_TYPE}
Expand All @@ -42,12 +53,19 @@ if [[ ! -z "${GOOGLE_APPLICATION_CREDENTIALS}" && "${GOOGLE_APPLICATION_CREDENTI
export GOOGLE_APPLICATION_CREDENTIALS=$(realpath ${KOKORO_GFILE_DIR}/${GOOGLE_APPLICATION_CREDENTIALS})
fi

# units-java8 uses both JDK 11 and JDK 8. We ensure the generated class files
# are compatible with Java 8 when running tests.
if [ ! -z "${JAVA8_HOME}" ]; then
setJava "${JAVA8_HOME}"
mvn -version
fi

RETURN_CODE=0
set +e

case ${JOB_TYPE} in
test)
mvn test -B \
mvn test -B -V \
-Dclirr.skip=true \
-Denforcer.skip=true \
-Djava.net.preferIPv4Stack=true
Expand Down
2 changes: 1 addition & 1 deletion .kokoro/release/common.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ build_file: "java-spanner/.kokoro/trampoline.sh"
# Configure the docker image for kokoro-trampoline.
env_vars: {
key: "TRAMPOLINE_IMAGE"
value: "gcr.io/cloud-devrel-kokoro-resources/java8"
value: "gcr.io/cloud-devrel-kokoro-resources/java11"
}

before_action {
Expand Down
2 changes: 2 additions & 0 deletions owlbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
".kokoro/presubmit/java8-samples.cfg",
".kokoro/presubmit/java11-samples.cfg",
".kokoro/presubmit/samples.cfg",
".kokoro/release/common.cfg",
"samples/install-without-bom/pom.xml",
"samples/snapshot/pom.xml",
"samples/snippets/pom.xml",
Expand All @@ -40,6 +41,7 @@
".github/release-please.yml",
".github/blunderbuss.yml",
".github/workflows/samples.yaml",
".github/workflows/ci.yaml",
".kokoro/build.sh",
]
)
13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,17 @@
</plugins>
</reporting>

<profiles>
<profile>
<!-- JDK 9+ has the "release" option to ensure the generated bytecode is
compatible with Java 8. -->
<id>compiler-release-8</id>
<activation>
<jdk>[9,]</jdk>
</activation>
<properties>
<maven.compiler.release>8</maven.compiler.release>
</properties>
</profile>
</profiles>
</project>

0 comments on commit 4143583

Please sign in to comment.