ClassCircularityError: java/lang/WeakPairMap$Pair$Weak in JUnit5, Springboot, Pact Project in Debug Mode - junit5

We have a spring boot project using JUnit 5 and Pact. We are using OpenJDK 17. When we run the JUnit 5 tests, we don't face any problems, but when we want to debug them, we get the below problem.
Note: I tried many versions of JUnit Jupiter and Pact dependencies but could not solve the issue.
When we remove the pact junit5 consumer and provider dependencies, the debug works fine.
I also tried Async Stack Traces -> Instrumenting Agent option on/off in IntelliJ but it did not solve anything.
Any help is much appreciated.
Error Message:
Connected to the target VM, address: '127.0.0.1:52218', transport: 'socket'
Internal Error occurred.
org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-jupiter' failed to discover tests
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:160)
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverSafely(EngineDiscoveryOrchestrator.java:132)
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discover(EngineDiscoveryOrchestrator.java:107)
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discover(EngineDiscoveryOrchestrator.java:78)
at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:110)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:57)
at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: org.junit.platform.commons.JUnitException: MethodSelector [className = 'com.emirates.ocsl.skeleton.ct.tests.SkeletonCT', methodName = 'iGetResponseSuccessfully', methodParameterTypes = ''] resolution failed
at org.junit.platform.launcher.listeners.discovery.AbortOnFailureLauncherDiscoveryListener.selectorProcessed(AbortOnFailureLauncherDiscoveryListener.java:39)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolveCompletely(EngineDiscoveryRequestResolution.java:103)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.run(EngineDiscoveryRequestResolution.java:83)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolver.resolve(EngineDiscoveryRequestResolver.java:113)
at org.junit.jupiter.engine.discovery.DiscoverySelectorResolver.resolveSelectors(DiscoverySelectorResolver.java:46)
at org.junit.jupiter.engine.JupiterTestEngine.discover(JupiterTestEngine.java:69)
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:152)
... 13 more
Caused by: java.lang.ClassCircularityError: java/lang/WeakPairMap$Pair$Weak
at java.base/java.lang.WeakPairMap$Pair.weak(WeakPairMap.java:201)
at java.base/java.lang.WeakPairMap.putIfAbsent(WeakPairMap.java:123)
at java.base/java.lang.Module.implAddReads(Module.java:488)
at java.base/java.lang.Module.implAddReads(Module.java:449)
at java.base/java.lang.System$2.addReads(System.java:2335)
at java.base/jdk.internal.module.Modules.addReads(Modules.java:90)
at java.base/java.lang.reflect.Proxy$ProxyBuilder.lambda$getDynamicModule$1(Proxy.java:918)
at java.base/jdk.internal.loader.AbstractClassLoaderValue$Memoizer.get(AbstractClassLoaderValue.java:329)
at java.base/jdk.internal.loader.AbstractClassLoaderValue.computeIfAbsent(AbstractClassLoaderValue.java:205)
at java.base/java.lang.reflect.Proxy$ProxyBuilder.getDynamicModule(Proxy.java:908)
at java.base/java.lang.reflect.Proxy$ProxyBuilder.mapToModule(Proxy.java:846)
at java.base/java.lang.reflect.Proxy$ProxyBuilder.<init>(Proxy.java:651)
at java.base/java.lang.reflect.Proxy$ProxyBuilder.<init>(Proxy.java:656)
at java.base/java.lang.reflect.Proxy.lambda$getProxyConstructor$0(Proxy.java:429)
at java.base/jdk.internal.loader.AbstractClassLoaderValue$Memoizer.get(AbstractClassLoaderValue.java:329)
at java.base/jdk.internal.loader.AbstractClassLoaderValue.computeIfAbsent(AbstractClassLoaderValue.java:205)
at java.base/java.lang.reflect.Proxy.getProxyConstructor(Proxy.java:427)
at java.base/java.lang.reflect.Proxy.newProxyInstance(Proxy.java:1037)
at java.base/sun.reflect.annotation.AnnotationParser$1.run(AnnotationParser.java:302)
at java.base/sun.reflect.annotation.AnnotationParser$1.run(AnnotationParser.java:300)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
at java.base/sun.reflect.annotation.AnnotationParser.annotationForMap(AnnotationParser.java:300)
at java.base/sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:289)
at java.base/sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:121)
at java.base/sun.reflect.annotation.AnnotationParser.parseSelectAnnotations(AnnotationParser.java:102)
at java.base/sun.reflect.annotation.AnnotationType.<init>(AnnotationType.java:146)
at java.base/sun.reflect.annotation.AnnotationType.getInstance(AnnotationType.java:85)
at java.base/sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:262)
at java.base/sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:121)
at java.base/sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:73)
at java.base/java.lang.Class.createAnnotationData(Class.java:4068)
at java.base/java.lang.Class.annotationData(Class.java:4057)
at java.base/java.lang.Class.getAnnotation(Class.java:3940)
at java.base/java.lang.reflect.AnnotatedElement.isAnnotationPresent(AnnotatedElement.java:292)
at java.base/java.lang.Class.isAnnotationPresent(Class.java:3950)
at org.junit.platform.commons.util.AnnotationUtils.findAnnotation(AnnotationUtils.java:136)
at org.junit.platform.commons.util.AnnotationUtils.isAnnotated(AnnotationUtils.java:105)
at org.junit.jupiter.engine.discovery.predicates.IsTestableMethod.test(IsTestableMethod.java:52)
at org.junit.jupiter.engine.discovery.predicates.IsTestMethod.test(IsTestMethod.java:23)
at org.junit.jupiter.engine.discovery.predicates.IsTestableMethod.test(IsTestableMethod.java:26)
at java.base/java.util.function.Predicate.lambda$or$2(Predicate.java:101)
at java.base/java.util.function.Predicate.lambda$or$2(Predicate.java:101)
at org.junit.platform.commons.util.ReflectionUtils.findMethod(ReflectionUtils.java:1345)
at org.junit.platform.commons.util.ReflectionUtils.isMethodPresent(ReflectionUtils.java:1244)
at org.junit.jupiter.engine.discovery.predicates.IsTestClassWithTests.hasTestOrTestFactoryOrTestTemplateMethods(IsTestClassWithTests.java:50)
at org.junit.jupiter.engine.discovery.predicates.IsTestClassWithTests.test(IsTestClassWithTests.java:46)
at org.junit.jupiter.engine.discovery.predicates.IsTestClassWithTests.test(IsTestClassWithTests.java:27)
at java.base/java.util.function.Predicate.lambda$or$2(Predicate.java:101)
at org.junit.jupiter.engine.discovery.MethodSelectorResolver.resolve(MethodSelectorResolver.java:87)
at org.junit.jupiter.engine.discovery.MethodSelectorResolver.resolve(MethodSelectorResolver.java:75)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.lambda$resolve$2(EngineDiscoveryRequestResolution.java:150)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1602)
at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129)
at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:527)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:513)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:647)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolve(EngineDiscoveryRequestResolution.java:189)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolve(EngineDiscoveryRequestResolution.java:126)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolveCompletely(EngineDiscoveryRequestResolution.java:92)
... 18 more

After long debugging hours, the below configuration in pom.xml works. ktor libraries create conflict in our Springboot, webflux, junit5, openJDK17 project.
<dependency>
<groupId>au.com.dius.pact.provider</groupId>
<artifactId>junit5</artifactId>
<version>${pact.version}</version>
<exclusions>
<exclusion>
<groupId>io.ktor</groupId>
<artifactId>ktor-network-tls-certificates</artifactId>
</exclusion>
<exclusion>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-netty</artifactId>
</exclusion>
<exclusion>
<groupId>io.ktor</groupId>
<artifactId>ktor-http-jvm</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>au.com.dius.pact.consumer</groupId>
<artifactId>junit5</artifactId>
<version>${pact.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>io.ktor</groupId>
<artifactId>ktor-network-tls-certificates</artifactId>
</exclusion>
<exclusion>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-netty</artifactId>
</exclusion>
<exclusion>
<groupId>io.ktor</groupId>
<artifactId>ktor-http-jvm</artifactId>
</exclusion>
</exclusions>
</dependency>

Related

Azure Keyvault library to Atlassian Confluence plugin pom.xml

I am trying to combine these 2 tutorials - Confluence Hello World Macro & Azure keyvault quick start:
https://developer.atlassian.com/server/framework/atlassian-sdk/create-a-confluence-hello-world-macro/
https://learn.microsoft.com/en-us/azure/key-vault/secrets/quick-create-java?tabs=azure-cli
After having added the 2 Azure dependencies to the pom.xml of the maven project and running atlas-mvn clean package I receive an error message about 3 banned dependencies.
I looked for the newest Azure packages at the maven portal. Then it was reduced to one.
Found Banned Dependency: org.slf4j:slf4j-api:jar:1.7.25
Then I added added exclusions to the dependency section:
This resulted that the build ran successfully, however, the Confluence plugin produces a runtime error:
java.lang.NoClassDefFoundError
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/Logger
at com.azure.security.keyvault.secrets.SecretClientBuilder.(SecretClientBuilder.java:110)
Can you please help, how can I achieve this?
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-security-keyvault-secrets</artifactId>
<version>4.3.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.4.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
error: java.lang.NoClassDefFoundError Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/Logger at com.azure.security.keyvault.secrets.SecretClientBuilder.(SecretClientBuilder.java:110)
The above error indicates that JVM is not able to found org/slf4j/Logger class in your application's path.The simplest reason for this error is the missing Slf4j.jar file.
If the problem is caused due to the missing slf4j.jar file then you can fix it by adding a relevant version of slf4j.jar into your path.
Use the latest version of the jar in which version of the JAR file you should add will depend upon the application.
In Maven , you can also add the following dependency in your pom.xml file to download sl4j.jar
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
Reference:
java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory - Stack Overflow

Outputting Docx4J to PDF File

I am using the commercial version of docx4j and we have a requirement to output the document to PDF format. I understand there are two options. One is to use an online converter tool. The other is to use a legacy docx4j-export-fo. We can't use the first approach due to the company firewall rules, so the system needs to be self contained, which means option 2.
My pom looks like the following:
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.4</version>
</dependency>
<dependency>
<groupId>com.plutext</groupId>
<artifactId>Plutext-Enterprise</artifactId>
<version>8.1.0.4</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-JAXB-Internal</artifactId>
<version>8.2.9</version>
</dependency>
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-export-fo</artifactId>
<version>8.2.9</version>
<exclusions>
<exclusion>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>xmlgraphics-commons</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.pdfbox</groupId>
<artifactId>fontbox</artifactId>
</exclusion>
</exclusions>
</dependency>
The exclusions were to address the issues detected by the maven enforcer. When attempting to covert the word document to PDF, the test fails with the following:
Looks like your endpoint URL 'http://localhost:9016/v1/00000000-0000-0000-0000-000000000000/convert' is wrong
This seems to indicate the first approach is being used rather than the second, which is not the desired result.
I've also tried using apache poi to do the conversion, but that fails with NPEs. Can anyone suggest how to get round this issue?
The current options are set out at https://www.docx4java.org/blog/2020/09/office-pptxxlsxdocx-to-pdf-to-in-docx4j-8-2-3/
Whether export-fo is used depends on:
Class<?> clazz = Class.forName("org.docx4j.convert.out.fo.FOExporterVisitor");
Can you confirm docx4j-export-fo is on your classpath? Perhaps you have security settings prohibiting reflection?
You can try invoking it directly:
FOSettings settings = Docx4J.createFOSettings();
settings.setOpcPackage(wmlPackage);
settings.setApacheFopMime("application/pdf");
Docx4J.toFO(settings, outputStream, Docx4J.FLAG_NONE);

Running JUnit tests in IntelliJ, getting: java.lang.NoSuchMethodError: org.junit.platform.commons.util.Preconditions.notNull

I'm trying to run unit tests in IntelliJ, and I'm getting the stack trace:
Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.Preconditions.notNull([Ljava/lang/Object;Ljava/lang/String;)[Ljava/lang/Object;
at org.junit.platform.launcher.core.DefaultLauncher.registerTestExecutionListeners(DefaultLauncher.java:71)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:44)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Googling the error message doesn't help - all of the hits I get back have to do with Gradle dependencies, but I'm using Maven (and I've triple-checked my dependencies). Here is my pom:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.0-M3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.0-M3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.0.0-M3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
And what's frustrating is that this does actually work in a different project, so I'm not sure what's gone wrong here.
Never mind, I figured it out - in case anybody else has the same problem: It turned out that my unit test was importing org.junit.Test, rather than org.junit.jupiter.api.Test, but I didn't declare a dependency on junit-vintage in my pom.xml. The solution was to either explicitly declare the correct version of junit-vintage in my pom (4.12.0-M3 in my case), or switch my unit tests over to import org.junit.jupiter.api.Test.

Maven dependency exclusions: Same artifact-id issue

I have an Apache Cocoon Project and I wanted to update Apache FOP from 1.0 to 1.1, in order to fix foreign (non-latin) script issues, such as Greek.
I found FOP 1.1 has a Maven dependency:
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>fop</artifactId>
<version>1.1</version>
</dependency>
ERROR: Failed to execute goal on project X: Could not resolve dependencies for project com.X:jar:1.0-SNAPSHOT: Failure to find org.apache.avalon.framework:avalon-framework-api:jar:4.2.0 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
I search for a solution in this issue and I found that this dependency has broken links to some other dependencies, which FOP 1.1 needs to call. These are connected with Avalon framework API 4.2. I read in a mailing list that maybe trying to use exclusions and call extra dependencies is working fine. The solution was this code:
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>fop</artifactId>
<version>1.1</version>
<exclusions>
<exclusion>
<artifactId>avalon-framework-api</artifactId>
<groupId>org.apache.avalon.framework</groupId>
</exclusion>
<exclusion>
<artifactId>avalon-framework-impl</artifactId>
<groupId>org.apache.avalon.framework</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- these two are to correct issues in fop dependency -->
<dependency>
<groupId>avalon-framework</groupId>
<artifactId>avalon-framework-api</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>avalon-framework</groupId>
<artifactId>avalon-framework-impl</artifactId>
<version>4.2.0</version>
</dependency>
Now compilation returns the following ERROR2: "Failed to execute goal org.apache.cocoon:cocoon-maven-plugin:1.0.0-M2:prepare (prepare) on project X: There are at least two artifacts with the ID 'avalon-framework-api': avalon-framework:avalon-framework-api:jar:4.2.0:compile".
Of course there are. Two dependencies are excluded, the broken ones, and two of them are called, the correct ones. How can I fix this issue?
Haven't tested this yet, but perhaps excluding org.apache.avalon.framework v4.2.0 and include the latest v4.3.1 instead. Such as:
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>fop</artifactId>
<version>1.1</version>
<exclusions>
<exclusion>
<groupId>org.apache.avalon.framework</groupId>
<artifactId>avalon-framework-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.avalon.framework</groupId>
<artifactId>avalon-framework-impl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.avalon.framework</groupId>
<artifactId>avalon-framework-api</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>org.apache.avalon.framework</groupId>
<artifactId>avalon-framework-impl</artifactId>
<version>4.3.1</version>
</dependency>

Can anyone give a good example of using org.apache.maven.cli.MavenCli programmatically?

I'm trying to create an intelliJ plugin that needs to execute maven targets on the current project. All the talk in the intertubes recommends using the MavenEmbedder. Good luck with that. The 2.0.4 version isn't well supported and there are no references for how to use it.
I gave it a whirl and ran into a wall where the embedder had not been initialized with all the fields it needs. Reflective private member injection? Awesome! Why would anyone need an obvious way to initialize an object?
It seems a few people are using a 2.1 version with some success. I have been unable to find that in a jar or even sources.
I went and checked out the 3.0 version of the embedder project: http://maven.apache.org/ref/3.0-beta-3/maven-embedder/ It does away with the MavenEmbedder object all together and seems to only support access through the main or doMain methods on MavenCli. Has anyone used these methods and can give some advice?
Yeah, the's not much in the way of documentation of MavenCli. The API is significatly simpler but i'd still like some examples. Here's one that works...
MavenCli cli = new MavenCli();
int result = cli.doMain(new String[]{"compile"},
"/home/aioffe/workspace/MiscMaven",
System.out, System.out);
System.out.println("result: " + result);
It takes a dir and runs the 'compile' phase...
Working maven configuration for maven 3.6.3
Code
MavenCli cli = new MavenCli();
System.setProperty("maven.multiModuleProjectDirectory", workingDirectory);
cli.doMain(new String[]{"compile"}, workingDirectory, System.out, System.err);
Dependencies
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<version>3.6.3</version>
</dependency>
<!-- https://issues.apache.org/jira/browse/MNG-5995 -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>3.6.3</version>
</dependency>
<!-- enable logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.30</version>
</dependency>
</dependencies>
The dependency matrix information for provided scopes and dynamically acquired components can be a bit confusing. It was for me, since it appeared to me that I got all the required items by direct or transitive dependency, but then remote resolution didn't work.
I wanted to jump to Maven 3.3.3 (latest as of 2015-05-25). I got it working without the sisu errors that presented when I tried to optimistically update to current versions of things specified here (and elsewhere). This is a project with a tag that worked with the example specified as of today using JDK8.
https://github.com/mykelalvis/test-maven-embedder/tree/20150525-working
Relevant deps (SLF4J is just so I can see the logs)
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<version>3.3.3</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-basic</artifactId>
<version>1.0.2.v20150114</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-wagon</artifactId>
<version>1.0.2.v20150114</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http</artifactId>
<version>2.9</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
<version>2.9</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http-lightweight</artifactId>
<version>2.9</version>
</dependency>
Running this is:
rm -r ~/.m2/repository/org/apache/maven/plugins/maven-clean-plugin/
mvn exec:java
Probably should have made it a unit test of some sort.
If someone has a superior solution for embedded Maven 3.3.3 (i.e. came up with a smaller or more range-oriented set of required dependencies), please post them.
to build on the comment from #StevePerkins, and using maven version 3.1.0,
I had to exclude the transitive dependency from aether-connector-wagon to wagon-provider-api to get it working.
pom.xml:
(...)
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<version>3.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-wagon</artifactId>
<version>0.9.0.M2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http</artifactId>
<version>2.5</version>
<scope>test</scope>
</dependency>
(...)
and here is a java example:
(...)
MavenCli cli = new MavenCli();
ByteArrayOutputStream baosOut = new ByteArrayOutputStream();
ByteArrayOutputStream baosErr = new ByteArrayOutputStream();
PrintStream out = new PrintStream(baosOut, true);
PrintStream err = new PrintStream(baosErr, true);
cli.doMain( new String[] { "clean" }, new File("."), out, err );
String stdout = baosOut.toString("UTF-8");
String stderr = baosErr.toString("UTF-8");
(...)
full example here
There is a dependency matrix for each version of maven-embedder, e.g. for 3.2.5: http://maven.apache.org/ref/3.2.5/maven-embedder/dependencies.html
Based on that I had to use org.apache.maven:maven-embedder:jar:3.2.5, org.apache.maven:maven-aether-provider:jar:3.2.5, and org.apache.maven.wagon:wagon-provider-api:jar:2.8.
It also fixes dependency on very old Guava library, since this version uses 18.0.
Dependency list for Maven Embedded 3.6.3 version that works in my Spring Boot 2.3 project (JDK8 or JDK 11 runtime):
<!-- Maven Embedder -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<version>3.6.3</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>3.6.3</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http</artifactId>
<version>3.3.4</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-basic</artifactId>
<version>1.1.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-wagon</artifactId>
<version>1.1.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>org.usefultoys</groupId>
<artifactId>slf4j-toys</artifactId>
<version>1.6.3</version>
</dependency>
The Maven CLI command looks like to:
// Maven CLI to execute Maven Commands
MavenCli cli = new MavenCli();
int result = cli.doMain(args, workingDirectory,
org.usefultoys.slf4j.LoggerFactory.getInfoPrintStream(LOGGER),
org.usefultoys.slf4j.LoggerFactory.getErrorPrintStream(LOGGER));
HTH