bazelbuild / bazelbuild/bazel

`bazel coverage //...` for Java on Windows fails

Open
#18,839 4 comments 1 reaction 0 assignees View on GitHub
coverage type: feature request untriaged
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### 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_

Contributor guide

Open the contributing guide

Research direction

Start by reproducing `bazel coverage :tests` from the `java-maven` example on Windows 10. Read `tools/test/windows/tw.cc`, `src/main/native/windows/process.cc`, and the referenced `collect_coverage.sh` path to trace why the coverage test process cannot start. Done means Java coverage runs successfully on Windows without manually adding the script to runfiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, operating-systems, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.