Skip to content

Commit 27baf41

Browse files
Add Java bzlmod tests to CI
1 parent 2a6f8b3 commit 27baf41

File tree

24 files changed

+749
-6
lines changed

24 files changed

+749
-6
lines changed

.github/workflows/ci.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- uses: actions/checkout@v5
2020
- uses: bazel-contrib/setup-bazel@0.15.0
2121

22-
- name: bazel build
22+
- name: sonar canner build
2323
run: |
2424
bazel build //:sonar_scanner
2525
bazel build //:sonarqube_coverage_generator
@@ -30,24 +30,24 @@ jobs:
3030
# run: |
3131
# bazel aquery ...
3232

33-
test-workspace:
33+
test:
3434
runs-on: ubuntu-latest
3535
strategy:
3636
matrix:
3737
folder:
3838
- examples/java-workspace
39-
# - examples/java-bzlmod
39+
- examples/java-bzlmod
4040
steps:
4141
- uses: actions/checkout@v5
4242
- uses: bazel-contrib/setup-bazel@0.15.0
4343

44-
- name: bazel test coverage
44+
- name: test coverage
4545
working-directory: ${{ matrix.folder }}
4646
run: |
4747
bazel coverage //...
4848
bazel build //:sonarqube
4949
50-
- name: bazel sonarqube report
50+
- name: sonarqube report
5151
working-directory: ${{ matrix.folder }}
5252
# TODO We don't have sonar server to send scan results
5353
continue-on-error: True

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module(
22
name = "bazel_sonarqube",
3-
version = "1.0.3",
3+
version = "1.0.5",
44
compatibility_level = 1,
55
repo_name = "bazel_sonarqube",
66
)

examples/java-bzlmod/.bazelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage --collect_code_coverage
2+
coverage --combined_report=lcov
3+
coverage --coverage_report_generator=@bazel_sonarqube//:sonarqube_coverage_generator

examples/java-bzlmod/.bazelversion

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

examples/java-bzlmod/BUILD

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
filegroup(
2+
name = "git",
3+
srcs = glob(
4+
[".git/**"],
5+
exclude = [".git/**/*[*"], # gitk creates temp files with []
6+
),
7+
tags = ["manual"],
8+
)
9+
10+
filegroup(
11+
name = "coverage_report",
12+
srcs = ["bazel-out/_coverage/_coverage_report.dat"], # Created manually
13+
tags = ["manual"],
14+
)
15+
16+
filegroup(
17+
name = "test_reports",
18+
srcs = glob(["bazel-testlogs/**/test.xml"]), # Created manually
19+
tags = ["manual"],
20+
visibility = ["//visibility:public"],
21+
)
22+
23+
load("@bazel_sonarqube//:defs.bzl", "sonarqube")
24+
25+
sonarqube(
26+
name = "sonarqube",
27+
srcs = [],
28+
coverage_report = ":coverage_report",
29+
modules = {
30+
"//subproject:sq_subproject": "subproject",
31+
},
32+
project_key = "com.example.project:project",
33+
project_name = "My Project",
34+
scm_info = [":git"],
35+
tags = ["manual"],
36+
targets = [],
37+
testonly = True,
38+
)

examples/java-bzlmod/MODULE.bazel

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
###############################################################################
2+
# Bazel now uses Bzlmod by default to manage external dependencies.
3+
# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel.
4+
#
5+
# For more details, please check https://github.com/bazelbuild/bazel/issues/18958
6+
###############################################################################
7+
8+
bazel_dep(name = "bazel_sonarqube", version = "1.0.3", dev_dependency = True)
9+
non_module_dependencies = use_extension("@bazel_sonarqube//:extensions.bzl", "non_module_dependencies")
10+
# TODO This needs to be uncommented after 1.0.5 release
11+
# non_module_dependencies.settings(
12+
# sonar_scanner_cli_version = "7.2.0.5079",
13+
# sonar_scanner_cli_sha256 = "30d80b37c8f4be1254b6c43ec8c64291798d97a710c28475958b5e2f10809fe1",
14+
# )
15+
use_repo(non_module_dependencies, "org_sonarsource_scanner_cli_sonar_scanner_cli")
16+
17+
bazel_dep(name = "rules_jvm_external", version = "6.8")
18+
19+
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
20+
21+
use_repo(maven, "maven")

examples/java-bzlmod/MODULE.bazel.lock

Lines changed: 395 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
load("@bazel_sonarqube//:defs.bzl", "sonarqube")
2+
3+
sonarqube(
4+
name = "sonarqube",
5+
srcs = [
6+
"//subproject-with-separate-sonarqube/src/main/java/com/separate:srcs",
7+
],
8+
targets = [
9+
"//subproject-with-separate-sonarqube/src/main/java/com/separate",
10+
],
11+
test_reports = [ "//:test_reports" ],
12+
test_srcs = [
13+
"//subproject-with-separate-sonarqube/src/test/java/com/separate:srcs",
14+
],
15+
test_targets = [
16+
"//subproject-with-separate-sonarqube/src/test/java/com/separate:SeparateAppTest",
17+
],
18+
modules = {
19+
"//subproject-with-separate-sonarqube/subsubproject:sq_project": "subproject-with-separate-sonarqube/subsubproject",
20+
},
21+
coverage_report = "//:coverage_report",
22+
project_key = "com.example.separate:separate",
23+
project_name = "My Project with Separate sonarqube rule",
24+
scm_info = ["//:git"],
25+
tags = ["manual"],
26+
testonly = True,
27+
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
filegroup(
2+
name = "srcs",
3+
srcs = glob(["*.java"]),
4+
visibility = [ "//visibility:public" ],
5+
)
6+
7+
java_library(
8+
name = "separate",
9+
srcs = [":srcs"],
10+
visibility = [ "//visibility:public" ],
11+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.separate;
2+
3+
public class SeparateApp {
4+
private final String message;
5+
6+
public SeparateApp() {
7+
this.message = "Hello from another (separate) world.";
8+
}
9+
10+
public String getMessage() {
11+
return this.message;
12+
}
13+
}

0 commit comments

Comments
 (0)