开发者

Invoking Maven goals inside Mavenplugin

I want to write a maven plugin which executes some specific maven goals on a set of projects.

Currently I have in my plugins pom:

<dependency>
    <groupId>org.apache.maven.shared</groupId>
    <artifactId>maven-invoker</artifactId>
    <version>2.0.11</version>
</dependency>

and in the plugins code

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);

If I ran it on a maven project it fails with

[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)

Can someone tell me why it fails ? And how to achieve my actual goal ?

Thanks for any help


Let me paraphase what I think you're trying to do: You want to ensure that your plugin is run after clean and generate-sources are run, because of dependence on some state.

It's a plugin, and it's called from points within the maven lifecycle.

I think what you need to do create a goal on the 'process-sources' phase, or later. When that goal is run, clean and generate-sources will have already been run.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜