From ba52bfe600408f50966bb1765b9627aa622c0114 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 9 May 2024 22:17:59 +0200 Subject: [PATCH] [MNG-8117] Maven PluginVersionResolver improvement (#1502) Produces output like this: https://gist.github.com/cstamas/3ca4bc6cea5f701054061871b5db3f35 --- https://issues.apache.org/jira/browse/MNG-8117 --- .../DefaultPluginVersionResolver.java | 54 +++++++++++++++---- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java b/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java index 904606a2a04a..9082b30887d9 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java @@ -39,6 +39,7 @@ import org.apache.maven.model.Build; import org.apache.maven.model.Plugin; import org.apache.maven.plugin.MavenPluginManager; +import org.apache.maven.plugin.PluginIncompatibleException; import org.apache.maven.plugin.PluginResolutionException; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.version.PluginVersionRequest; @@ -175,6 +176,8 @@ private void selectVersion(DefaultPluginVersionResult result, PluginVersionReque throws PluginVersionResolutionException { String version = null; ArtifactRepository repo = null; + boolean resolvedPluginVersions = !versions.versions.isEmpty(); + boolean searchPerformed = false; if (versions.releaseVersion != null && !versions.releaseVersion.isEmpty()) { version = versions.releaseVersion; @@ -184,8 +187,13 @@ private void selectVersion(DefaultPluginVersionResult result, PluginVersionReque repo = versions.latestRepository; } if (version != null && !isCompatible(request, version)) { + logger.info( + "Latest version of plugin {}:{} failed compatibility check", + request.getGroupId(), + request.getArtifactId()); versions.versions.remove(version); version = null; + searchPerformed = true; } if (version == null) { @@ -206,16 +214,26 @@ private void selectVersion(DefaultPluginVersionResult result, PluginVersionReque } } - for (Version v : releases) { - String ver = v.toString(); - if (isCompatible(request, ver)) { - version = ver; - repo = versions.versions.get(version); - break; + if (!releases.isEmpty()) { + logger.info( + "Looking for compatible RELEASE version of plugin {}:{}", + request.getGroupId(), + request.getArtifactId()); + for (Version v : releases) { + String ver = v.toString(); + if (isCompatible(request, ver)) { + version = ver; + repo = versions.versions.get(version); + break; + } } } - if (version == null) { + if (version == null && !snapshots.isEmpty()) { + logger.info( + "Looking for compatible SNAPSHOT version of plugin {}:{}", + request.getGroupId(), + request.getArtifactId()); for (Version v : snapshots) { String ver = v.toString(); if (isCompatible(request, ver)) { @@ -228,15 +246,27 @@ private void selectVersion(DefaultPluginVersionResult result, PluginVersionReque } if (version != null) { + // if LATEST worked out of the box, remain silent as today, otherwise inform user about search result + if (searchPerformed) { + logger.info("Selected plugin {}:{}:{}", request.getGroupId(), request.getArtifactId(), version); + } result.setVersion(version); result.setRepository(repo); } else { + logger.warn( + resolvedPluginVersions + ? "Could not find compatible version of plugin {}:{} in any plugin repository" + : "Plugin {}:{} not found in any plugin repository", + request.getGroupId(), + request.getArtifactId()); throw new PluginVersionResolutionException( request.getGroupId(), request.getArtifactId(), request.getRepositorySession().getLocalRepository(), request.getRepositories(), - "Plugin not found in any plugin repository"); + resolvedPluginVersions + ? "Could not find compatible plugin version in any plugin repository" + : "Plugin not found in any plugin repository"); } } @@ -261,8 +291,12 @@ private boolean isCompatible(PluginVersionRequest request, String version) { try { pluginManager.checkPrerequisites(pluginDescriptor); - } catch (Exception e) { - logger.warn("Ignoring incompatible plugin version {}", version, e); + } catch (PluginIncompatibleException e) { + if (logger.isDebugEnabled()) { + logger.warn("Ignoring incompatible plugin version {}:", version, e); + } else { + logger.warn("Ignoring incompatible plugin version {}: {}", version, e.getMessage()); + } return false; }