Skip to content

Commit

Permalink
Update Bazel to use JDK 18.
Browse files Browse the repository at this point in the history
This is required before updating to the latest XProcessing jars (which require JDK 17+). Note that we're not using JDK 17 because there's a bug that affects Dagger (https://bugs.openjdk.org/browse/JDK-8268575).

This CL sets the default target level to 8, which is used by all of the processors, but some of the Dagger (non-processor) artifacts are set explicitly to target 7. Note that we're keeping the target low to avoid forcing downstream users to have to use a higher JDK.

I've also added a validation step to our GitHub Actions to add some level of guarantee that the classes in the artifact jars all have the expected language level.

RELNOTES=N/A
PiperOrigin-RevId: 658131076
  • Loading branch information
bcorso authored and Dagger Team committed Jul 31, 2024
1 parent 5293ff5 commit 31eec2a
Show file tree
Hide file tree
Showing 16 changed files with 285 additions and 59 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 other
# 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
26 changes: 21 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,13 @@ 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 +187,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.6",
jvm_target = "1.8",
language_version = "1.6",
)

java_library(
name = "dagger_with_compiler",
exported_plugins = ["//java/dagger/internal/codegen:component-codegen"],
Expand Down
20 changes: 9 additions & 11 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,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 +135,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 +159,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 +299,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
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 31eec2a

Please sign in to comment.