Fix: Add test-classes folder to classpath for test-jar workspace dependencies#2175
Open
mnpoonia wants to merge 2 commits into
Open
Fix: Add test-classes folder to classpath for test-jar workspace dependencies#2175mnpoonia wants to merge 2 commits into
mnpoonia wants to merge 2 commits into
Conversation
…ndencies When a Maven dependency has type="test-jar" and the dependency project is in the workspace, M2E now correctly adds the dependency's target/test-classes folder to the classpath as a library entry. Previously, M2E only added a project reference with WITHOUT_TEST_CODE attribute, but Eclipse JDT doesn't automatically include the test-classes output folder based on this attribute alone, causing compilation errors like "TestUtil cannot be resolved". This fix: - Detects test-jar dependencies using existing isTestArtifact() check - Retrieves test output directory from Maven project model - Adds test-classes folder as a library entry with source attachment - Gracefully falls back to existing behavior if test output unavailable Fixes workspace resolution for Maven test-jar artifacts.
Author
|
@laeubi Please guide me here. I am trying to contribute for the first time. |
…ndencies Adds workspace resolution support for Maven test-jar dependencies, allowing projects that depend on <type>test-jar</type> artifacts to reference the workspace project's target/test-classes folder directly. Changes: - DefaultClasspathManagerDelegate: Add test-classes library entry for test-jar deps - TestJarWorkspaceResolutionTest: Comprehensive test coverage (4 test methods) - Test type=test-jar in compile scope - Test classifier=tests variant - Test regular deps don't get test-classes (negative case) - Test test-jar in test scope (edge case) Fixes eclipse-m2e#2174
31cb849 to
81d24a7
Compare
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