Upgrading Maven library to 3.9.9
I tried to upgrade the Maven library version to 3.9.9. However, it fails with the RepositorySystem instance creation:
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.123 s <<< FAILURE! - in com.google.cloud.tools.opensource.classpath.ClassPathBuilderTest
[ERROR] testBomToPaths_firstElementsAreBomMembers(com.google.cloud.tools.opensource.classpath.ClassPathBuilderTest) Time elapsed: 0.081 s <<< ERROR!
java.lang.ExceptionInInitializerError
at com.google.cloud.tools.opensource.classpath.ClassPathBuilderTest.<init>(ClassPathBuilderTest.java:42)
Caused by: com.google.common.base.VerifyException: Couldn't retrieve RepositorySystem
at com.google.cloud.tools.opensource.classpath.ClassPathBuilderTest.<init>(ClassPathBuilderTest.java:42)
In this pull request, I added Verify.verifyNotNull(system, "Couldn't retrieve RepositorySystem"); to make the failure point clear (before this, it was failing a generic NullPointerException without a specific line number).
/**
* Creates a new system configured for file and HTTP repository resolution.
*/
public static RepositorySystem newRepositorySystem() {
DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
locator.addService(TransporterFactory.class, FileTransporterFactory.class);
locator.addService(TransporterFactory.class, HttpTransporterFactory.class);
RepositorySystem system = locator.getService(RepositorySystem.class);
Verify.verifyNotNull(system, "Couldn't retrieve RepositorySystem");
return system;
}
The release note (https://maven.apache.org/docs/3.9.9/release-notes.html) says:
Mojos are prevented to bootstrap new instance of RepositorySystem (for example by using deprecated ServiceLocator), they should reuse RepositorySystem instance provided by Maven instead. See MNG-7471.
(3.9.0 release note also includes this)
Memo:
When the problem only happens in mvn command and not in IntelliJ, having JUnit waiting for debugger is helpful: ./mvnw test -Dtest="ClassPathBuilderTest#testBomToPaths_firstElementsAreBomMembers" -Dmaven.surefire.debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005
b/416442478