2011-02-14 46 views
2

我想寫一個Maven插件,它在一組項目上執行一些特定的Maven目標。在Mavenplugin中調用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) 

燦有人告訴我爲什麼失敗?以及如何實現我的實際目標?

感謝所有幫助

回答

1

讓我倒相什麼,我認爲你正在試圖做的:你要確保你的插件後,清潔運行,併產生-源運行,因爲在一些國家的依賴。

它是一個插件,它從maven生命週期中的點調用。

我認爲您需要做的是在'流程來源'階段或以後創建一個目標。當這個目標運行時,clean和generate-sources將已經運行。