Skip to content

Conversation

@lucaneg
Copy link
Contributor

@lucaneg lucaneg commented Jan 2, 2026

While trying out the plugin on a multi-module gradle project (https://github.com/lisa-analyzer/lisa), I encountered some errors that are fixed by this pr. Below is a rundown of all commits (each addressing a separate problem):

  • when running tests inside a submodule, the cwd of the test was the nvim root instead of the module root. The correct information was already computed by the plugin, but the module path was not forwarded to junit. This has also been reflected in the path for the test outputs (078f29b)
  • test selectors were being passed in within single quotes, and this caused junit to not find relevant classes and errors eg (class 'a.b.c' was searched instead of class a.b.c -- 0c25eac)
  • stdout/stderr produced by the test was not being shown during debug: bot are now posted to dap.repl (0c25eac)
  • when more than one failure was being reported (eg when executing a whole test class with multiple failing tests), only the first failure was being shown, and the stack trace was missing -- now the failure text shows all messages and stacktraces (781c62d)
  • the directory scan to search for submodules was taking a lot of time, causing nvim to hang for ~15-20 seconds -- I transformed the search to a plain non-recursive dfs and it is now almost instant (670d5e0)
  • when executing tests from the neotest summary, the classpath computation fails silently (the selected buffer is neotest summary, so the jdtls cannot get its classpath in classpath_provider.lua and returns an empty string, which causes the test to fail with a ClassNotFoundException on the desired test class) (888660c)

@lucaneg lucaneg changed the title Improvements for multi-module gradle builds fix: Improvements for multi-module gradle builds Jan 2, 2026
@lucaneg lucaneg marked this pull request as ready for review January 2, 2026 16:15
Copilot AI review requested due to automatic review settings January 2, 2026 16:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes several issues encountered when using the neotest-java plugin with multi-module Gradle projects. The changes improve test execution in submodules, enhance error reporting for multiple test failures, optimize directory scanning performance, and fix debug output handling.

Key changes:

  • Fixed current working directory (cwd) to use module base directory instead of root for multi-module projects
  • Removed single quotes from JUnit test selectors that were preventing test discovery
  • Refactored directory scanning from recursive to iterative DFS, significantly improving performance

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/unit/spec_builder_spec.lua Updated test expectations to reflect new user.dir system property, stderr capture config, unquoted selectors, and module-specific cwd paths
lua/neotest-java/util/dir_scan.lua Replaced complex recursive scanning with simple iterative DFS using a stack, eliminating performance bottleneck
lua/neotest-java/model/junit_result.lua Enhanced failure handling to support multiple failures per test with proper message and stacktrace aggregation
lua/neotest-java/core/spec_builder/init.lua Updated to use module base directory for cwd and report directory generation in multi-module projects
lua/neotest-java/core/spec_builder/compiler/classpath_provider.lua Changed from buffer URI to base directory URI for classpath resolution to fix execution from neotest summary
lua/neotest-java/command/junit_command_builder.lua Removed quotes from test selectors and added user.dir system property to ensure tests run in correct directory
lua/neotest-java/build_tool/init.lua Added debug output streaming to DAP REPL and proper cwd handling for debug test execution
Comments suppressed due to low confidence (1)

lua/neotest-java/command/junit_command_builder.lua:133

  • The JDWP agent is started with address=0.0.0.0: in -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=0.0.0.0: which exposes the Java debug port on all network interfaces without authentication. If a developer runs debug tests on an untrusted network, an attacker on the same network could attach to the JDWP port and gain arbitrary code execution in the test process. Restrict the JDWP bind address to localhost (e.g. 127.0.0.1) or make it configurable and default to a loopback-only address to avoid exposing the debug port externally.
	if port then
		table.insert(junit_command.args, 1, "-Xdebug")
		table.insert(
			junit_command.args,
			1,
			"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=0.0.0.0:" .. port
		)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rcasia
Copy link
Owner

rcasia commented Jan 2, 2026

Hi @lucaneg, thanks for the good work!

test selectors were being passed in within single quotes, and this caused junit to not find relevant classes and errors eg (class 'a.b.c' was searched instead of class a.b.c -- 0c25eac)

The reason to single quote the selector values was #216. Do you have a concrete example value that does not work for the single quotes? We might have to find a third solution

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this changes, should add a test in result_builder_spec.lua with an xml report example.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great refactor here!

@rcasia
Copy link
Owner

rcasia commented Jan 2, 2026

There are many different set of changes on this PR. As a recommendation for the next time, try to open multiple PRs better and some stuff would be merged almost immediately.

Nice work!

rcasia referenced this pull request Jan 2, 2026
Co-authored-by: Luca Negrini <luca.negrinii@gmail.com>
rcasia referenced this pull request Jan 2, 2026
Co-authored-by: Luca Negrini <luca.negrinii@gmail.com>
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