Skip to content

Commit c09dad1

Browse files
authored
Merge pull request #4726 from kubernetes-client/copilot/add-bazel-support
Add Bazel build support with incremental artifact caching
2 parents 0e4d7f5 + 77ac9fa commit c09dad1

38 files changed

Lines changed: 5555 additions & 277 deletions

File tree

‎.bazelrc‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# ============================================================
2+
# Default build flags for kubernetes-client/java
3+
# ============================================================
4+
5+
# ---------------------------------------------------------------------------
6+
# Java toolchain configuration
7+
# ---------------------------------------------------------------------------
8+
# Build all Java targets at language level 11 by default.
9+
# Modules that require Java 17+ (spring, spring-aot) set javacopts per-target.
10+
build --java_language_version=11
11+
build --java_runtime_version=remotejdk_17
12+
build --tool_java_language_version=11
13+
build --tool_java_runtime_version=remotejdk_11
14+
15+
# ---------------------------------------------------------------------------
16+
# Error Prone configuration
17+
# ---------------------------------------------------------------------------
18+
# Bazel's Java rules enable Error Prone by default. The checks fire on
19+
# pre-existing patterns in this codebase (e.g. DoubleBraceInitialization,
20+
# EqualsHashCode) that are not caught by the Maven build. Disable all
21+
# Error Prone checks so that the Bazel build stays consistent with Maven.
22+
build --javacopt=-XepDisableAllChecks
23+
24+
# ---------------------------------------------------------------------------
25+
# Build settings
26+
# ---------------------------------------------------------------------------
27+
build --enable_platform_specific_config
28+
build --incompatible_strict_action_env=true
29+
30+
# ---------------------------------------------------------------------------
31+
# Local disk cache
32+
# Speeds up repeated local builds by caching action outputs on disk.
33+
# Override the path by putting `build --disk_cache=<path>` in .bazelrc.user.
34+
# ---------------------------------------------------------------------------
35+
build --disk_cache=~/.cache/bazel-disk-cache
36+
37+
# ---------------------------------------------------------------------------
38+
# CI configuration
39+
# Enable when running under GitHub Actions:
40+
# bazel build --config=ci ...
41+
# ---------------------------------------------------------------------------
42+
# The disk cache is intentionally left at its default path
43+
# (~/.cache/bazel-disk-cache) so the GitHub Actions cache step (configured in
44+
# .github/workflows/bazel.yml) can save and restore compiled action outputs
45+
# between runs for faster incremental builds.
46+
# Show full test output on failure.
47+
build:ci --test_output=errors
48+
# Avoid interactive prompts.
49+
build:ci --noshow_progress
50+
build:ci --show_result=0
51+
52+
# ---------------------------------------------------------------------------
53+
# Remote cache configuration (opt-in)
54+
# To use a Bazel remote cache, create a .bazelrc.user file with:
55+
# build --config=remote-cache
56+
# build:remote-cache --remote_cache=grpcs://<your-cache-endpoint>
57+
# build:remote-cache --remote_header=x-auth-token=<token>
58+
# ---------------------------------------------------------------------------
59+
# (remote-cache config is user-supplied)
60+
61+
# ---------------------------------------------------------------------------
62+
# User-local overrides (not committed)
63+
# ---------------------------------------------------------------------------
64+
try-import %workspace%/.bazelrc.user

‎.bazelversion‎

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

‎.github/workflows/bazel.yml‎

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Build and test the library with Bazel.
2+
#
3+
# Bazel's built-in action caching combined with GitHub Actions cache gives
4+
# incremental builds: only changed targets and their dependents are rebuilt.
5+
#
6+
# Cache layers used:
7+
# 1. Repository cache – downloaded JARs / external repositories
8+
# 2. Disk cache – action output cache (build artifacts)
9+
# Both are saved to GitHub Actions cache keyed on the OS, Bazel module lock,
10+
# and Maven artifact list so cache hits are maximized across identical runs.
11+
12+
name: bazel
13+
14+
on:
15+
push:
16+
branches: ["master", "release-**"]
17+
paths:
18+
- "**/*.java"
19+
- "**/BUILD.bazel"
20+
- "MODULE.bazel"
21+
- ".bazelversion"
22+
- ".bazelrc"
23+
- ".github/workflows/bazel.yml"
24+
pull_request:
25+
branches: ["master", "release-**"]
26+
paths:
27+
- "**/*.java"
28+
- "**/BUILD.bazel"
29+
- "MODULE.bazel"
30+
- ".bazelversion"
31+
- ".bazelrc"
32+
- ".github/workflows/bazel.yml"
33+
34+
jobs:
35+
bazel-build-test:
36+
name: Bazel build & test (Java ${{ matrix.java }})
37+
runs-on: ubuntu-latest
38+
strategy:
39+
fail-fast: false
40+
matrix:
41+
java: ["11", "17", "21"]
42+
env:
43+
BAZELISK_SKIP_VERSION_CHECK: "1"
44+
45+
steps:
46+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
47+
48+
- name: Set up Java ${{ matrix.java }}
49+
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
50+
with:
51+
distribution: temurin
52+
java-version: ${{ matrix.java }}
53+
54+
# Install Bazelisk which reads the pinned version from .bazelversion.
55+
# Install into $HOME/.local/bin (no root required) and add it to PATH.
56+
- name: Install Bazelisk
57+
run: |
58+
mkdir -p "$HOME/.local/bin"
59+
curl -fsSL \
60+
https://github.com/bazelbuild/bazelisk/releases/download/v1.24.1/bazelisk-linux-amd64 \
61+
-o "$HOME/.local/bin/bazel"
62+
chmod +x "$HOME/.local/bin/bazel"
63+
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
64+
65+
# ----------------------------------------------------------------
66+
# Cache layers
67+
# The disk cache stores compiled action outputs; the repository cache
68+
# stores downloaded external files (JARs, etc.).
69+
# ----------------------------------------------------------------
70+
- name: Restore Bazel caches
71+
id: bazel-cache
72+
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
73+
with:
74+
path: |
75+
~/.cache/bazel-disk-cache
76+
~/.cache/bazel/cache/repos/v1
77+
key: bazel-${{ runner.os }}-java${{ matrix.java }}-${{ hashFiles('MODULE.bazel', '.bazelversion', 'maven_install.json') }}
78+
restore-keys: |
79+
bazel-${{ runner.os }}-java${{ matrix.java }}-
80+
bazel-${{ runner.os }}-
81+
82+
# Re-generate the Maven lock file so it is always consistent with
83+
# MODULE.bazel. The __INPUT_ARTIFACTS_HASH in the committed file is
84+
# intentionally set to -1 to signal that the file needs to be regenerated;
85+
# REPIN=1 overwrites it with the correct value. Once the artifact list
86+
# stabilises, subsequent runs where MODULE.bazel has not changed are fast
87+
# because rules_jvm_external short-circuits on an identical artifact list.
88+
- name: Pin Maven dependencies
89+
run: REPIN=1 bazel run @maven//:pin
90+
91+
# ----------------------------------------------------------------
92+
# Build all core modules
93+
# ----------------------------------------------------------------
94+
- name: Build
95+
run: |
96+
bazel build --config=ci \
97+
//kubernetes:client-java-api \
98+
//proto:client-java-proto \
99+
//util:client-java \
100+
//fluent:client-java-api-fluent \
101+
//extended:client-java-extended
102+
103+
# Spring modules require Java 17+; skip them on the Java 11 matrix leg.
104+
- name: Build Spring modules (Java 17+)
105+
if: matrix.java != '11'
106+
run: |
107+
bazel build --config=ci \
108+
//spring:client-java-spring-integration \
109+
//spring-aot:client-java-spring-aot-integration
110+
111+
# ----------------------------------------------------------------
112+
# Test — run per-module test suites
113+
# ----------------------------------------------------------------
114+
- name: Test core modules
115+
run: |
116+
bazel test --config=ci \
117+
//kubernetes:tests \
118+
//util:tests \
119+
//extended:tests
120+
121+
- name: Test Spring modules (Java 17+)
122+
if: matrix.java != '11'
123+
run: |
124+
bazel test --config=ci \
125+
//spring:tests

‎.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ hs_err_pid*
3434
kubernetes/bin
3535
kubernetes/swagger.json.unprocessed
3636
**/*.orig
37+
38+
# Bazel build artifacts and symlinks
39+
bazel-*
40+
MODULE.bazel.lock

‎BUILD.bazel‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Root BUILD file for kubernetes-client/java.
2+
# Individual library targets are defined in sub-packages.

‎MODULE.bazel‎

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
"""
2+
Bazel MODULE for kubernetes-client/java.
3+
4+
This enables building the library with Bazel in addition to Maven.
5+
Key features:
6+
- rules_jvm_external manages all Maven dependencies.
7+
- contrib_rules_jvm provides java_test_suite for JUnit 5 test discovery.
8+
- Remote-cache and disk-cache settings live in .bazelrc / .bazelrc.user.
9+
"""
10+
11+
module(
12+
name = "kubernetes_client_java",
13+
version = "27.0.0-SNAPSHOT",
14+
compatibility_level = 1,
15+
)
16+
17+
bazel_dep(name = "bazel_skylib", version = "1.7.1")
18+
bazel_dep(name = "rules_java", version = "7.12.2")
19+
bazel_dep(name = "rules_jvm_external", version = "6.7")
20+
bazel_dep(name = "contrib_rules_jvm", version = "0.27.0")
21+
22+
# ---------------------------------------------------------------------------
23+
# Maven dependency management
24+
# ---------------------------------------------------------------------------
25+
26+
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
27+
28+
maven.install(
29+
artifacts = [
30+
# ---- core ----
31+
# Versions kept in sync with the property values in the root pom.xml.
32+
"jakarta.annotation:jakarta.annotation-api:3.0.0",
33+
"io.swagger:swagger-annotations:1.6.16",
34+
"com.squareup.okhttp3:okhttp:5.3.2",
35+
"com.squareup.okhttp3:okhttp-jvm:5.3.2",
36+
"com.squareup.okhttp3:logging-interceptor:5.3.2",
37+
"com.squareup.okio:okio:3.16.4",
38+
"com.squareup.okio:okio-jvm:3.16.4",
39+
"com.google.code.gson:gson:2.14.0",
40+
"com.fasterxml.jackson.core:jackson-databind:2.21.2",
41+
"com.fasterxml.jackson.core:jackson-core:2.21.2",
42+
"com.fasterxml.jackson.core:jackson-annotations:2.21",
43+
"io.gsonfire:gson-fire:1.9.0",
44+
"org.apache.commons:commons-lang3:3.20.0",
45+
"org.apache.commons:commons-collections4:4.5.0",
46+
"org.apache.commons:commons-compress:1.28.0",
47+
"commons-io:commons-io:2.22.0",
48+
"commons-codec:commons-codec:1.22.0",
49+
"org.yaml:snakeyaml:2.6",
50+
"org.slf4j:slf4j-api:2.0.17",
51+
"org.bouncycastle:bcpkix-jdk18on:1.84",
52+
"org.bouncycastle:bcprov-jdk18on:1.84",
53+
"com.google.protobuf:protobuf-java:4.34.1",
54+
"org.bitbucket.b_c:jose4j:0.9.6",
55+
"com.google.auth:google-auth-library-oauth2-http:1.46.0",
56+
"software.amazon.awssdk:auth:2.43.0",
57+
"software.amazon.awssdk:http-auth-aws:2.43.0",
58+
"software.amazon.awssdk:http-auth-spi:2.43.0",
59+
"software.amazon.awssdk:http-client-spi:2.43.0",
60+
"software.amazon.awssdk:sts:2.43.0",
61+
"software.amazon.awssdk:utils:2.43.0",
62+
"io.prometheus:simpleclient:0.16.0",
63+
"io.prometheus:simpleclient_httpserver:0.16.0",
64+
"com.bucket4j:bucket4j-core:8.10.1",
65+
"com.github.ben-manes.caffeine:caffeine:3.0.0",
66+
"com.flipkart.zjsonpatch:zjsonpatch:0.4.16",
67+
"org.jetbrains:annotations:26.1.0",
68+
"org.reflections:reflections:0.10.2",
69+
# ---- spring (Java 17+ modules) ----
70+
# spring-boot 4.0.6 transitively brings in spring-framework 7.0.x, but the
71+
# root pom.xml pins spring.version=6.2.12. Explicitly declare all
72+
# spring-framework modules at 6.2.12 and use maven.artifact() with
73+
# exclusions on the spring-boot artifacts so Coursier does not upgrade them.
74+
"org.springframework:spring-aop:6.2.12",
75+
"org.springframework:spring-beans:6.2.12",
76+
"org.springframework:spring-context:6.2.12",
77+
"org.springframework:spring-core:6.2.12",
78+
"org.springframework:spring-expression:6.2.12",
79+
"org.springframework:spring-test:6.2.12",
80+
# ---- test ----
81+
"org.junit.jupiter:junit-jupiter-api:5.13.4",
82+
"org.junit.jupiter:junit-jupiter-engine:5.13.4",
83+
"org.junit.jupiter:junit-jupiter-params:5.13.4",
84+
"org.junit.platform:junit-platform-launcher:1.13.4",
85+
"org.junit.platform:junit-platform-commons:1.13.4",
86+
"org.junit.platform:junit-platform-engine:1.13.4",
87+
"org.junit.platform:junit-platform-reporting:1.13.4",
88+
"org.mockito:mockito-core:5.23.0",
89+
"org.mockito:mockito-junit-jupiter:5.23.0",
90+
"uk.org.webcompere:system-stubs-jupiter:2.1.8",
91+
"uk.org.webcompere:system-stubs-core:2.1.8",
92+
"org.wiremock:wiremock:3.13.2",
93+
"org.awaitility:awaitility:4.3.0",
94+
"org.assertj:assertj-core:3.27.7",
95+
"ch.qos.logback:logback-classic:1.5.32",
96+
"ch.qos.logback:logback-core:1.5.32",
97+
],
98+
repositories = [
99+
"https://repo1.maven.org/maven2",
100+
"https://repo.spring.io/milestone",
101+
],
102+
fetch_sources = False,
103+
lock_file = "//:maven_install.json",
104+
)
105+
106+
# Spring Boot 4.0.6 artifacts declared with exclusions to pin spring-framework at
107+
# 6.2.12 (matching pom.xml spring.version) instead of the 7.0.x that spring-boot
108+
# 4.0.x normally pulls in.
109+
_SPRING_FRAMEWORK_EXCLUSIONS = [
110+
"org.springframework:spring-aop",
111+
"org.springframework:spring-beans",
112+
"org.springframework:spring-context",
113+
"org.springframework:spring-core",
114+
"org.springframework:spring-expression",
115+
"org.springframework:spring-test",
116+
]
117+
118+
maven.artifact(
119+
artifact = "spring-boot",
120+
group = "org.springframework.boot",
121+
version = "4.0.6",
122+
exclusions = _SPRING_FRAMEWORK_EXCLUSIONS,
123+
)
124+
125+
maven.artifact(
126+
artifact = "spring-boot-autoconfigure",
127+
group = "org.springframework.boot",
128+
version = "4.0.6",
129+
exclusions = _SPRING_FRAMEWORK_EXCLUSIONS,
130+
)
131+
132+
maven.artifact(
133+
artifact = "spring-boot-actuator",
134+
group = "org.springframework.boot",
135+
version = "4.0.6",
136+
exclusions = _SPRING_FRAMEWORK_EXCLUSIONS,
137+
)
138+
139+
maven.artifact(
140+
artifact = "spring-boot-test",
141+
group = "org.springframework.boot",
142+
version = "4.0.6",
143+
exclusions = _SPRING_FRAMEWORK_EXCLUSIONS,
144+
)
145+
146+
use_repo(maven, "maven")

0 commit comments

Comments
 (0)