我想编写一个maven插件,在一组项目中执行一些特定的maven目标。
目前我的插件是pom:
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-invoker</artifactId>
<version>2.0.11</version>
</dependency>
并在插件代码中
InvocationRequest request = new DefaultInvocationRequest();
request.setBaseDirectory(file.getParentFile());
request.setGoals(newArrayList("clean", "generate-sources"));
request.setPomFile(file);
Inoker invoker = new DefaultInvoker();
InvocationResult execute = invoker.execute(request);
如果我在maven项目上运行它,则
失败[FATAL ERROR] de.test.builder.MyBuilder#execute() caused a linkage error (java.lang.NoSuchMethodError) and may be out-of-date. Check the realms:
[FATAL ERROR] Plugin realm = app0.child-container[de.test.plugins:maven-builder-plugin:0.1-SNAPSHOT]
urls[0] = file:/C:/Dokumente und Einstellungen/user/.m2/repository/de/test/plugins/maven-builder-plugin/0.1-SNAPSHOT/maven-builder-plugin-
.1-SNAPSHOT.jar
urls[1] = file:/C:/Dokumente und Einstellungen/user/.m2/repository/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar
urls[2] = file:/C:/Dokumente und Einstellungen/user/.m2/repository/org/apache/maven/shared/maven-invoker/2.0.11/maven-invoker-2.0.11.jar
urls[3] = file:/C:/Dokumente und Einstellungen/user/.m2/repository/com/google/collections/google-collections/1.0/google-collections-1.0.jar
[FATAL ERROR] Container realm = plexus.core
urls[0] = file:/d:/development/build-tools/apache-maven-2.2.1/lib/maven-2.2.1-uber.jar
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] org.codehaus.plexus.util.cli.Commandline.createArg()Lorg/codehaus/plexus/util/cli/Arg;
[INFO] ------------------------------------------------------------------------
[INFO] Trace
java.lang.NoSuchMethodError: org.codehaus.plexus.util.cli.Commandline.createArg()Lorg/codehaus/plexus/util/cli/Arg;
at org.apache.maven.shared.invoker.MavenCommandLineBuilder.setFlags(MavenCommandLineBuilder.java:407)
at org.apache.maven.shared.invoker.MavenCommandLineBuilder.build(MavenCommandLineBuilder.java:83)
at org.apache.maven.shared.invoker.DefaultInvoker.execute(DefaultInvoker.java:91)
at de.test.builder.Builder.execute(Builder.java:46)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
有人能告诉我它失败的原因吗?以及如何实现我的实际目标?
感谢您的帮助
答案 0 :(得分:1)
让我了解一下我认为您正在尝试做的事情:您希望确保在清理和生成源运行后运行插件,因为依赖某些状态。
这是一个插件,它是从maven生命周期内的点调用的。
我认为您需要做的是在“流程源”阶段或之后创建目标。运行该目标时,已经运行了clean和generate-sources。