You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2021/12/17 11:51:27 UTC

[maven-plugin-tools] 01/01: [MPLUGIN-385] Lower the tone and scope of warning

This is an automated email from the ASF dual-hosted git repository.

cstamas pushed a commit to branch MPLUGIN-385-clarify-provided-scope-for-mvn-plugin-api
in repository https://gitbox.apache.org/repos/asf/maven-plugin-tools.git

commit 1292df7961f4b05f29278a1b0007b7e86f94b26e
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Fri Dec 17 12:49:31 2021 +0100

    [MPLUGIN-385] Lower the tone and scope of warning
    
    The warning was too chatty, a bit pushy, and also it
    triggered on too broad condition (all of org.apache.maven groupIds).
    
    This change makes following modifications:
    * only maven-plugin-api is checked for (so JXR, Archiver will not trigger it)
    * message is really one liner about best practice (if anyone curious, go after it anyway)
---
 .../maven/plugin/plugin/AbstractGeneratorMojo.java | 32 ++++++----------------
 1 file changed, 9 insertions(+), 23 deletions(-)

diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java
index 3a5aacc..ffe14e9 100644
--- a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java
+++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java
@@ -204,23 +204,12 @@ public abstract class AbstractGeneratorMojo
                                 + "In the future this error will break the build.%n%n" ) );
         }
 
-        Set<Artifact> wrongScopedArtifacts = mavenDependenciesNotInProvidedScope();
-        if ( !wrongScopedArtifacts.isEmpty() )
+        boolean wrongScopedMavenPluginApi = mavenPluginApiDependencyNotInProvidedScope();
+        if ( wrongScopedMavenPluginApi )
         {
-            StringBuilder errorMessage = new StringBuilder(
-                "%n%nMaven dependencies of Maven Plugins should be in provided scope.%n"
-                    + "Please make sure that all your dependencies declared in POM whose group ID is%n"
-                    + "org.apache.maven have set '<scope>provided</scope>' as well.%n"
-                    + "In the future this error will break the build.%n%n"
-                    + "The following dependencies are in wrong scope:%n"
+            getLog().warn(
+                "It is best practice to keep maven-plugin-api dependency in provided scope."
             );
-            for ( Artifact artifact : wrongScopedArtifacts )
-            {
-                errorMessage.append( " * " ).append( artifact ).append( "%n" );
-            }
-            errorMessage.append( "%nPlease fix your build!%n%n" );
-
-            getLog().error( String.format( errorMessage.toString() ) );
         }
 
         String defaultGoalPrefix = getDefaultGoalPrefix( project );
@@ -314,23 +303,20 @@ public abstract class AbstractGeneratorMojo
     }
 
     /**
-     * Collects all dependencies having {@code org.apache.maven} group ID that are NOT in provided scope.
+     * Returns {@code true} if maven-plugin-api is NOT in provided scope.
      */
-    private Set<Artifact> mavenDependenciesNotInProvidedScope()
+    private boolean mavenPluginApiDependencyNotInProvidedScope()
     {
-        LinkedHashSet<Artifact> wrongScopedDependencies = new LinkedHashSet<>();
-
         for ( Artifact dependency : project.getArtifacts() )
         {
             if ( "org.apache.maven".equals( dependency.getGroupId() )
-                && dependency.getArtifactId().startsWith( "maven-" )
+                && dependency.getArtifactId().equals( "maven-plugin-api" )
                 && !Artifact.SCOPE_PROVIDED.equals( dependency.getScope() ) )
             {
-                wrongScopedDependencies.add( dependency );
+                return true;
             }
         }
-
-        return wrongScopedDependencies;
+        return false;
     }
 
     /**