4343
4444import java .io .File ;
4545import java .util .Arrays ;
46+ import java .util .Collections ;
4647import java .util .LinkedHashSet ;
4748import java .util .List ;
4849import java .util .Set ;
@@ -139,7 +140,7 @@ public abstract class AbstractGeneratorMojo
139140 * @since 3.5
140141 */
141142 @ Parameter
142- private List <String > mojoDependencies ;
143+ private List <String > mojoDependencies = null ;
143144
144145 /**
145146 * List of Remote Repositories used by the resolver
@@ -163,7 +164,36 @@ public abstract class AbstractGeneratorMojo
163164 * @since 3.3
164165 */
165166 @ Parameter
166- protected List <String > packagingTypes = Arrays .asList ( "maven-plugin" );
167+ protected List <String > packagingTypes = Collections .singletonList ( "maven-plugin" );
168+
169+ /**
170+ * Flag controlling is "expected dependencies in provided scope" check to be performed or not. Default value:
171+ * {@code true}.
172+ *
173+ * @since 3.6.3
174+ */
175+ @ Parameter ( defaultValue = "true" , property = "maven.plugin.checkExpectedProvidedScope" )
176+ private boolean checkExpectedProvidedScope = true ;
177+
178+ /**
179+ * List of {@code groupId} strings of artifact coordinates that are expected to be in "provided" scope. Default
180+ * value: {@code ["org.apache.maven"]}.
181+ *
182+ * @since 3.6.3
183+ */
184+ @ Parameter
185+ private List <String > expectedProvidedScopeGroupIds = Collections .singletonList ( "org.apache.maven" );
186+
187+ /**
188+ * List of {@code groupId:artifactId} strings of artifact coordinates that are to be excluded from "expected
189+ * provided scope" check. Default value: {@code ["org.apache.maven:maven-archiver", "org.apache.maven:maven-jxr"]}.
190+ *
191+ * @since 3.6.3
192+ */
193+ @ Parameter
194+ private List <String > expectedProvidedScopeExclusions = Arrays .asList (
195+ "org.apache.maven:maven-archiver" ,
196+ "org.apache.maven:maven-jxr" );
167197
168198 /**
169199 * @return the output directory where files will be generated.
@@ -209,23 +239,25 @@ public void execute()
209239 + "In the future this error will break the build." + LS + LS );
210240 }
211241
212- Set <Artifact > wrongScopedArtifacts = mavenDependenciesNotInProvidedScope ();
213- if ( !wrongScopedArtifacts .isEmpty () )
242+ if ( checkExpectedProvidedScope )
214243 {
215- StringBuilder errorMessage = new StringBuilder (
216- LS + LS + "Maven dependencies of Maven Plugins should be in provided scope." + LS
217- + "Please make sure that all your dependencies declared in POM whose group ID is" + LS
218- + "org.apache.maven have set '<scope>provided</scope>' as well." + LS
219- + "In the future this error will break the build." + LS + LS
220- + "The following dependencies are in wrong scope:" + LS
221- );
222- for ( Artifact artifact : wrongScopedArtifacts )
244+ Set <Artifact > wrongScopedArtifacts = dependenciesNotInProvidedScope ();
245+ if ( !wrongScopedArtifacts .isEmpty () )
223246 {
224- errorMessage .append ( " * " ).append ( artifact ).append ( LS );
225- }
226- errorMessage .append ( LS ).append ( "Please fix your build!" ).append ( LS ).append ( LS );
247+ StringBuilder errorMessage = new StringBuilder (
248+ LS + LS + "Some dependencies of Maven Plugins are expected to be in provided scope." + LS
249+ + "Please make sure that dependencies listed below declared in POM" + LS
250+ + "have set '<scope>provided</scope>' as well." + LS + LS
251+ + "The following dependencies are in wrong scope:" + LS
252+ );
253+ for ( Artifact artifact : wrongScopedArtifacts )
254+ {
255+ errorMessage .append ( " * " ).append ( artifact ).append ( LS );
256+ }
257+ errorMessage .append ( LS ).append ( LS );
227258
228- getLog ().error ( errorMessage .toString () );
259+ getLog ().error ( errorMessage .toString () );
260+ }
229261 }
230262
231263 String defaultGoalPrefix = getDefaultGoalPrefix ( project );
@@ -294,7 +326,7 @@ else if ( !goalPrefix.equals( defaultGoalPrefix ) )
294326 }
295327 catch ( InvalidPluginDescriptorException | ExtractionException e )
296328 {
297- throw new MojoExecutionException ( "Error extracting plugin descriptor: \ ' " + e .getLocalizedMessage () + "\ ' " ,
329+ throw new MojoExecutionException ( "Error extracting plugin descriptor: '" + e .getLocalizedMessage () + "'" ,
298330 e );
299331 }
300332 catch ( LinkageError e )
@@ -319,16 +351,17 @@ static String getDefaultGoalPrefix( MavenProject project )
319351 }
320352
321353 /**
322- * Collects all dependencies having {@code org.apache.maven} group ID that are NOT in provided scope.
354+ * Collects all dependencies expected to be in "provided" scope but are NOT in " provided" scope.
323355 */
324- private Set <Artifact > mavenDependenciesNotInProvidedScope ()
356+ private Set <Artifact > dependenciesNotInProvidedScope ()
325357 {
326358 LinkedHashSet <Artifact > wrongScopedDependencies = new LinkedHashSet <>();
327359
328360 for ( Artifact dependency : project .getArtifacts () )
329361 {
330- if ( "org.apache.maven" .equals ( dependency .getGroupId () )
331- && dependency .getArtifactId ().startsWith ( "maven-" )
362+ String ga = dependency .getGroupId () + ":" + dependency .getArtifactId ();
363+ if ( expectedProvidedScopeGroupIds .contains ( dependency .getGroupId () )
364+ && !expectedProvidedScopeExclusions .contains ( ga )
332365 && !Artifact .SCOPE_PROVIDED .equals ( dependency .getScope () ) )
333366 {
334367 wrongScopedDependencies .add ( dependency );
0 commit comments