e-gineering/gitflow-helper-maven-plugin

UnsupportedOperationException when promoting master - Maven 3.6.0 Compatibility

jddipqd opened this issue · 2 comments

When executing a deploy goal on master branch, the promote-master goal throws an exception:

$ mvn clean deploy
[INFO] Scanning for projects...
[INFO] GitBranchInfo: [name='master', type='MASTER', pattern='(origin/)?master']
[INFO] gitflow-helper-maven-plugin: Enabling MasterPromoteExtension. GIT_BRANCH: [master] matches masterBranchPattern: [(origin/)?master]
[ERROR] Internal error: java.lang.UnsupportedOperationException -> [Help 1]
org.apache.maven.InternalErrorException: Internal error: java.lang.UnsupportedOperationException
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:120)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: java.lang.UnsupportedOperationException
    at java.util.Collections$UnmodifiableCollection.removeAll (Collections.java:1068)
    at com.e_gineering.maven.gitflowhelper.MasterPromoteExtension.afterProjectsRead (MasterPromoteExtension.java:192)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:264)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/InternalErrorException

Plugin configuration:

<plugin>
	<groupId>com.e-gineering</groupId>
	<artifactId>gitflow-helper-maven-plugin</artifactId>
	<version>2.1.1</version>
	<configuration>
		<releaseDeploymentRepository>...</releaseDeploymentRepository>
		<stageDeploymentRepository>...</stageDeploymentRepository>
		<snapshotDeploymentRepository>...</snapshotDeploymentRepository>
	</configuration>
	<extensions>true</extensions>
	<executions>
		<execution>
			<goals>
				<goal>enforce-versions</goal>
				<goal>retarget-deploy</goal>
				<goal>tag-master</goal>
				<goal>promote-master</goal>
			</goals>
		</execution>
	</executions>
</plugin>

Maven version:

mvn -version
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T20:41:47+02:00)
Java version: 1.8.0_191, vendor: Oracle Corporation
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

Gah! Looks like maven finally figured out they should make internal collections unable to be modified.

I experienced the same issue when using gitflow-helper-maven-plugin with Maven 3.6.0. It appears that since Maven 3.6.0 previously mutable collections (e.g. list of BuildPlugins of a MavenProject) are now returning immutable collection upon calling MavenProject.getBuildPlugins(). (see also https://github.com/apache/maven/blob/44826ab446d1115d464e73e7e308df36dcf7d39b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java#L781).

A quick fix could be to obtain the 'BuildPlugin' list directly from the Model (MavenProject.getModel().getBuild().getPlugins()), rather then via the 'convenience' method MavenProject.getBuildPlugins. There is however a comment in the code suggesting that the MavenProject.getModel() could be removed in the future (https://github.com/apache/maven/blob/44826ab446d1115d464e73e7e308df36dcf7d39b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java#L224), so this path could potentially break (again).