Skip to content

fix: Test Explorer discovery and debug classpath resolution for Bazel Java targets#27

Merged
monkey666-cr merged 4 commits into
monkey666-cr:mainfrom
runchen0919:feature/test-explorer-debug
May 26, 2026
Merged

fix: Test Explorer discovery and debug classpath resolution for Bazel Java targets#27
monkey666-cr merged 4 commits into
monkey666-cr:mainfrom
runchen0919:feature/test-explorer-debug

Conversation

@runchen0919

@runchen0919 runchen0919 commented May 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Enable Test Explorer discovery for Bazel Java test targets: Propagate isTest flag from Rust through JNI, resolve fallback JARs from Bazel external cache, and add BazelExternalRepoResolver for classic/bzlmod layouts.
  • Re-resolve classpath after pre-debug build: After buildTarget completes, re-resolve classpath via vscode.java.resolveClasspath and merge new entries to fix ClassNotFoundException on first Run/Debug.

Test plan

  • Verify Test Explorer discovers @Test annotated tests in Bazel Java projects
  • Verify first-time Run/Debug does not throw ClassNotFoundException
  • Confirm classpath entries include test attribute (isTest=true) for test sources
  • Validate fallback JAR resolution from <output_base>/external/ before first build
  • Run cargo test --workspace — all Rust tests pass
  • Run mvn test — all Java tests pass (including new tests for BazelExternalRepoResolver, BazelClasspathContainer, BazelProjectCreator)

🤖 Generated with Claude Code

runchen0919 and others added 4 commits May 25, 2026 11:38
Fix VS Code Test Explorer not discovering @Test-annotated tests by:

1. Propagate isTest flag from Rust TargetKind::JavaTest through JNI to
   source entries, marking test folders with IClasspathAttribute.TEST.
   This unblocks vscode-java-test's isTestFile check.

2. Resolve fallback JARs from Bazel's external cache when build artifacts
   don't exist. JUnit and other test JARs cached at <output_base>/external/
   are now found even before first build, enabling JDT SearchEngine to
   resolve @test annotation class.

3. Add BazelExternalRepoResolver utility for output_base discovery and
   external repo JAR lookup, with fallback to both classic and bzlmod
   repository layouts.

All classpath entries now correctly decorated with test=true attribute,
test sources are marked at project level, and missing JARs gracefully
resolve from cache or skip with warnings.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…t JARs

The Java Test Runner pre-resolves classPaths before our debug config
provider runs. When a Bazel target hasn't been built yet, output JARs
don't exist on disk and are skipped by fileExists() during resolution.
Our buildTarget creates those JARs, but config.classPaths is already
frozen — causing ClassNotFoundException on first Run/Debug.

After buildTarget, re-resolve the classpath via vscode.java.resolveClasspath
and merge any new entries into the existing classPaths. We merge rather
than replace to preserve test-runner infrastructure JARs (RemoteTestRunner).

Also reorders handleBuildTarget post-build steps: resetWarnings →
setMergedClasspathContainer(force=true) → clearCacheForProject.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
BazelProjectCreator uses Platform.getLog() which requires OSGi runtime,
causing ExceptionInInitializerError in CI where no OSGi container runs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@monkey666-cr monkey666-cr merged commit 857b2a2 into monkey666-cr:main May 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants