How do I write simple a java main() that:
- Takes a maven scope name and a pom.xml file path as arguments
- Produces a list of Strings containing the classpath of the corresponding maven project and scope
- Only depends on libraries that are currently being maintained?
Motivation:
I'm trying to upgrade the dependencies of the fitnesse-maven-classpath plugin found at https://github.com/amolenaar/fitnesse-maven-classpath , which has usability issues because of its dependency on maven-embedder-3.0.4, see for example Fitnesse maven-classpath-plugin conflicting with Guava jar and Maven / Plexus ComponentLookupException - classpath nightmare? .
Simply upgrading the dependency in the plugin's pom file to maven-embedder-3.1.1 and replacing import com.sonatype.aether with import com.eclipse.aether in the java source makes the project compilable, but the tests fail with a long list of errors that starts as follows:
Unable to parse POM file: org.codehaus.plexus.component.repository.exception.ComponentLookupException: com.google.inject.ProvisionException: Guice provision errors:
1) No implementation for java.util.Set<org.eclipse.aether.RepositoryListener> was bound.
while locating java.util.Set<org.eclipse.aether.RepositoryListener>
for parameter 0 at org.eclipse.aether.internal.impl.DefaultRepositoryEventDispatcher.<init>(Unknown Source)
while locating org.eclipse.aether.internal.impl.DefaultRepositoryEventDispatcher
at ClassRealm[maven, parent: ClassRealm[maven-parent, parent: null]]
at ClassRealm[maven, parent: ClassRealm[maven-parent, parent: null]]
while locating org.eclipse.aether.impl.RepositoryEventDispatcher
for parameter 0 at org.eclipse.aether.internal.impl.DefaultMetadataResolver.<init>(Unknown Source)
while locating org.eclipse.aether.internal.impl.DefaultMetadataResolver
at ClassRealm[maven, parent: ClassRealm[maven-parent, parent: null]]
at ClassRealm[maven, parent: ClassRealm[maven-parent, parent: null]]
while locating org.eclipse.aether.impl.MetadataResolver
for parameter 0 at org.apache.maven.repository.internal.DefaultVersionResolver.<init>(Unknown Source)
while locating org.apache.maven.repository.internal.DefaultVersionResolver
at ClassRealm[maven, parent: ClassRealm[maven-parent, parent: null]]
at ClassRealm[maven, parent: ClassRealm[maven-parent, parent: null]]
while locating org.eclipse.aether.impl.VersionResolver
for parameter 0 at org.eclipse.aether.internal.impl.DefaultRepositorySystem.<init>(Unknown Source)
while locating org.eclipse.aether.internal.impl.DefaultRepositorySystem
at ClassRealm[maven, parent: ClassRealm[maven-parent, parent: null]]
at ClassRealm[maven, parent: ClassRealm[maven-parent, parent: null]]
while locating org.eclipse.aether.RepositorySystem
while locating org.apache.maven.artifact.resolver.DefaultArtifactResolver
at ClassRealm[maven, parent: ClassRealm[maven-parent, parent: null]]
at ClassRealm[maven, parent: ClassRealm[maven-parent, parent: null]]
while locating org.apache.maven.artifact.resolver.ArtifactResolver
while locating org.apache.maven.repository.legacy.LegacyRepositorySystem
at ClassRealm[maven, parent: ClassRealm[maven-parent, parent: null]]
at ClassRealm[maven, parent: ClassRealm[maven-parent, parent: null]]
while locating org.apache.maven.repository.RepositorySystem
while locating org.apache.maven.execution.DefaultMavenExecutionRequestPopulator
at ClassRealm[maven, parent: ClassRealm[maven-parent, parent: null]]
at ClassRealm[maven, parent: ClassRealm[maven-parent, parent: null]]
while locating org.apache.maven.execution.MavenExecutionRequestPopulator
2) No implementation for java.util.Set<org.eclipse.aether.RepositoryListener> was bound.
while locating java.util.Set<org.eclipse.aether.RepositoryListener>
for parameter 0 at org.eclipse.aether.internal.impl.DefaultRepositoryEventDispatcher.<init>(Unknown Source)
while locating org.eclipse.aether.internal.impl.DefaultRepositoryEventDispatcher
...
etc
...
at ClassRealm[maven, parent: ClassRealm[maven-parent, parent: null]]
at ClassRealm[maven, parent: ClassRealm[maven-parent, parent: null]]
while locating org.apache.maven.execution.MavenExecutionRequestPopulator
37 errors
at com.google.inject.internal.InjectorImpl$3.get(InjectorImpl.java:974)
at org.eclipse.sisu.inject.LazyBeanEntry.getValue(LazyBeanEntry.java:82)
at org.eclipse.sisu.plexus.LazyPlexusBean.getValue(LazyPlexusBean.java:51)
at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:260)
... 37 more
More specifically the plugin in essence consists of two parts: First deriving a classpath from a pom file, and second, feeding that classpath to fitnesse. The first part, classpath derivation, fails with the above error message when upgrading to maven-embedder-3.1.1, and with a less verbose message when upgrading to 3.5.4.
Is there a simple alternative for the existing implementation of the classpath derivation that only depends on modern libraries, say on https://github.com/apache/maven-dependency-plugin/tree/maven-dependency-plugin-3.1.1 ?
I'm specifically asking for the code of a main() method to make sure that I can transform in into plugin code, rather than having to assume that my code gets called from say a running mvn process that would have already computed the classpath.