Relative <targetPath> are resolved against the wrong directory #11322
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.
The specification that we wrote in
maven.mdosaid about the<targetPath>element:However, the implementation in the
DefaultSourceRoot(Session session, Path baseDir, Source source)constructor resolves againstbaseDir, which is not even insidetarget.Furthermore, the specification is incomplete. The default directory should be
target/classeswhen the scope is "main", but should betarget/test-classeswhen the scope is "test". The current specification said nothing about the fact that the default value depends on the scope.This pull request is divided in 4 commits. The first commit is only trivial javadoc fixes. The second commit refactors the
DefaultSourceRootimplementation as a Java record, but without significant changes to its behaviour. The benefit of using record is to reduce the boilerplate code (the number of lines is reduced by about one third), and it also forces us to be more rigorous since all constructions must pass by the canonical constructor. The third commit is the one that actually fixes the issue described above. The last commit proposes a new method in theProjectinterface.