[ 
https://issues.apache.org/jira/browse/MNG-7610?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17649040#comment-17649040
 ] 

Michael Osipov commented on MNG-7610:
-------------------------------------

[~sjaranowski], do you want to take a look at this?

> ValidatingConfigurationListener doesn't validate, causing wrong "parameters 
> ... are missing or invalid" errors
> --------------------------------------------------------------------------------------------------------------
>
>                 Key: MNG-7610
>                 URL: https://issues.apache.org/jira/browse/MNG-7610
>             Project: Maven
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 3.8.6
>         Environment: mvn -version
> Apache Maven 3.8.6
> java -version
> openjdk version "11" 2018-09-25
>            Reporter: Peter Bugla
>            Priority: Major
>
> Applies to mvn 3.8.6 (and at least some earlier versions, but our project 
> uses 3.8.6 now), mvn-core.
> {*}Short description{*}:
> ValidatingConfigurationListener (see constructor) considers all parameters 
> marked as required in a plugin as missing, causing an otherwise perfectly 
> fine mvn run to wrongly end with an error statement
> Detailed description:
> *Short intro* / history / pointing out that it's not my rare irrelevant 
> personal issue:
> There are already some articles on StackOverflow getting the following error 
> message after an mvn run that uses a plugin, which has at least one required 
> parameter.
> Apart from obvious user errors, where someone just forgot to set a required 
> parameter, looking closely there are also a bunch of cases (including mine) 
> where the required parameter(s) are set perfectly fine, the triggered plugin 
> execution used them successfully, so they were obviously there, but mvn still 
> ends with the error statement.:
> [ERROR] Failed to execute goal 
> <plugin_groupId>:<plugin_artifactId>:<plugin_version>:<goal> (default-cli) on 
> project <your_mvn_project_name>: The parameters 
> '<name_of_parameter_marked_as_required_in_plugin.xml>' for goal 
> <plugin_groupId>:<plugin_artifactId>:<plugin_version>:<goal> are missing or 
> invalid
> --
> *Specific example* (the one I encountered):
> [ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.1.0:java 
> (default-cli) on project qat.lup.alltests: The parameters 'mainClass' for 
> goal org.codehaus.mojo:exec-maven-plugin:3.1.0:java are missing or invalid
> Excerpt from my pom.xml:
>             <plugin>
>                 <groupId>org.codehaus.mojo</groupId>
>                 <artifactId>exec-maven-plugin</artifactId>
>                 <version>3.1.0</version>
>                 <executions>
>                     <execution>
>                         <id>MyExecutionId</id>
>                         <goals>
>                             <goal>java</goal>
>                         </goals>
>                     </execution>
>                 </executions>
>                 <configuration>
>                     <mainClass>full.package.ClassName</mainClass>
>                     <arguments>
>                         <argument>argument_1_for_class_ClassName</argument>
>                         <argument>argument_2_for_class_ClassName</argument>
>                         <argument>argument_3_for_class_ClassName</argument>
>                     </arguments>
>                 </configuration>
>             </plugin>
> Started with:
> mvn -s settings.xml exec:java
> Run result:
> The execution of full.package.ClassName via the plugin worked perfectly. So 
> obviously "mainClass" was found and read correctly by exec-maven-plugin, 
> otherwise it would have failed.
> However that mvn run always ends with the error message:
> [ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.1.0:java 
> (default-cli) on project qat.lup.alltests: The parameters 'mainClass' for 
> goal org.codehaus.mojo:exec-maven-plugin:3.1.0:java are missing or invalid
> --
> *My analysis* (all file names and line numbers are references against mvn 
> 3.8.6 checked out with the according tag from your git):
> As there was no answer in StackOverflow that worked for me, I dug deeper in 
> my case:
> The relevant configuration in plugin.xml of 
> org.codehaus.mojo:exec-maven-plugin:3.1.0 concerning the parameter mainClass 
> seems fine (it's set as required as expected, no visible issue with that).
> So I checked where that error message originates from and backtrack from 
> there:
> - The error message is from
>   PluginParameterException.java:45 
> (org.apache.maven.plugin.PluginParameterException) (in constructor).
> - this (in the relevant case) is called from DefaultMavenPluginManager.java 
> (in multiple places, but I believe the relevant one here is:
>   DefaultMavenPluginManager.java:644 
> (org.apache.maven.plugin.internal.DefaultMavenPluginManager) (in 
> populatePluginFields)
> - DefaultMavenPluginManager.java:630 calls 
> ValidatingConfigurationListener.java:46 (constructor) and I think in there is 
> the issue:
>   It gets the parameters from the mojoDescriptor, checks if they are marked 
> as required and if yes adds them to "missingParameters" without
>   checking if the parameters are actually present in the parameters supplied 
> to the "mojo".
>   DefaultMavenPluginManager.java:639 then gets "missingParameters" from 
> ValidatingConfigurationListener and turns that into a
>   PluginParameterException in DefaultMavenPluginManager.java:644 (depending 
> on if configuratorId is basic, otherwise it handles it differently in else).
> {*}My conclusion{*}:
> So I think the constructor of ValidatingConfigurationListener just needs to 
> check, if the parameters marked as required are actually present
>   according to its task, which includes according to JavaDoc "[...] check for 
> required but missing parameters." and put only those actually missing in 
> "missingParameters".
>   
> I assume that should solve the issue.
> (When fixing it, make sure to additionally check, whether the purpose of the 
> if/else depending on configuratorId in DefaultMavenPluginManager.java:642-653 
> makes sense in this context, as it seems to call a different validation in 
> the else part.)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to