Re: [m2e-users] Programmatically run maven goal |
I use:eclipse mars where m2e has version 1.6.0Linux Mint 17 - however solution should be multiplatform2015-09-20 22:17 GMT+02:00 Marek Jagielski <marek.jagielski@xxxxxxxxx>:Hi,I am developing pde plugin where user projects are maven nature projects. My plugin requires m2e to handle project configuration from user perspective.In some occasion I needed to run "package" goal programmatically. I was doing like this as below:    String path = project.getLocation().toOSString();    MavenCli cli = new MavenCli();    int result = cli.doMain(new String[] { "package", "-T 4C", "-DskipTests" }, path, null, null);    return result == 0 ? true : false;However, I was using separate bundle:   <dependency>    Â<groupId>org.apache.maven</groupId>    Â<artifactId>maven-embedder</artifactId>    Â<version>3.2.3</version>   </dependency>that was integrated usingÂmaven-bundle-plugin.Doing further development I started using m2e and reached compatibility issues. I decided to use only m2e api.With the same code, but using m2e I got exception:-Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script matchSo I started to look into m2e api. I tried code like this:    IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry();    IFile pomFile = project.getFile(new Path("pom.xml"));    IMavenProjectFacade projectFacade = projectManager.create(pomFile, true, new NullProgressMonitor());    MavenProject mp = projectFacade.getMavenProject();    IMavenExecutionContext ec = MavenPlugin.getMaven().createExecutionContext();    ec.getExecutionRequest().getGoals().add("package");    ec.getExecutionRequest().setBaseDirectory(mp.getBasedir());    ec.getExecutionRequest().setPom(mp.getFile());    ec.getExecutionRequest().setBuilderId("multithreaded");    ec.getExecutionRequest().setDegreeOfConcurrency(4);    ec.execute(projectFacade.getMavenProject(),new ICallable<Boolean>() {      @Override      public Boolean call(IMavenExecutionContext mec, IProgressMonitor pm) throws CoreException {        return true;      }    }, new NullProgressMonitor());without errors, however without expected results. In console I got:21:40:43.440 [Worker-37] DEBUG o.e.m.c.i.builder.MavenBuilder - Building project test121:40:43.443 [Worker-37] DEBUG o.e.a.i.i.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for /home/marek/.m2/repository21:40:43.444 [Worker-37] DEBUG o.e.m.c.p.c.AbstractCustomizableLifecycleMapping - Build participants for MavenProject: org.examples:example:1.0.0-SNAPSHOT @ /home/marek/Projects/systemInCloudModeler/runtime-EclipseApplication/test1/pom.xml21:40:43.444 [Worker-37] DEBUG o.e.m.c.p.c.AbstractCustomizableLifecycleMapping - Mojo execution key: org.apache.maven.plugins:maven-resources-plugin:2.6:resources (execution: default-resources, phase: process-resources)21:40:43.444 [Worker-37] DEBUG o.e.m.c.p.c.AbstractCustomizableLifecycleMapping - Action: execute21:40:43.444 [Worker-37] DEBUG o.e.m.c.p.c.AbstractCustomizableLifecycleMapping - Mojo execution key: org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (execution: default-compile, phase: compile)21:40:43.444 [Worker-37] DEBUG o.e.m.c.p.c.AbstractCustomizableLifecycleMapping - Mojo execution key: org.apache.maven.plugins:maven-resources-plugin:2.6:testResources (execution: default-testResources, phase: process-test-resources)21:40:43.445 [Worker-37] DEBUG o.e.m.c.p.c.AbstractCustomizableLifecycleMapping - Action: execute21:40:43.445 [Worker-37] DEBUG o.e.m.c.p.c.AbstractCustomizableLifecycleMapping - Mojo execution key: org.apache.maven.plugins:maven-compiler-plugin:2.3.2:testCompile (execution: default-testCompile, phase: test-compile)21:40:43.445 [Worker-37] DEBUG o.e.m.c.p.c.AbstractCustomizableLifecycleMapping - Mojo execution key: org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (execution: default-test, phase: test)21:40:43.445 [Worker-37] DEBUG o.e.m.c.p.c.AbstractCustomizableLifecycleMapping - Mojo execution key: org.apache.maven.plugins:maven-jar-plugin:2.4:jar (execution: default-jar, phase: package)21:40:43.445 [Worker-37] DEBUG o.e.m.c.p.c.AbstractCustomizableLifecycleMapping - Action: configurator21:40:43.445 [Worker-37] DEBUG o.e.m.c.p.c.AbstractCustomizableLifecycleMapping - Project configurator : id=org.sonatype.m2e.mavenarchiver.jararchiverconfigurator class=org.sonatype.m2e.mavenarchiver.internal.JarArchiverConfigurator21:40:43.446 [Worker-37] DEBUG o.e.m.c.p.c.AbstractCustomizableLifecycleMapping - Build participant: org.sonatype.m2e.mavenarchiver.internal.AbstractMavenArchiverConfigurator$121:40:43.446 [Worker-37] DEBUG o.e.m.c.p.c.AbstractCustomizableLifecycleMapping - Mojo execution key: org.apache.maven.plugins:maven-install-plugin:2.4:install (execution: default-install, phase: install)21:40:43.446 [Worker-37] DEBUG o.e.m.c.p.c.AbstractCustomizableLifecycleMapping - Mojo execution key: org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (execution: default-deploy, phase: deploy)21:40:43.446 [Worker-37] DEBUG o.e.m.c.i.builder.MavenBuilderImpl - Executing build participant org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant for plugin execution org.apache.maven.plugins:maven-resources-plugin:2.6:resources (execution: default-resources, phase: process-resources)21:40:43.451 [Worker-37] INFO Âo.e.m.c.i.embedder.EclipseLogger - Using 'UTF-8' encoding to copy filtered resources.21:40:43.452 [Worker-37] INFO Âo.e.m.c.i.embedder.EclipseLogger - Copying 0 resource21:40:43.453 [Worker-37] DEBUG o.e.m.c.i.builder.MavenBuilderImpl - Finished executing build participant org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant for plugin execution org.apache.maven.plugins:maven-resources-plugin:2.6:resources (execution: default-resources, phase: process-resources) in 7 ms21:40:43.453 [Worker-37] DEBUG o.e.m.c.i.builder.MavenBuilderImpl - Executing build participant org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant for plugin execution org.apache.maven.plugins:maven-resources-plugin:2.6:testResources (execution: default-testResources, phase: process-test-resources)21:40:43.456 [Worker-37] INFO Âo.e.m.c.i.embedder.EclipseLogger - Using 'UTF-8' encoding to copy filtered resources.21:40:43.457 [Worker-37] INFO Âo.e.m.c.i.embedder.EclipseLogger - Copying 0 resource21:40:43.457 [Worker-37] DEBUG o.e.m.c.i.builder.MavenBuilderImpl - Finished executing build participant org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant for plugin execution org.apache.maven.plugins:maven-resources-plugin:2.6:testResources (execution: default-testResources, phase: process-test-resources) in 4 ms21:40:43.457 [Worker-37] DEBUG o.e.m.c.i.builder.MavenBuilderImpl - Executing build participant org.sonatype.m2e.mavenarchiver.internal.AbstractMavenArchiverConfigurator$1 for plugin execution org.apache.maven.plugins:maven-jar-plugin:2.4:jar (execution: default-jar, phase: package)21:40:43.457 [Worker-37] DEBUG o.e.m.c.i.builder.MavenBuilderImpl - Finished executing build participant org.sonatype.m2e.mavenarchiver.internal.AbstractMavenArchiverConfigurator$1 for plugin execution org.apache.maven.plugins:maven-jar-plugin:2.4:jar (execution: default-jar, phase: package) in 0 ms21:40:43.458 [Worker-37] DEBUG o.e.m.c.i.builder.MavenBuilder - Built project test1 in 18 msI would be appreciated for any help with explaining how to use m2e api.Thanks in advance,Marek--Marek Jagielski
+48 513 402 596--Marek Jagielski
+48 513 402 596
_______________________________________________
m2e-users mailing list
m2e-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/m2e-users