apache / apache/maven

[MNG-6732] DefaultArtifactDescriptorReader.loadPom to check IGNORE_MISSING policy upon ArtifactTransferException

Open
#8,525 6 comments 0 reactions 0 assignees View on GitHub
enhancement priority:major
Dominant language
Java
Stars
5.3k
Forks
3.1k
Avg merge
20h 42m
Merged PRs (30d)
297

Description

**[Tomo Suzuki](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=suztomo)** opened **[MNG-6732](https://issues.apache.org/jira/browse/MNG-6732?redirect=false)** and commented

# Problem

Sometimes [Linkage Checker enforcer rule](https://github.com/GoogleCloudPlatform/cloud-opensource-java/tree/master/enforcer-rules) does not receive resolved artifact list because of a missing artifact even when the missing artifact is unused after Maven's dependency mediation.

# Background

The enforcer rule fails to retrieve artifact list through `DefaultProjectDependenciesResolver.resolve` when applied to [grpc-java-by-example/chat-example/chat-vaadin-client](https://github.com/saturnism/grpc-java-by-example/tree/master/chat-example/chat-vaadin-client) because of the missing `xerces:xerces-impl:2.6.2`, even though the artifact does not appear in the final dependency graph. The artifact does not appear in the graph because of Maven's dependency mediation.

Artifact xerces:xerces-impl:2.6.2 is not published in Maven Central.

In contrast, the enforcer rule can retrieve artifact list when applied to https://github.com/suztomo/spring-cloud-gcp/tree/v1.1.2-linkage-checker project even though it outputs "[WARNING] The POM for xerces:xerces-impl:jar:2.6.2 is missing, no dependency information available". The missing artifact does not appear in final dependency graph.

https://github.com/GoogleCloudPlatform/cloud-opensource-java/issues/834

# Diagnosis

Currently `DefaultArtifactDescriptorReader.loadPom` method checks "ArtifactDescriptorPolicy.IGNORE_MISSING" policy upon ArtifactNotFoundException. This allows `DefaultProjectDependenciesResolver.resolve` calls `repoSystem.resolveDependencies` to obtain partially resolved artifact list, rather than failing entirely, when there is a missing artifact (such as `xerces:xerces-impl:2.6.2`)

However, when a retired Maven repository is involved (such as http://repository.codehaus.org/ ), `DefaultArtifactDescriptorReader.loadPom` gets an ArtifactTransferException and throws ArtifactDescriptorException without checking "ArtifactDescriptorPolicy.IGNORE_MISSING" policy (excerpt below), and thus `DefaultProjectDependenciesResolver.resolve` does not return partially resolved artifact list.

```java
catch ( ArtifactResolutionException e )
{
if ( e.getCause() instanceof ArtifactNotFoundException )
{
missingDescriptor( session, trace, a, (Exception) e.getCause() );
if ( ( getPolicy( session, a, request ) & ArtifactDescriptorPolicy.IGNORE_MISSING ) != 0 )
{
return null;
}
}
result.addException( e );
throw new ArtifactDescriptorException( result );
}
```

from [DefaultArtifactDescriptorReader.java](https://github.com/apache/maven/blob/d3ace78/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java#L255)

ArtifactNotFoundException is a special case of [ArtifactTransferException](https://maven.apache.org/resolver/apidocs/org/eclipse/aether/transfer/ArtifactTransferException.html).

# Example Project

Example project to demonstrate the diagnosis: https://github.com/suztomo/maven-missing-artifact . In this example, even though module-b and module-c have the same dependency section, module-c fails to run Maven because of a repository section containing a retired repository URL.

---

**Affects:** 3.6.1

**Attachments:**
- [62884438-89260580-bd04-11e9-8c4a-897d4b736dc7.png](https://issues.apache.org/jira/secure/attachment/12977387/62884438-89260580-bd04-11e9-8c4a-897d4b736dc7.png) (_757.20 kB_)

**Issue Links:**
- [MNG-7758](https://issues.apache.org/jira/browse/MNG-7758) o.e.aether.resolution.ArtifactResolutionException incorrectly examined when multiple repositories are involved
(_**"is a child of"**_)

**Remote Links:**
- [GitHub Pull Request #276
](https://github.com/apache/maven/pull/276)
- [GitHub Pull Request #277
](https://github.com/apache/maven/pull/277)

1 votes, 1 watchers

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.