Skip to content

Commit 08b4718

Browse files
bcorsoDagger Team
authored and
Dagger Team
committed
Clean up Bazel workspace rules
* Migrated most WORKSPACE deps to MODULE.bazel (will be required in Bazel 9.x). * Use `.bazelversion` to declare Bazel version instead of `USE_BAZEL_VERSION` env variable (makes it easier to run locally with same bazel version). * Explicitly set `source`/`target` for `dagger.android` api, and use `.bazelrc` to set default `source`/`target` for annotation processors. * Removed unused bazel common dependencies in WORKSPACE * Removed `bazel_skylib` * Removed `google_bazel_common` * Removed `rules_python` * Removed `zlib` * Removed obsolete `tools/bazel.rc` config RELNOTES=N/A PiperOrigin-RevId: 654352167
1 parent 140e201 commit 08b4718

File tree

11 files changed

+80
-141
lines changed

11 files changed

+80
-141
lines changed

.bazelrc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,27 @@ build --host_javacopt=-g
66
# TODO(ronshapiro): explore how much work it would be to reenable this
77
build --javacopt="-Xep:BetaApi:OFF"
88
build --host_javacopt="-Xep:BetaApi:OFF"
9+
10+
# Enable Bzlmod for every Bazel command. This flag will be enabled by default in
11+
# Bazel 7.0.0, but for now we enable it manually.
12+
common --enable_bzlmod
13+
14+
# Note: This flag is required to prevent actions from clashing with each when
15+
# reading/writing tmp files. Without this flag we get errors like:
16+
#
17+
# Error: Cannot use file /tmp/hsperfdata_runner/12 because it is locked by
18+
# another process
19+
#
20+
# This flag will be enabled by default in Bazel 7.0.0, but for now we enable it
21+
# manually. For more details: https://github.com/bazelbuild/bazel/issues/3236.
22+
build --incompatible_sandbox_hermetic_tmp
23+
24+
# Sets the JDK for compiling sources and executing tests.
25+
build --java_language_version=11
26+
build --tool_java_language_version=11
27+
build --java_runtime_version=remotejdk_11
28+
build --tool_java_runtime_version=remotejdk_11
29+
30+
# Sets the default source/target for Dagger's processors. Note that Dagger's api
31+
# libraries can target JDK 8, so we set it explicitly on the Bazel target.
32+
build --javacopt="-source 8 -target 11"

.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6.4.0

.github/workflows/ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ env:
1313
USE_JAVA_VERSION: '11'
1414
# This is required by AGP 8.3+.
1515
USE_JAVA_VERSION_FOR_PLUGIN: '17'
16-
# Our Bazel builds currently rely on 6.4.0. The version is set via
17-
# baselisk by USE_BAZEL_VERSION: https://github.com/bazelbuild/bazelisk.
18-
USE_BAZEL_VERSION: '6.4.0'
1916
# The default Maven 3.9.0 has a regression so we manually install 3.8.7.
2017
# https://issues.apache.org/jira/browse/MNG-7679
2118
USE_MAVEN_VERSION: '3.8.7'

.github/workflows/release.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ env:
1212
USE_JAVA_VERSION: '11'
1313
# This is required by AGP 8.3+.
1414
USE_JAVA_VERSION_FOR_PLUGIN: '17'
15-
# Our Bazel builds currently rely on 6.4.0. The version is set via
16-
# baselisk by USE_BAZEL_VERSION: https://github.com/bazelbuild/bazelisk.
17-
USE_BAZEL_VERSION: '6.4.0'
1815
DAGGER_RELEASE_VERSION: "${{ github.event.inputs.dagger_release_version }}"
1916
# The default Maven 3.9.0 has a regression so we manually install 3.8.7.
2017
# https://issues.apache.org/jira/browse/MNG-7679

BUILD

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ package(default_visibility = ["//visibility:public"])
2121

2222
define_kt_toolchain(
2323
name = "kotlin_toolchain",
24-
api_version = "1.4",
25-
jvm_target = "1.8",
26-
language_version = "1.4",
24+
api_version = "1.8",
25+
jvm_target = "17",
26+
language_version = "1.8",
2727
)
2828

2929
package_group(

MODULE.bazel

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright (C) 2024 The Dagger Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
bazel_dep(
16+
name = "bazel_skylib",
17+
version = "1.7.1",
18+
)
19+
20+
bazel_dep(
21+
name = "rules_java",
22+
version = "7.0.6",
23+
)
24+
25+
bazel_dep(
26+
name = "rules_kotlin",
27+
version = "1.9.0",
28+
repo_name = "io_bazel_rules_kotlin",
29+
)
30+
31+
bazel_dep(
32+
name = "rules_jvm_external",
33+
version = "5.3",
34+
)
35+
36+
bazel_dep(
37+
name = "rules_robolectric",
38+
version = "4.11.1",
39+
repo_name = "robolectric",
40+
)

WORKSPACE

Lines changed: 5 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
# limitations under the License.
1414

1515

16-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
17-
1816
#############################
1917
# Load nested repository
2018
#############################
@@ -26,37 +24,6 @@ local_repository(
2624
path = "examples/bazel",
2725
)
2826

29-
#############################
30-
# Load Bazel Skylib rules
31-
#############################
32-
33-
BAZEL_SKYLIB_VERSION = "1.5.0"
34-
35-
BAZEL_SKYLIB_SHA = "cd55a062e763b9349921f0f5db8c3933288dc8ba4f76dd9416aac68acee3cb94"
36-
37-
http_archive(
38-
name = "bazel_skylib",
39-
sha256 = BAZEL_SKYLIB_SHA,
40-
urls = [
41-
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/%s/bazel-skylib-%s.tar.gz" % (BAZEL_SKYLIB_VERSION, BAZEL_SKYLIB_VERSION),
42-
"https://github.com/bazelbuild/bazel-skylib/releases/download/%s/bazel-skylib-%s.tar.gz" % (BAZEL_SKYLIB_VERSION, BAZEL_SKYLIB_VERSION),
43-
],
44-
)
45-
46-
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
47-
48-
bazel_skylib_workspace()
49-
50-
#############################
51-
# Load rules_java repository
52-
#############################
53-
54-
http_archive(
55-
name = "rules_java",
56-
sha256 = "c73336802d0b4882e40770666ad055212df4ea62cfa6edf9cb0f9d29828a0934",
57-
url = "https://github.com/bazelbuild/rules_java/releases/download/5.3.5/rules_java-5.3.5.tar.gz",
58-
)
59-
6027
#############################
6128
# Load Android Sdk
6229
#############################
@@ -67,84 +34,10 @@ android_sdk_repository(
6734
build_tools_version = "32.0.0",
6835
)
6936

70-
####################################################
71-
# Load Protobuf repository (needed by bazel-common)
72-
####################################################
73-
74-
http_archive(
75-
name = "rules_proto",
76-
# output from `sha256sum` on the downloaded tar.gz file
77-
sha256 = "66bfdf8782796239d3875d37e7de19b1d94301e8972b3cbd2446b332429b4df1",
78-
strip_prefix = "rules_proto-4.0.0",
79-
urls = [
80-
"https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/refs/tags/4.0.0.tar.gz",
81-
"https://github.com/bazelbuild/rules_proto/archive/refs/tags/4.0.0.tar.gz",
82-
],
83-
)
84-
85-
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
86-
87-
rules_proto_dependencies()
88-
89-
rules_proto_toolchains()
90-
91-
#############################
92-
# Load Protobuf dependencies
93-
#############################
94-
95-
# rules_python and zlib are required by protobuf.
96-
# TODO(ronshapiro): Figure out if zlib is in fact necessary, or if proto can depend on the
97-
# @bazel_tools library directly. See discussion in
98-
# https://github.com/protocolbuffers/protobuf/pull/5389#issuecomment-481785716
99-
# TODO(cpovirk): Should we eventually get rules_python from "Bazel Federation?"
100-
# https://github.com/bazelbuild/rules_python#getting-started
101-
102-
http_archive(
103-
name = "rules_python",
104-
sha256 = "e5470e92a18aa51830db99a4d9c492cc613761d5bdb7131c04bd92b9834380f6",
105-
strip_prefix = "rules_python-4b84ad270387a7c439ebdccfd530e2339601ef27",
106-
urls = ["https://github.com/bazelbuild/rules_python/archive/4b84ad270387a7c439ebdccfd530e2339601ef27.tar.gz"],
107-
)
108-
109-
http_archive(
110-
name = "zlib",
111-
build_file = "@com_google_protobuf//:third_party/zlib.BUILD",
112-
sha256 = "629380c90a77b964d896ed37163f5c3a34f6e6d897311f1df2a7016355c45eff",
113-
strip_prefix = "zlib-1.2.11",
114-
urls = ["https://github.com/madler/zlib/archive/v1.2.11.tar.gz"],
115-
)
116-
117-
#############################
118-
# Load Robolectric repository
119-
#############################
120-
121-
ROBOLECTRIC_VERSION = "4.4"
122-
123-
http_archive(
124-
name = "robolectric",
125-
sha256 = "d4f2eb078a51f4e534ebf5e18b6cd4646d05eae9b362ac40b93831bdf46112c7",
126-
strip_prefix = "robolectric-bazel-%s" % ROBOLECTRIC_VERSION,
127-
urls = ["https://github.com/robolectric/robolectric-bazel/archive/%s.tar.gz" % ROBOLECTRIC_VERSION],
128-
)
129-
130-
load("@robolectric//bazel:robolectric.bzl", "robolectric_repositories")
131-
132-
robolectric_repositories()
133-
13437
#############################
13538
# Load Kotlin repository
13639
#############################
13740

138-
RULES_KOTLIN_TAG = "v1.8"
139-
140-
RULES_KOTLIN_SHA = "01293740a16e474669aba5b5a1fe3d368de5832442f164e4fbfc566815a8bc3a"
141-
142-
http_archive(
143-
name = "io_bazel_rules_kotlin",
144-
sha256 = RULES_KOTLIN_SHA,
145-
urls = ["https://github.com/bazelbuild/rules_kotlin/releases/download/%s/rules_kotlin_release.tgz" % RULES_KOTLIN_TAG],
146-
)
147-
14841
load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories", "kotlinc_version")
14942

15043
KOTLIN_VERSION = "1.9.23"
@@ -167,17 +60,6 @@ kt_register_toolchains()
16760
# Load Maven dependencies
16861
#############################
16962

170-
RULES_JVM_EXTERNAL_TAG = "4.5"
171-
172-
RULES_JVM_EXTERNAL_SHA = "b17d7388feb9bfa7f2fa09031b32707df529f26c91ab9e5d909eb1676badd9a6"
173-
174-
http_archive(
175-
name = "rules_jvm_external",
176-
sha256 = RULES_JVM_EXTERNAL_SHA,
177-
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
178-
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
179-
)
180-
18163
load("@rules_jvm_external//:defs.bzl", "maven_install")
18264

18365
ANDROID_LINT_VERSION = "30.1.0"
@@ -209,6 +91,9 @@ KSP_VERSION = KOTLIN_VERSION + "-1.0.19"
20991

21092
MAVEN_VERSION = "3.3.3"
21193

94+
# NOTE: This version should match the version declared in MODULE.bazel
95+
ROBOLECTRIC_VERSION = "4.11.1"
96+
21297
maven_install(
21398
artifacts = [
21499
"androidx.annotation:annotation:1.1.0",
@@ -301,8 +186,8 @@ maven_install(
301186
"org.ow2.asm:asm:%s" % ASM_VERSION,
302187
"org.ow2.asm:asm-tree:%s" % ASM_VERSION,
303188
"org.ow2.asm:asm-commons:%s" % ASM_VERSION,
304-
"org.robolectric:robolectric:4.4",
305-
"org.robolectric:shadows-framework:4.4", # For ActivityController
189+
"org.robolectric:robolectric:%s" % ROBOLECTRIC_VERSION,
190+
"org.robolectric:shadows-framework:%s" % ROBOLECTRIC_VERSION, # For ActivityController
306191
],
307192
repositories = [
308193
"https://repo1.maven.org/maven2",

build_defs.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ DOCLINT_HTML_AND_SYNTAX = ["-Xdoclint:html,syntax"]
1919
DOCLINT_REFERENCES = ["-Xdoclint:reference"]
2020

2121
JAVA_RELEASE_MIN = [
22-
"-source 7 -target 7",
22+
"-source 8 -target 8",
2323
]
2424

2525
POM_VERSION = "${project.version}"

java/dagger/android/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
load(
1919
"//:build_defs.bzl",
20+
"DOCLINT_HTML_AND_SYNTAX",
21+
"JAVA_RELEASE_MIN",
2022
"POM_VERSION",
2123
)
2224
load("//tools:dejetify.bzl", "dejetified_library")
@@ -43,6 +45,7 @@ filegroup(
4345
android_library(
4446
name = "android",
4547
srcs = SRCS,
48+
javacopts = JAVA_RELEASE_MIN + DOCLINT_HTML_AND_SYNTAX,
4649
plugins = [
4750
"//java/dagger/android/internal/proguard:plugin",
4851
],

java/dagger/android/support/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
load(
1919
"//:build_defs.bzl",
20+
"DOCLINT_HTML_AND_SYNTAX",
21+
"JAVA_RELEASE_MIN",
2022
"POM_VERSION",
2123
)
2224
load("//tools:dejetify.bzl", "dejetified_library")
@@ -36,6 +38,7 @@ filegroup(
3638
android_library(
3739
name = "support",
3840
srcs = glob(["*.java"]),
41+
javacopts = JAVA_RELEASE_MIN + DOCLINT_HTML_AND_SYNTAX,
3942
tags = ["maven_coordinates=com.google.dagger:dagger-android-support:" + POM_VERSION],
4043
deps = [
4144
"//:dagger_with_compiler",

tools/bazel.rc

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)