Skip to content

Conversation

@gnodet
Copy link
Contributor

@gnodet gnodet commented Jul 25, 2025

Fixes #10996

When external tools like IntelliJ launch Maven directly using the ClassWorlds launcher without setting the maven.mainClass system property, Maven fails with:

org.codehaus.plexus.classworlds.launcher.ConfigurationException: No such property: maven.mainClass

Root Cause

The m2.conf file was changed to use ${maven.mainClass} but this property is only set by the Maven launcher scripts (mvn and mvn.cmd). External tools that launch Maven directly don't set this property.

Solution

This change adds a default value for maven.mainClass in m2.conf:

set maven.mainClass default org.apache.maven.cling.MavenCling

How it works

  1. When Maven launcher scripts run, they set -Dmaven.mainClass=org.apache.maven.cling.MavenCling (or other variants for --enc, --shell, --up)
  2. When external tools launch Maven without setting this property, the ClassWorlds configuration now provides a default value
  3. The default value org.apache.maven.cling.MavenCling is the standard Maven CLI entry point

Impact

  • Maven continues to work normally when launched via mvn scripts
  • External tools like IntelliJ can now launch Maven without needing to know about the new maven.mainClass property
  • The fix is minimal and maintains backward compatibility

The solution uses the same ClassWorlds configuration syntax already used elsewhere in the m2.conf file (set maven.conf default ${maven.home}/conf).


Pull Request opened by Augment Code with guidance from the PR author

Fixes apache#10996

When external tools like IntelliJ launch Maven directly using the
ClassWorlds launcher without setting the maven.mainClass system
property, Maven fails with 'No such property: maven.mainClass'.

This change adds a default value for maven.mainClass in m2.conf
so that external tools can launch Maven without needing to know
about this property. The default value is org.apache.maven.cling.MavenCling
which is the standard Maven CLI entry point.

The fix maintains backward compatibility - Maven launcher scripts
continue to work normally by setting the property explicitly,
while external tools now have a sensible default.
@gnodet gnodet added the bug Something isn't working label Jul 25, 2025
@gnodet gnodet requested a review from cstamas July 25, 2025 07:37
@gnodet gnodet merged commit 4e50e95 into apache:master Jul 28, 2025
19 checks passed
@github-actions github-actions bot added this to the 4.1.0 milestone Jul 28, 2025
@gnodet
Copy link
Contributor Author

gnodet commented Jul 28, 2025

💚 All backports created successfully

Status Branch Result
maven-4.0.x

Questions ?

Please refer to the Backport tool documentation

gnodet added a commit to gnodet/maven that referenced this pull request Jul 28, 2025
Fixes apache#10996

When external tools like IntelliJ launch Maven directly using the
ClassWorlds launcher without setting the maven.mainClass system
property, Maven fails with 'No such property: maven.mainClass'.

This change adds a default value for maven.mainClass in m2.conf
so that external tools can launch Maven without needing to know
about this property. The default value is org.apache.maven.cling.MavenCling
which is the standard Maven CLI entry point.

The fix maintains backward compatibility - Maven launcher scripts
continue to work normally by setting the property explicitly,
while external tools now have a sensible default.

(cherry picked from commit 4e50e95)
@gnodet gnodet deleted the fix-maven-mainclass-default branch July 28, 2025 07:46
gnodet added a commit that referenced this pull request Aug 5, 2025
)

Fixes #10996

When external tools like IntelliJ launch Maven directly using the
ClassWorlds launcher without setting the maven.mainClass system
property, Maven fails with 'No such property: maven.mainClass'.

This change adds a default value for maven.mainClass in m2.conf
so that external tools can launch Maven without needing to know
about this property. The default value is org.apache.maven.cling.MavenCling
which is the standard Maven CLI entry point.

The fix maintains backward compatibility - Maven launcher scripts
continue to work normally by setting the property explicitly,
while external tools now have a sensible default.

(cherry picked from commit 4e50e95)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-4.0.x bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to launch Maven: org.codehaus.plexus.classworlds.launcher.ConfigurationException: No such property: maven.mainClass

2 participants