Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.6
-
None
-
Maven 3.0.4, Oracle Java jdk1.6.0_30
Description
When setting the mergeUserSettings configuration parameter [1] to "true" and configuring multiple executions for the maven-invoker-plugin, a java.lang.IllegalStateException with a message of "Cannot reset sourceLevel attribute; it is already set to: user-level" is thrown from org.apache.maven.settings.TrackableBase.setSourceLevel() [2] when merging the "private Settings settings" local variable [3] in org.apache.maven.plugin.invoker.AbstractInvokerMojo with the settings file configured through the "settingsFile" plugin configuration parameter [4] inside the AbstractInvokerMojo.runBuilds() [5] method.
The problem appears to be that the MavenSettingsMerger [6] mutates the "recessive" org.apache.maven.settings.Settings parameter it receives in its "merge" method, setting the source level attribute of the Settings parameter. TrackableBase (which Settings extends) has a rule that its source level attribute can only be set one time. When multiple executions are configured for the maven-invoker-plugin, it appears all executions share the same org.apache.maven.settings.Settings instance. Therefore, when the second execution executes and org.apache.maven.settings.SettingsUtils.merge() [7] is called, which calls org.apache.maven.settings.merge.MavenSettingsMerger.merge() [6], and the source level attribute is set on the same Settings instance a second time, the IllegalStateException is thrown.
The same IllegalStateException occurs in a maven reactor project containing multiple modules, each which configure one execution for the maven-invoker-plugin.
I don't know enough about the history behind why the MavenSettingsMerger.merge() method mutates the "recessive" Settings parameter to be able to determine if this logic is correct. In lieu of making changes in MavenSettingsMerger, a copy of the Settings instance variable, without setting the source level attribute, could be made in AbstractInvokerMojo.runBuilds() [5] before passing this variable to SettingsUtils.merge().
[1] http://maven.apache.org/plugins/maven-invoker-plugin-1.6/run-mojo.html#mergeUserSettings
[4] http://maven.apache.org/plugins/maven-invoker-plugin-1.6/run-mojo.html#settingsFile
[7] http://maven.apache.org/ref/3.0.4/maven-core/xref/org/apache/maven/settings/SettingsUtils.html#40
[8] http://maven.apache.org/guides/mini/guide-multiple-modules.html