Skip to content

bazel coverage //... for Java on Windows fails #18839

@Sakrafux

Description

@Sakrafux

Description of the bug:

When running bazel coverage //... for Java on Windows, it fails inexplicably.

BUILD:

load("@rules_jvm_external//:defs.bzl", "artifact")
load("@contrib_rules_jvm//java:defs.bzl", "JUNIT5_DEPS", "java_junit5_test", "java_test_suite")

java_library(
    name = "app-test-jar",
    srcs = glob(["src/main/java/**/*.java"]),
    resources = glob([
        "src/main/resources/**/*",
        "src/test/resources/**/*",
    ]),
    deps = [
        artifact("org.projectlombok:lombok"),
        artifact("org.springframework.boot:spring-boot"),
        artifact("org.springframework.boot:spring-boot-autoconfigure"),
        artifact("org.springframework.boot:spring-boot-starter-data-jpa"),
        artifact("org.springframework.boot:spring-boot-starter-security"),
        artifact("org.springframework.boot:spring-boot-starter-web"),
    ],
)

java_junit5_test(
    name = "test",
    size = "small",
    srcs = glob(["src/test/java/**/*.java"]),
    test_class = "com.example.demo.AdditionalTest",
    runtime_deps = JUNIT5_DEPS,
    deps = [
        ":app-test-jar",
        artifact("org.junit.jupiter:junit-jupiter-api"),
        artifact("org.junit.jupiter:junit-jupiter-params"),
        artifact("org.springframework.boot:spring-boot-starter-test"),
        artifact("org.springframework.boot:spring-boot-test"),
    ],
)

Running bazel coverage test fails with the following error:

==================== Test output for //backend:test:
ERROR(tools/test/windows/tw.cc:1294) ERROR: src/main/native/windows/process.cc(202): CreateProcessW("C:\users\...\bazel-out\x64_windows-fastbuild\bin\backend\test.exe.runfiles\__main__\external\bazel_tools\tools\test\collect_coverage.sh"  backend/test.exe): The system cannot find the file specified.
 (error: 2)
ERROR(tools/test/windows/tw.cc:1453) Failed to start test process (arg: C:\users\...\bazel-out\x64_windows-fastbuild\bin\backend\test.exe.runfiles\__main__\external\bazel_tools\tools\test\collect_coverage.sh)
================================================================================
ERROR: E:/.../BUILD:21:17: output 'backend/test/coverage.dat' was not created
ERROR: E:/.../BUILD:21:17: Testing //backend:test failed: not all outputs were created or valid

When I force the missing script into the runfiles via data = ["@bazel_tools//tools/test:collect_coverage"] I instead get %1 is not a valid Win32 application. rather than The system cannot find the file specified.

To further clarify, bazel test test works fine and running everything with WSL successfully runs the coverage.

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

On a Windows machine, clone the given Java example https://github.com/bazelbuild/examples/tree/main/java-maven and run bazel coverage :tests.

Which operating system are you running Bazel on?

Windows 10

What is the output of bazel info release?

release 6.2.1

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions