Skip to content

Conversation

@floison51
Copy link

@floison51 floison51 commented Dec 17, 2019

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Make sure there is a JIRA issue filed
    for the change (usually before you start working on it). Trivial changes like typos do not
    require a JIRA issue. Your pull request should address just this issue, without
    pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [MPH-XXX] - Fixes bug in ApproximateQuantiles,
    where you replace MPH-XXX with the appropriate JIRA issue. Best practice
    is to use the JIRA issue title in the pull request title and in the first line of the
    commit message.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean verify to make sure basic checks pass. A more thorough check will
    be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its clean verify).

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

@floison51
Copy link
Author

I added an integration test case reproducing MCOMPILER-372 test case.
Bug root case: project2 depends on project1. Both are modularized. Test compilation of project2 fails because project2 test can acceed to project 1 module but not to project 1 test class patch (i.e. project1/target/test-classes).
When this configuration is detected, project 1 test class path is added as -patchModule compiler options. All integration tests pass.

@floison51 floison51 closed this Dec 20, 2019
@floison51

This comment was marked as resolved.

@floison51 floison51 reopened this Dec 20, 2019
@floison51

This comment was marked as outdated.

* @param modulePathElt
* @return
*/
private File getModuleTestPathElt( File modulePathElt )
Copy link
Contributor

Choose a reason for hiding this comment

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

This methods feels a bit like best guessing. It is better to loop over all the reactorProjects to find the Paths that belong to the same Maven Project (and because of that to the same module)

@floison51
Copy link
Author

floison51 commented Jan 6, 2020 via email

path element, if it does not succeed, guess test path element from path
element
@floison51
Copy link
Author

floison51 commented Jan 7, 2020 via email

{

// Get test path from reactor projects
File result = getModuleTestPathEltFromReactorProjects( modulePathElt );
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you change this to return getModuleTestPathEltFromReactorProjects( modulePathElt );

I can't think of a reason why we need the rest of the code in this method. It would mean something went wrong somewhere else.

@floison51
Copy link
Author

floison51 commented Jan 8, 2020 via email

Prj2 was not uploading test jar to local repo.
Prj2 was not opening prj2 package.
@rfscholte
Copy link
Contributor

If you only need the reactor, please never use install anymore, but just verify. And with this plugin you should only use compile, test-compile or package (in case you depend on the jar).
I wonder if we should allow pulling in test-jars from outside the reactor. I know it is possible, but it is a codesmell to me, especially in the JPMS world. (and if overcomplicates the code)

@floison51
Copy link
Author

floison51 commented Jan 9, 2020 via email

@floison51
Copy link
Author

floison51 commented Jan 9, 2020 via email

@gnodet gnodet changed the title MCOMPILER-372 - fix test compile issue: added dependency test path for modules [MCOMPILER-372] - fix test compile issue: added dependency test path for modules Feb 13, 2023
@desruisseaux
Copy link
Contributor

This is fixed, under some conditions, by #320. The condition is to use module source hierarchy as described in this wiki page.

If, nevertheless, there is a need for patching a module with a test-jar outside the compilation unit of the patched module (i.e., the other modules who need that test-jar cannot be in the same multi-module project), then this is doable. But I would like to see if the above paragraph can address most common cases first.

@jira-importer
Copy link

Resolve #577

@slawekjaranowski slawekjaranowski added the waiting-for-feedback Waiting for 90 days until issues or pull request will be closed label Jun 20, 2025
@github-actions

This comment was marked as resolved.

@github-actions github-actions bot added the Stale label Aug 20, 2025
@desruisseaux desruisseaux changed the base branch from master to maven-compiler-plugin-3.x September 17, 2025 08:24
@github-actions
Copy link

This pull request is stale because it has been waiting for feedback for 60 days. Remove the stale label or comment on this PR, or it will be automatically closed in 30 days.

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 pull request fixes a test compilation issue (MCOMPILER-372) for modularized multi-module Maven projects where test classes depend on test classes from other modules. When a modularized dependency is added, its test jar classes are ignored if added to the classpath. The fix adds these test jars using --patch-module instead.

Changes:

  • Enhanced test compilation to detect modularized dependencies and patch their modules with test paths
  • Added reactor project resolution to map module paths to their corresponding test output directories
  • Created integration test with 4 projects (prj0-3) demonstrating multi-level modularized test jar dependencies

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 15 comments.

File Description
src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java Refactored preparePaths to use patch modules map; added patchModulesForTestDependencies and helper methods to resolve test paths from reactor projects
src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java Added reactorProjects field and getter method to enable access to reactor project information
src/it/MCOMPILER-372_modularized_testjar/* Integration test structure with 4 modularized projects testing multi-level test jar dependencies

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


compilerArgs.add(patchModuleValue.toString());

// Patch module to add
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

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

The comment is incomplete - it ends abruptly with "Patch module to add" without finishing the sentence. This should be completed to clearly describe what is being added to the patch module.

Suggested change
// Patch module to add
// Patch module to add main output directory, source roots, and modularized test dependencies

Copilot uses AI. Check for mistakes.
Comment on lines +429 to +431
} catch (IOException e) {
throw new RuntimeException(e);
}
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

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

IOException is being caught and wrapped in a RuntimeException, which loses the exception type information and converts a checked exception to an unchecked one. This could make it harder for callers to handle specific error scenarios. Consider wrapping it in a more specific exception type or propagating the IOException with better context about what failed.

Copilot uses AI. Check for mistakes.
Comment on lines +528 to +530
* Get module test path element from module path element
* @param modulePathElt
* @return
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

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

The javadoc is missing a description for the @param modulePathElt parameter and the @return value. These should be documented to explain what the parameter represents and what is returned.

Suggested change
* Get module test path element from module path element
* @param modulePathElt
* @return
* Get module test path element from module path element.
*
* @param modulePathElt the module path element, typically the main output directory of a module
* @return the corresponding test output directory for the given module path element,
* or {@code null} if no matching test path can be resolved or it does not exist

Copilot uses AI. Check for mistakes.
Comment on lines +400 to +401
* As prj1.jar is added as a module, pjr1-tests.jar classes are ignored if we add jar class path<br/>
* We have to add pjr1-tests.jar as --patch-module<p/>
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

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

There's a typo in the javadoc comment: "pjr1-tests.jar" should be "prj1-tests.jar" to match the project naming convention used throughout the codebase and examples.

Suggested change
* As prj1.jar is added as a module, pjr1-tests.jar classes are ignored if we add jar class path<br/>
* We have to add pjr1-tests.jar as --patch-module<p/>
* As prj1.jar is added as a module, prj1-tests.jar classes are ignored if we add jar class path<br/>
* We have to add prj1-tests.jar as --patch-module<p/>

Copilot uses AI. Check for mistakes.

for (String path : patchModuleEntry.getValue()) {
patchModuleValue.append(path).append(PS);
}
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

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

The patch module value will have a trailing path separator (PS) after the loop completes. For example, if there are two paths, the result would be "moduleName=path1:path2:" with an extra colon at the end. This trailing separator should be removed after the loop to ensure the --patch-module argument is correctly formatted.

Suggested change
}
}
if (!patchModuleEntry.getValue().isEmpty()) {
patchModuleValue.setLength(patchModuleValue.length() - 1);
}

Copilot uses AI. Check for mistakes.
Comment on lines +74 to +77
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
<scope>test</scope>
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

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

The indentation uses tabs instead of spaces, which is inconsistent with the XML file's general indentation style. This dependency declaration should use spaces to match the surrounding code.

Suggested change
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
<scope>test</scope>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
<scope>test</scope>

Copilot uses AI. Check for mistakes.
Comment on lines +66 to +69
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
<scope>test</scope>
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

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

The indentation uses tabs instead of spaces, which is inconsistent with the XML file's general indentation style. This dependency declaration should use spaces to match the surrounding code.

Suggested change
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
<scope>test</scope>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
<scope>test</scope>

Copilot uses AI. Check for mistakes.
* As prj1.jar is added as a module, pjr1-tests.jar classes are ignored if we add jar class path<br/>
* We have to add pjr1-tests.jar as --patch-module<p/>
* @param mainModuleName
* param mainModuleTarget
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

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

The @param documentation is malformed. The second parameter "mainModuleTarget" is missing the "@" symbol and appears as "param mainModuleTarget" instead of "@param mainModuleTarget". This will cause the javadoc to be incorrectly formatted.

Suggested change
* param mainModuleTarget
* @param mainModuleTarget

Copilot uses AI. Check for mistakes.
Comment on lines +400 to +401
* As prj1.jar is added as a module, pjr1-tests.jar classes are ignored if we add jar class path<br/>
* We have to add pjr1-tests.jar as --patch-module<p/>
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

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

There's a typo in the javadoc comment: "pjr1-tests.jar" should be "prj1-tests.jar" to match the project naming convention.

Suggested change
* As prj1.jar is added as a module, pjr1-tests.jar classes are ignored if we add jar class path<br/>
* We have to add pjr1-tests.jar as --patch-module<p/>
* As prj1.jar is added as a module, prj1-tests.jar classes are ignored if we add jar class path<br/>
* We have to add prj1-tests.jar as --patch-module<p/>

Copilot uses AI. Check for mistakes.
Comment on lines +72 to +75
</sources>
<packageName>prj0.conf</packageName>
<outputDirectory>${project.build.directory}/generated-sources/xjcConf</outputDirectory>
</configuration>
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

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

The indentation uses tabs instead of spaces, which is inconsistent with the XML file's general indentation style. This should use spaces to match the surrounding code.

Suggested change
</sources>
<packageName>prj0.conf</packageName>
<outputDirectory>${project.build.directory}/generated-sources/xjcConf</outputDirectory>
</configuration>
</sources>
<packageName>prj0.conf</packageName>
<outputDirectory>${project.build.directory}/generated-sources/xjcConf</outputDirectory>
</configuration>

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.x waiting-for-feedback Waiting for 90 days until issues or pull request will be closed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants