gnodet commented on code in PR #11394:
URL: https://github.com/apache/maven/pull/11394#discussion_r2500339155


##########
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSourceRoot.java:
##########
@@ -169,7 +169,7 @@ public DefaultSourceRoot(final Path baseDir, ProjectScope 
scope, Resource resour
                 resource.getIncludes(),
                 resource.getExcludes(),
                 Boolean.parseBoolean(resource.getFiltering()),
-                
nonBlank(resource.getTargetPath()).map(baseDir::resolve).orElse(null),
+                nonBlank(resource.getTargetPath()).map(Path::of).orElse(null),

Review Comment:
   > `Path.of(String)` creates a path relative the to current working 
directory, which is not the desired output directory. I think that 
`DefaultSourceRoot` is okay, and the change rather needs to be applied in the 
codes that call this constructor. The problem seems to be in the following 
classes:
   > 
   > * `org.apache.maven.project.ConnectedResource` line 124.
   > * `org.apache.maven.project.DefaultProjectBuilder` lines 704 and 707.
   > * `org.apache.maven.project.MavenProject` line 840
   > 
   > The above-cited codes set the first parameter to 
`project.getBaseDirectory()` while it should be 
`project.getBuild().getOutputDirectory()`.
   > 
   > Note: the `baseDir` parameter name of `DefaultSourceRoot` is misleading. 
The Javadoc said _"the base directory for resolving relative paths"_, which can 
be the `baseDir` of the Maven project but not necessarily. It should be 
understood as any base directory for resolving paths. This parameter could be 
renamed `parentDir` if `baseDir` is too misleading.
   
   `Path.of(String)` just creates a relative path. But not relative to 
anything.  It's only when resolved against a directory that it will become 
relative to that directory.
   The built `Path` will be resolved against the correct directory, that's what 
happens in the maven-resource-plugin for example, which will resolve this path 
against either `project.build.outputDirectory` or 
`project.build.testOutputDirectory`, depending which mojo is called.
   I agree that there may be a mismatch, but it sounds difficult to just thrown 
away the m-resources-p at the moment.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to