slachiewicz opened a new issue, #13211: URL: https://github.com/apache/maven/issues/13211
### Affected version 4.0.0-rc-6 (`maven-4.0.x` and `master` both have the code below) ### Bug description A parent resolved from a repository gets a `MavenProject` whose `getFile()` is the POM in the local (or project-local) repository and whose `getBasedir()` is therefore that repository directory. Maven 3 left both unset for such a parent, and plugins use `getBasedir() == null` as the signal "this project is not a checkout, look for its attached artifacts instead". Symptom where it was found: maven-site-plugin's `inheritance-interpolation` IT fails on Maven 4 because `DefaultSiteTool` (doxia-integration-tools) sees a basedir on the repository parent, looks for `src/site/site.xml` under it, finds nothing, and silently drops the inherited site descriptor (apache/maven-site-plugin#1259, mitigated on the sitetools side in apache/maven-doxia-sitetools#693). Where it happens: - [`DefaultModelBuilder.java:1903`](https://github.com/apache/maven/blob/maven-4.0.x/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.java#L1903) and [`:2019`](https://github.com/apache/maven/blob/maven-4.0.x/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.java#L2019) set `withPomFile(modelSource.getPath())` on every model whose source has a path, and a repository source has one. - [`DefaultProjectBuilder.java:1065-1069`](https://github.com/apache/maven/blob/maven-4.0.x/impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java#L1065) (`initParent`) then finds `parentModel.getPomFile()` non-null and takes the file branch, `build(true, parentPomFile, Sources.buildSource(parentPomFile))`, which does [`project.setFile(pomFile.toFile())`](https://github.com/apache/maven/blob/maven-4.0.x/impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java#L367). The artifact branch that keeps the file unset for non-workspace results ([`:483-490`](https://github.com/apache/maven/blob/maven-4.0.x/impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java#L483), `build(parent, null, Sources.resolvedSource(...))`) is never reached for parents. The same file branch also skips `setFile`/`setResolved` on the parent artifact, so `getParentArtifact().isResolved()` cannot be used to tell the cases apart either. Maven 3.9.16 for contrast: `readParentExternally` reads the parent with a null POM file, so [`DefaultProjectBuilder.java:885`](https://github.com/apache/maven/blob/maven-3.9.16/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java#L885) sees `parentPomFile == null` and goes through [`build(parentArtifact, ...)`](https://github.com/apache/maven/blob/maven-3.9.16/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java#L911) → [`build(localProject ? pomFile : null, ...)`](https://github.com/apache/maven/blob/maven-3.9.16/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java#L333), leaving the file null. `MavenProject.setPomFile` ([`MavenProject.java:278-284`](https://github.com/apache/maven/blob/maven-4.0.x/impl/maven-core/src/main/java/org/apache/maven/project/MavenProject.java#L278), since 3.2.4) exists precisely to "set project file without changing project basedir", which suggests the intended contract: a repository-built project may know its file but has no basedir. ### Steps to reproduce Build maven-site-plugin master with Maven 4.0.0-rc-6 and run `mvn verify -Prun-its -Dinvoker.test=inheritance-interpolation`: the child's effective site descriptor has `<bannerLeft name="child" />` instead of the parent's `bannerLeft`. Passes on 3.10.0-rc-1. Or, in any plugin, log `project.getParent().getBasedir()` for a project whose parent is not in the reactor: null on 3.9.x, a path under `~/.m2/repository/...` (or `.mvn/target/project-local-repo/...`) on 4.0.0-rc-6. ### Expected behavior `MavenProject.getBasedir()` is null for a parent that was resolved from a repository, as on Maven 3; either route `initParent` through the artifact branch unless the parent's source is a build (checkout) source, or use `setPomFile` rather than `setFile` when the parent came from a resolved source. -- 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]
