Skip to content

Commit

Permalink
Update Bazel to use JDK 18.
Browse files Browse the repository at this point in the history
This CL updates Bazel to use JDK 18.

The source and target level are explicitly set to language level 8 so that downstream users are unaffected by this change.

In addition, I've added some validation to our GitHub Actions to check that the classes in our artifact jars all have the expected language level.

RELNOTES=N/A
PiperOrigin-RevId: 654943496
  • Loading branch information
bcorso authored and Dagger Team committed Jul 30, 2024
1 parent d55d61c commit d83ad30
Show file tree
Hide file tree
Showing 17 changed files with 286 additions and 67 deletions.
24 changes: 24 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,27 @@ build --host_javacopt=-g
# TODO(ronshapiro): explore how much work it would be to reenable this
build --javacopt="-Xep:BetaApi:OFF"
build --host_javacopt="-Xep:BetaApi:OFF"

# Note: This flag is required to prevent actions from clashing with each when
# reading/writing tmp files. Without this flag we get errors like:
#
# Error: Cannot use file /tmp/hsperfdata_runner/12 because it is locked by
# another process
#
# This flag will be enabled by default in Bazel 7.0.0, but for now we enable it
# manually. For more details: https://github.com/bazelbuild/bazel/issues/3236.
build --incompatible_sandbox_hermetic_tmp

# Sets the JDK for compiling sources and executing tests.
build --java_language_version=18
build --tool_java_language_version=18
build --java_runtime_version=remotejdk_18
build --tool_java_runtime_version=remotejdk_18

# Default source/target versions.
build --javacopt="-source 8 -target 8"

# Workaround for https://openjdk.java.net/jeps/411.
# See https://github.com/bazelbuild/bazel/issues/14502#issuecomment-1018366245.
build --jvmopt="-Djava.security.manager=allow"
build --jvmopt="--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED"
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.4.0
25 changes: 25 additions & 0 deletions .github/actions/artifact-verification-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: 'Artifact verification tests'
description: 'Runs verification tests on the Dagger LOCAL-SNAPSHOT artifacts.'

runs:
using: "composite"
steps:
- name: 'Check out repository'
uses: actions/checkout@v3
- name: 'Cache Gradle files'
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: 'Download local snapshot for tests'
uses: actions/download-artifact@v3
with:
name: local-snapshot
path: ~/.m2/repository/com/google/dagger
- name: 'Validate artifact jars'
run: ./util/validate-artifacts.sh
shell: bash
25 changes: 20 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ env:
USE_JAVA_VERSION: '11'
# This is required by AGP 8.3+.
USE_JAVA_VERSION_FOR_PLUGIN: '17'
# Our Bazel builds currently rely on 6.4.0. The version is set via
# baselisk by USE_BAZEL_VERSION: https://github.com/bazelbuild/bazelisk.
USE_BAZEL_VERSION: '6.4.0'
# The default Maven 3.9.0 has a regression so we manually install 3.8.7.
# https://issues.apache.org/jira/browse/MNG-7679
USE_MAVEN_VERSION: '3.8.7'
Expand Down Expand Up @@ -43,6 +40,13 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/bazel-test
artifact-verification-tests:
name: 'Artifact verification tests'
needs: bazel-build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/artifact-verification-tests
artifact-java-local-tests:
name: 'Artifact Java local tests'
needs: bazel-build
Expand Down Expand Up @@ -98,7 +102,12 @@ jobs:
name: 'Publish snapshot'
# TODO(bcorso): Consider also waiting on artifact-android-emulator-tests
# and artifact-android-emulator-legacy-api-tests after checking flakiness.
needs: [bazel-test, artifact-java-local-tests, artifact-android-local-tests, test-gradle-plugin]
needs: [
bazel-test, artifact-verification-tests,
artifact-java-local-tests,
artifact-android-local-tests,
test-gradle-plugin
]
if: github.event_name == 'push' && github.repository == 'google/dagger' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -177,7 +186,13 @@ jobs:
name: 'Clean up GitHub Action caches'
# TODO(bcorso): Consider also waiting on artifact-android-emulator-tests
# and artifact-android-emulator-legacy-api-tests after checking flakiness.
needs: [bazel-test, artifact-java-local-tests, artifact-android-local-tests, test-gradle-plugin]
needs: [
bazel-test,
artifact-verification-tests,
artifact-java-local-tests,
artifact-android-local-tests,
test-gradle-plugin
]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
18 changes: 14 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ env:
USE_JAVA_VERSION: '11'
# This is required by AGP 8.3+.
USE_JAVA_VERSION_FOR_PLUGIN: '17'
# Our Bazel builds currently rely on 6.4.0. The version is set via
# baselisk by USE_BAZEL_VERSION: https://github.com/bazelbuild/bazelisk.
USE_BAZEL_VERSION: '6.4.0'
DAGGER_RELEASE_VERSION: "${{ github.event.inputs.dagger_release_version }}"
# The default Maven 3.9.0 has a regression so we manually install 3.8.7.
# https://issues.apache.org/jira/browse/MNG-7679
Expand Down Expand Up @@ -45,6 +42,13 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/bazel-test
artifact-verification-tests:
name: 'Artifact verification tests'
needs: bazel-build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/artifact-verification-tests
artifact-java-local-tests:
name: 'Artifact Java local tests'
needs: bazel-build
Expand Down Expand Up @@ -80,7 +84,13 @@ jobs:
jdk: '${{ matrix.jdk }}'
publish-artifacts:
name: 'Publish Artifact'
needs: [bazel-test, artifact-java-local-tests, artifact-android-local-tests, test-gradle-plugin]
needs: [
bazel-test,
artifact-verification-tests,
artifact-java-local-tests,
artifact-android-local-tests,
test-gradle-plugin
]
runs-on: ubuntu-latest
steps:
- name: 'Install Java ${{ env.USE_JAVA_VERSION }}'
Expand Down
14 changes: 7 additions & 7 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ load("//tools/javadoc:javadoc.bzl", "javadoc_library")

package(default_visibility = ["//visibility:public"])

define_kt_toolchain(
name = "kotlin_toolchain",
api_version = "1.4",
jvm_target = "1.8",
language_version = "1.4",
)

package_group(
name = "src",
packages = ["//..."],
)

define_kt_toolchain(
name = "kotlin_toolchain",
api_version = "1.9",
jvm_target = "1.8",
language_version = "1.9",
)

java_library(
name = "dagger_with_compiler",
exported_plugins = ["//java/dagger/internal/codegen:component-codegen"],
Expand Down
21 changes: 9 additions & 12 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.


load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

#############################
Expand Down Expand Up @@ -118,13 +117,13 @@ http_archive(
# Load Robolectric repository
#############################

ROBOLECTRIC_VERSION = "4.4"
ROBOLECTRIC_VERSION = "4.11.1"

http_archive(
name = "robolectric",
sha256 = "d4f2eb078a51f4e534ebf5e18b6cd4646d05eae9b362ac40b93831bdf46112c7",
sha256 = "1ea1cfe67848decf959316e80dd69af2bbaa359ae2195efe1366cbdf3e968356",
strip_prefix = "robolectric-bazel-%s" % ROBOLECTRIC_VERSION,
urls = ["https://github.com/robolectric/robolectric-bazel/archive/%s.tar.gz" % ROBOLECTRIC_VERSION],
urls = ["https://github.com/robolectric/robolectric-bazel/releases/download/%s/robolectric-bazel-%s.tar.gz" % (ROBOLECTRIC_VERSION, ROBOLECTRIC_VERSION)],
)

load("@robolectric//bazel:robolectric.bzl", "robolectric_repositories")
Expand All @@ -135,14 +134,14 @@ robolectric_repositories()
# Load Kotlin repository
#############################

RULES_KOTLIN_TAG = "v1.8"
RULES_KOTLIN_TAG = "1.9.6"

RULES_KOTLIN_SHA = "01293740a16e474669aba5b5a1fe3d368de5832442f164e4fbfc566815a8bc3a"
RULES_KOTLIN_SHA = "3b772976fec7bdcda1d84b9d39b176589424c047eb2175bed09aac630e50af43"

http_archive(
name = "io_bazel_rules_kotlin",
sha256 = RULES_KOTLIN_SHA,
urls = ["https://github.com/bazelbuild/rules_kotlin/releases/download/%s/rules_kotlin_release.tgz" % RULES_KOTLIN_TAG],
urls = ["https://github.com/bazelbuild/rules_kotlin/releases/download/v%s/rules_kotlin-v%s.tar.gz" % (RULES_KOTLIN_TAG, RULES_KOTLIN_TAG)],
)

load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories", "kotlinc_version")
Expand All @@ -159,9 +158,7 @@ kotlin_repositories(
),
)

load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains")

kt_register_toolchains()
register_toolchains("//:kotlin_toolchain")

#############################
# Load Maven dependencies
Expand Down Expand Up @@ -301,8 +298,8 @@ maven_install(
"org.ow2.asm:asm:%s" % ASM_VERSION,
"org.ow2.asm:asm-tree:%s" % ASM_VERSION,
"org.ow2.asm:asm-commons:%s" % ASM_VERSION,
"org.robolectric:robolectric:4.4",
"org.robolectric:shadows-framework:4.4", # For ActivityController
"org.robolectric:robolectric:%s" % ROBOLECTRIC_VERSION,
"org.robolectric:shadows-framework:%s" % ROBOLECTRIC_VERSION, # For ActivityController
],
repositories = [
"https://repo1.maven.org/maven2",
Expand Down
3 changes: 2 additions & 1 deletion gwt/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
# GWT-specific files for Dagger

load("@rules_java//java:defs.bzl", "java_library")
load("//:build_defs.bzl", "POM_VERSION")
load("//:build_defs.bzl", "JAVA_RELEASE_MIN", "POM_VERSION")
load("//tools/maven:maven.bzl", "dagger_pom_file")

package(default_visibility = ["//:src"])

java_library(
name = "gwt",
javacopts = JAVA_RELEASE_MIN,
resource_strip_prefix = "gwt/",
resources = glob(["**/*.gwt.xml"]),
tags = ["maven_coordinates=com.google.dagger:dagger-gwt:" + POM_VERSION],
Expand Down
3 changes: 3 additions & 0 deletions java/dagger/android/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

load(
"//:build_defs.bzl",
"DOCLINT_HTML_AND_SYNTAX",
"JAVA_RELEASE_MIN",
"POM_VERSION",
)
load("//tools:dejetify.bzl", "dejetified_library")
Expand All @@ -43,6 +45,7 @@ filegroup(
android_library(
name = "android",
srcs = SRCS,
javacopts = JAVA_RELEASE_MIN + DOCLINT_HTML_AND_SYNTAX,
plugins = [
"//java/dagger/android/internal/proguard:plugin",
],
Expand Down
3 changes: 3 additions & 0 deletions java/dagger/android/support/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

load(
"//:build_defs.bzl",
"DOCLINT_HTML_AND_SYNTAX",
"JAVA_RELEASE_MIN",
"POM_VERSION",
)
load("//tools:dejetify.bzl", "dejetified_library")
Expand All @@ -36,6 +38,7 @@ filegroup(
android_library(
name = "support",
srcs = glob(["*.java"]),
javacopts = JAVA_RELEASE_MIN + DOCLINT_HTML_AND_SYNTAX,
tags = ["maven_coordinates=com.google.dagger:dagger-android-support:" + POM_VERSION],
deps = [
"//:dagger_with_compiler",
Expand Down
5 changes: 3 additions & 2 deletions java/dagger/grpc/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ load(
"//:build_defs.bzl",
"DOCLINT_HTML_AND_SYNTAX",
"DOCLINT_REFERENCES",
"JAVA_RELEASE_MIN",
"POM_VERSION",
)
load("//tools/javadoc:javadoc.bzl", "javadoc_library")
Expand All @@ -21,7 +22,7 @@ ANNOTATIONS_SRCS = [
java_library(
name = "annotations",
srcs = ANNOTATIONS_SRCS,
javacopts = DOCLINT_HTML_AND_SYNTAX,
javacopts = DOCLINT_HTML_AND_SYNTAX + JAVA_RELEASE_MIN,
tags = ["maven_coordinates=com.google.dagger:dagger-grpc-server-annotations:" + POM_VERSION],
deps = [
"//third_party/java/jsr330_inject",
Expand All @@ -36,7 +37,7 @@ java_library(
exclude = ANNOTATIONS_SRCS,
),
exported_plugins = ["//java/dagger/grpc/server/processor:plugin"],
javacopts = DOCLINT_HTML_AND_SYNTAX + DOCLINT_REFERENCES,
javacopts = DOCLINT_HTML_AND_SYNTAX + DOCLINT_REFERENCES + JAVA_RELEASE_MIN,
tags = ["maven_coordinates=com.google.dagger:dagger-grpc-server:" + POM_VERSION],
exports = [":annotations"],
deps = [
Expand Down
9 changes: 2 additions & 7 deletions test_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"""This file defines constants useful across the Dagger tests."""

load("@rules_java//java:defs.bzl", "java_library", "java_test")
load("//:build_defs.bzl", "JAVA_RELEASE_MIN")
load(
"@io_bazel_rules_kotlin//kotlin:kotlin.bzl",
"kt_jvm_library",
Expand Down Expand Up @@ -268,12 +267,8 @@ def _GenLibraryWithVariant(
functional,
require_jdk7_syntax):
if functional and require_jdk7_syntax:
# TODO(b/261894425): Decide if we still want to apply JAVA_RELEASE_MIN by default.
# Note: Technically, we should also apply JAVA_RELEASE_MIN to tests too, since we have
# Dagger code in there as well, but we keep it only on libraries for legacy reasons, and
# fixing tests to be jdk7 compatible would require a bit of work. We should decide on
# b/261894425 before committing to that work.
library_javacopts_kwargs = {"javacopts": javacopts + JAVA_RELEASE_MIN}
# TODO(b/261894425): consider applying this explictly at the test rule site.
library_javacopts_kwargs = {"javacopts": javacopts + ["-source 7 -target 7"]}
else:
library_javacopts_kwargs = {"javacopts": javacopts}

Expand Down
11 changes: 0 additions & 11 deletions tools/bazel.rc

This file was deleted.

8 changes: 7 additions & 1 deletion tools/jarjar/jarjar_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ fi

popd &>/dev/null

"${JARJAR}" process "${RULES_FILE}" "${TMPDIR}/combined.jar" "${OUTFILE}"
# If the RULES_FILE exists and is not empty then run jarjar.
# Otherwise, we're done so just copy the combined jar to the output file.
if [[ -f "${RULES_FILE}" && -s "${RULES_FILE}" ]]; then
"${JARJAR}" process "${RULES_FILE}" "${TMPDIR}/combined.jar" "${OUTFILE}"
else
cp $TMPDIR/combined.jar $OUTFILE
fi

rm -rf "${TMPDIR}"
17 changes: 0 additions & 17 deletions util/deploy-library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ deploy_library() {
library="${library%.*}-shaded.${library##*.}"
fi

# Validate that the classes in the library jar begin with expected prefixes.
validate_jar $(bazel_output_file $library)

# TODO(bcorso): Consider moving this into the "gen_maven_artifact" macro, this
# requires having the version checked-in for the build system.
add_tracking_version \
Expand Down Expand Up @@ -101,20 +98,6 @@ add_tracking_version() {
fi
}

validate_jar() {
local library=$1
if [[ $library == */gwt/libgwt.jar ]]; then
python $(dirname $0)/validate-jar-entry-prefixes.py \
$library "dagger/,META-INF/,javax/inject/"
elif [[ $library == */java/dagger/hilt/android/artifact.aar ]]; then
python $(dirname $0)/validate-jar-entry-prefixes.py \
$library "dagger/,META-INF/,hilt_aggregated_deps/"
else
python $(dirname $0)/validate-jar-entry-prefixes.py \
$library "dagger/,META-INF/"
fi
}

add_automatic_module_name_manifest_entry() {
local library=$1
local module_name=$2
Expand Down
Loading

0 comments on commit d83ad30

Please sign in to comment.