From c44304fe33e091be2a4b6a5d65f06ba777a692a0 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 9 May 2024 22:18:12 +0200 Subject: [PATCH] [MNG-8118] Backport to Maven 3.9.x (#1505) Produces output like this: https://gist.github.com/cstamas/3ca4bc6cea5f701054061871b5db3f35 --- https://issues.apache.org/jira/browse/MNG-8117 --- .../DefaultPluginVersionResolver.java | 52 +++++++++++++++---- 1 file changed, 42 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 67adceb8075a..0f3761063eb9 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 @@ -35,6 +35,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; @@ -158,6 +159,8 @@ private void selectVersion(DefaultPluginVersionResult result, PluginVersionReque throws PluginVersionResolutionException { String version = null; ArtifactRepository repo = null; + boolean resolvedPluginVersions = !versions.versions.isEmpty(); + boolean searchPerformed = false; if (StringUtils.isNotEmpty(versions.releaseVersion)) { version = versions.releaseVersion; @@ -167,8 +170,11 @@ private void selectVersion(DefaultPluginVersionResult result, PluginVersionReque repo = versions.latestRepository; } if (version != null && !isCompatible(request, version)) { + logger.info("Latest version of plugin " + request.getGroupId() + ":" + request.getArtifactId() + + " failed compatibility check"); versions.versions.remove(version); version = null; + searchPerformed = true; } if (version == null) { @@ -191,16 +197,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)) { @@ -213,15 +229,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"); } } @@ -246,8 +274,12 @@ private boolean isCompatible(PluginVersionRequest request, String version) { try { pluginManager.checkRequiredMavenVersion(pluginDescriptor); - } catch (Exception e) { - logger.debug("Ignoring incompatible plugin version " + version + ": " + e.getMessage()); + } 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; }