Skip to content

Upgrade to Maven 4.0.0-rc-3. #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 21, 2025
Merged

Upgrade to Maven 4.0.0-rc-3. #84

merged 4 commits into from
Mar 21, 2025

Conversation

desruisseaux
Copy link
Contributor

@desruisseaux desruisseaux commented Mar 15, 2025

Upgrade from Maven 4.0.0-rc-2 to 4.0.0-rc-3. There is some new methods in interfaces, which have been implemented as return List.of(). I'm not sure that returning unconditionally an empty list is the desired behaviour. If not, this pull request may need to be discarded.

@desruisseaux
Copy link
Contributor Author

Note: with Maven 4.0.0-rc-3, the tests of the Maven compiler plugin fail with the following stack trace:

java.lang.NullPointerException: Cannot invoke "org.apache.maven.api.services.Lookup.lookupOptional(java.lang.Class)" because the return value of "org.apache.maven.api.Session.getService(java.lang.Class)" is null
	at org.apache.maven.impl.DefaultToolchainManager.retrieveContext(DefaultToolchainManager.java:120)
	at org.apache.maven.impl.DefaultToolchainManager.getToolchainFromBuildContext(DefaultToolchainManager.java:90)
	at org.apache.maven.plugin.compiler.AbstractCompilerMojo.getToolchain(AbstractCompilerMojo.java:1530)
	at org.apache.maven.plugin.compiler.AbstractCompilerMojo.compiler(AbstractCompilerMojo.java:1046)
	at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1000)
	at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:157)
	at org.apache.maven.plugin.compiler.CompilerMojoTestCase.testCompileSkipTest(CompilerMojoTestCase.java:371)

I do not know how Mockito works (I do not use it myself), but I suspect that the following method of maven-plugin-testing-harness needs modification:

org.apache.maven.api.plugin.testing.stubs.SessionMock.getMockSession(LocalRepository)

The current implementation seems to define the behaviour of getService(Class) for various classes (RepositoryFactory, VersionParser, LocalRepositoryManager, ArtifactInstaller, ArtifactDeployer, ArtifactManager, ProjectManager, ArtifactFactory, ProjectBuilder, ModelXmlFactory), but I see no setting for Lookup.

@gnodet
Copy link
Contributor

gnodet commented Mar 15, 2025

I don't think it's really a good idea to use the session stub anyway. There's too much needed and a simple stub will almost never work. We can check, but I don't think any plugins we've migrated uses it. So maybe remove it.

Empty lists are fine for project and artifact stubs imho. Or use a fields and a setter to make those easier to use, that may be more reusable.

@desruisseaux
Copy link
Contributor Author

I can remove the JUnit tests of maven-compiler-plugin that depend on the session stub. It would remove 3 of the 14 tests (not necessarily a big lost, since I find the IT tests more useful anyway). A related question is whether we should also remove the session stub completely from maven-plugin-testing.

…ded in `ProjectStub`.

No setter added for `SessionStub` because the previously existing methods were already returning null or empty collections.
@desruisseaux
Copy link
Contributor Author

Just realized that this is a duplicated of #81, #83 and #67.

…s)` mock.

It resolves the `NullPointerException` observed during compiler plugin tests.
@desruisseaux
Copy link
Contributor Author

Added setter methods for usability. Also added an empty stub for Session.getService(Lookup.class). With the latter addition, the NullPointerException observed in the JUnit tests of maven-compiler-plugin is resolved, and there is no need anymore to delete some tests.

Copy link
Contributor

@gnodet gnodet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@slachiewicz
Copy link
Member

It would be good to modify gha to run tests also with Maven 4. So far all compilation and tests where under Maven 3.

@slachiewicz slachiewicz added this to the 4.0.0-beta-4 milestone Mar 19, 2025
@gnodet gnodet merged commit b66bbfc into apache:master Mar 21, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants