akashchamp opened a new pull request, #545: URL: https://github.com/apache/maven-build-cache-extension/pull/545
Fixes #503. When the extension is loaded by an embedder that does not set `MavenExecutionRequest#getMultiModuleProjectDirectory()` (m2e in the report), `CacheUtils.getMultimoduleRoot` dereferences `null` while `CacheConfigImpl` is being initialized, and the import fails with the NPE from the issue. `getMultimoduleRoot` now falls back to `session.getExecutionRootDirectory()` (the request base directory) and, if that is also unset, to the current working directory, which is what the Maven CLI uses as the base directory. When the multi-module directory is set, the behaviour does not change. I picked this order because it seemed the least surprising, but I'm happy to change it, e.g. to the top-level project basedir, if you prefer something else. Verification: - Added `CacheUtilsMultimoduleRootTest`. On `master`, two of its three cases fail with the same NPE as the issue (`Cannot invoke "java.io.File.toPath()" because the return value of "...getMultiModuleProjectDirectory()" is null`), and all three pass with the change. - `mvn test`: 100 tests, 0 failures, with checkstyle, spotless and rat enabled. - `mvn verify -Prun-its -Dit.test=BuildExtensionTest,CoreExtensionTest,MultiModulePartialBuildTest,SubtreeBuildCacheHitTest,NoConfigFileDefaultsTest,CustomConfigPathTest`: 26 ITs pass on Maven 3.9.16. --- To make clear that you license your contribution under the [Apache License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0) check one of the following: - [x] I hereby declare this contribution to be licensed under the [Apache License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0) - [ ] I hereby declare that I have filed an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
