artemmukhin opened a new issue, #14135:
URL: https://github.com/apache/maven/issues/14135
### Affected version
4.0.0-rc-7
### Bug description
A POM declares a repository with releases disabled, for example
`apache.snapshots` of the Apache parent POMs or `sonatype-nexus-snapshots` of
`org.sonatype.oss:oss-parent:9`. One mirror in `settings.xml` covers this
repository and `central` (`*` or `external:*`). Then Maven 4.0.0-rc-7 does not
resolve release dependencies. Maven 3.9.11 builds the same project.
#### Reproducer
`settings.xml`:
```xml
<settings>
<mirrors>
<mirror>
<id>all</id>
<mirrorOf>*</mirrorOf>
<url>https://repo.maven.apache.org/maven2</url>
</mirror>
</mirrors>
</settings>
```
`pom.xml`, with one class in `src/main/java` that uses `StringUtils`:
```xml
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>policy-merge</artifactId>
<version>1</version>
<properties>
<maven.compiler.release>17</maven.compiler.release>
</properties>
<repositories>
<repository>
<id>snaps</id>
<url>https://repository.apache.org/snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.17.0</version>
</dependency>
</dependencies>
</project>
```
`mvn -s settings.xml -Dmaven.repo.local=<empty folder> compile`:
- Maven 3.9.11: `BUILD SUCCESS`.
- Maven 4.0.0-rc-7: `Could not find artifact
org.apache.commons:commons-lang3:jar:3.17.0`. Maven does not send a request for
the artifact. The plugins download correctly.
With `-X`, rc-7 shows that the project repository list has the policy of
`snaps` only:
```text
[DEBUG] Repositories (dependencies): [all
(https://repo.maven.apache.org/maven2, default, snapshots)]
[DEBUG] Resolving artifact org.apache.commons:commons-lang3:jar:3.17.0 from
[all (https://repo.maven.apache.org/maven2, default, snapshots)]
```
The model builder merges the policies correctly (`Replacing repositories
from test:policy-merge:jar:1` with `all (https://repo.maven.apache.org/maven2,
default, releases+snapshots)`). Only the repository lists of the `MavenProject`
lose the release policy.
#### Cause
1. The Maven 4 super POM has no `<repositories>`. `central` is only in the
request repositories (`ProjectBuildingRequest.getRemoteRepositories()`), and
these already have the mirror (`all`). In Maven 3.9, the effective model has
`central` from the super POM: `help:effective-pom` shows `snaps` and `central`
on 3.9.11, but only `snaps` on rc-7.
2.
[`DefaultProjectBuildingHelper.createArtifactRepositories`](https://github.com/apache/maven/blob/6d8f301b38af7399b36b862969d520974944f0b9/impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java#L124-L141)
applies the mirrors to the POM repositories (`snaps` becomes `all`, snapshots
only). Then it adds a request repository only if its id is new (line 135). The
request repository `all` (from `central`, releases) has the same id, so the
method drops it.
3.
[`MavenRepositorySystem.getEffectiveRepositories`](https://github.com/apache/maven/blob/6d8f301b38af7399b36b862969d520974944f0b9/impl/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java#L604-L631)
merges the policies of the repositories with the same id. But it gets only one
`all`.
In Maven 3.9, both `all` repositories come from the model. Thus both are in
the dominant list, and `getEffectiveRepositories` merges them to
releases+snapshots.
[`DefaultProjectBuilder`](https://github.com/apache/maven/blob/6d8f301b38af7399b36b862969d520974944f0b9/impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java#L1270-L1294)
uses the same method for the plugin repositories. Thus a snapshots-only
`<pluginRepository>` can have the same effect on plugins. I did not test this.
The code of steps 2 and 3 is the same on `maven-4.0.x` and `master`. I
tested only rc-7. apache/maven-resolver#2225 (fixed in Resolver 2.0.25) is a
different problem: the policy is lost in Maven core, before Resolver gets the
list.
#### Workaround
Give `central` a mirror of its own before the `*` mirror. Then the two ids
are different, and rc-7 keeps both repositories:
```xml
<mirror>
<id>central-mirror</id>
<mirrorOf>central</mirrorOf>
<url>https://repo.maven.apache.org/maven2</url>
</mirror>
```
```text
[DEBUG] Repositories (dependencies): [all
(https://repo.maven.apache.org/maven2, default, snapshots), central-mirror
(https://repo.maven.apache.org/maven2, default, releases)]
[INFO] BUILD SUCCESS
```
#### Possible fix
In `createArtifactRepositories`, keep a request repository with a known id
if both repositories are mirrors (both have mirrored repositories). Then
`getEffectiveRepositories` merges their policies. Resolver does the same in
`DefaultRemoteRepositoryManager.aggregateRepositories` with `mergeMirrors`. A
repository that is not a mirror keeps the current rule, so a POM repository
with the id `central` still replaces the request repository.
--
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]