Fix: Add test-classes folder to classpath for test-jar workspace dependencies - #2175
Open
mnpoonia wants to merge 4 commits into
Open
Fix: Add test-classes folder to classpath for test-jar workspace dependencies#2175mnpoonia wants to merge 4 commits into
mnpoonia wants to merge 4 commits into
Conversation
Author
|
@laeubi Please guide me here. I am trying to contribute for the first time. |
mnpoonia
force-pushed
the
fix/test-jar-workspace-resolution
branch
from
May 20, 2026 06:56
31cb849 to
81d24a7
Compare
When a project depends on another workspace project via type=test-jar or classifier=tests, the dependency should resolve to a CPE_PROJECT entry with WITHOUT_TEST_CODE=null so the consumer sees the producer's test sources. The previous approach incorrectly added a CPE_LIBRARY entry pointing to target/test-classes, which broke existing count-based assertions in BuildPathManagerTest and JavaClasspathTest. The correct mechanism already exists: excludeTestSources &= !isTestArtifact in DefaultClasspathManagerDelegate sets WITHOUT_TEST_CODE=null for test-jar project references. The producer also needs m2e.disableTestClasspathFlag=true so its src/test/java folder is not marked test=true, making test classes visible to consumers. Adds TestJarWorkspaceResolutionTest covering: - type=test-jar in compile scope (WITHOUT_TEST_CODE absent) - classifier=tests (project entry present, WITHOUT_TEST_CODE absent) - regular dependency (WITHOUT_TEST_CODE=true, no test-classes library) - type=test-jar in test scope (test=true attribute set)
…DependencyCollector
- Fix operator precedence bug in isVersionRanged(): the expression
version != null && version.startsWith("(") || version.startsWith("[")
was parsed as (version != null && ...) || version.startsWith("["),
causing NPE when version is null
- Add import scope BOM expansion: when dependencyScopes contains "import"
and the current node is a POM artifact, also enqueue its managed
dependencies (both in DIRECT and BFS depth paths)
- Deduplicate artifacts in the DIRECT depth path using a seen Set,
matching the dedup logic already present in the BFS path
- Extract enqueueDependencies() helper (DRY)
- Bump org.eclipse.m2e.pde.target to 2.1.400 and
org.eclipse.m2e.pde.feature to 2.3.800 (binary change)
mnpoonia
force-pushed
the
fix/test-jar-workspace-resolution
branch
from
June 9, 2026 16:37
60d32a1 to
27f2721
Compare
…operty Previously, a project that produced a test-jar via maven-jar-plugin had to explicitly set m2e.disableTestClasspathFlag=true in its pom.xml properties for consumers to see its test classes via workspace project reference. This required producer opt-in, which meant third-party projects (e.g. Apache HBase with 191 test-jar dependencies) could not benefit without pom.xml changes. Fix: MavenClasspathHelpers.hasTestFlagDisabled() now also returns true when maven-jar-plugin has a test-jar execution, regardless of whether the pom property is set. The explicit property still works as before. Remove m2e.disableTestClasspathFlag from the module-a test fixture since it is no longer needed — auto-detection now covers the common case.
…10.300 MavenClasspathHelpers.hasTestFlagDisabled() is a behavioral change (auto-detection of maven-jar-plugin:test-jar), requiring a minor version bump per Tycho baseline rules. The containing feature must also be bumped when its bundle versions change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2174
Summary
Adds
target/test-classesfolder to classpath for workspacetest-jardependencies, fixing compilation errors like "TestUtil cannot be resolved".Problem
When a Maven dependency has
<type>test-jar</type>and the dependency project is in the workspace, M2E only added a project reference withWITHOUT_TEST_CODEattribute. Eclipse JDT doesn't automatically include thetarget/test-classesfolder based on this attribute, causing compilation failures.Solution
After detecting a test-jar workspace dependency, explicitly add the dependency's test-classes output folder as a library entry with source attachment.
Changed file:
org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/DefaultClasspathManagerDelegate.javaImplementation Details
isTestArtifact()check (already detects"test-jar".equals(type))mavenProject.getBuild().getTestOutputDirectory()target/test-classesfoldersrc/test/javafor F3 (go to definition) supportTEST_ATTRIBUTEfor proper visibility controlTesting
Manual Testing
Minimal reproduction (2 modules):
Apache HBase (50+ modules, 191 test-jar dependencies):
Maven CLI Compatibility
✅ Matches Maven CLI behavior (uses test-jar from workspace)
Benefits
Reproduction Project
Created minimal 2-module test case demonstrating the issue and fix:
Available at:
/Users/apoonia/Code/github/m2e-testjar-repro