java 在 maven-deploy-plugin 中多次执行的 Maven 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/649955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven error with multiple executions in maven-deploy-plugin
提问by Mauli
I found this nice recipeand want to use it to deploy some 3rd-party files in our repository
我发现了这个不错的秘籍,并想用它在我们的存储库中部署一些 3rd-party 文件
The call on the command line is
命令行上的调用是
mvn -P deploy-libs
If I do this for onefile it works exactly as intended
如果我为一个文件执行此操作,它会完全按预期工作
<profiles>
<profile>
<id>deploy-libs</id>
<build>
<defaultGoal>deploy:deploy-file</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.4</version>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<repositoryId>openscada-external</repositoryId>
<url>${openscada.distrib.repository}</url>
<file>../openscada_opc_dcom/lib/j-interop.jar</file>
<pomFile>../openscada_opc_dcom/lib/j-interop.pom</pomFile>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
If I use an execution block with multiple executions, it doesn't work. Is this a bug, or is this intended behavior?
如果我使用具有多次执行的执行块,则它不起作用。这是一个错误,还是这是预期的行为?
<profiles>
<profile>
<id>deploy-libs</id>
<build>
<defaultGoal>deploy:deploy-file</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.4</version>
<configuration>
<repositoryId>openscada-external</repositoryId>
<url>${openscada.distrib.repository}</url>
</configuration>
<executions>
<execution>
<id>j-interop</id>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<file>../openscada_opc_dcom/lib/j-interop.jar</file>
<pomFile>../openscada_opc_dcom/lib/j-interop.pom</pomFile>
</configuration>
</execution>
<execution>
<id>j-interopdeps</id>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<file>../openscada_opc_dcom/lib/j-interopdeps.jar</file>
<pomFile>../openscada_opc_dcom/lib/j-interopdeps.pom</pomFile>
</configuration>
</execution>
<execution>
<id>jcifs</id>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<file>../openscada_opc_dcom/lib/jcifs-1.2.9.jar</file>
<pomFile>../openscada_opc_dcom/lib/jcifs-1.2.9.pom</pomFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
The error I get is:
我得到的错误是:
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] One or more required plugin parameters are invalid/missing for 'deploy:deploy-file'
[0] Inside the definition for plugin 'maven-deploy-plugin' specify the following:
<configuration>
...
<file>VALUE</file>
</configuration>
-OR-
on the command line, specify: '-Dfile=VALUE'
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Error configuring: org.apache.maven.plugins:maven-deploy-plugin. Reason: Invalid or missing parameters: [Mojo parameter [name: 'file'; alias: 'null']] for mojo: org.apache.maven.plugins:maven-deploy-plugin:2.4:deploy-file
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:587)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:512)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:482)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:330)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:227)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:142)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:287)
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)
Caused by: org.apache.maven.plugin.PluginParameterException: Error configuring: org.apache.maven.plugins:maven-deploy-plugin. Reason: Invalid or missing parameters: [Mojo parameter [name: 'file'; alias: 'null']] for mojo: org.apache.maven.plugins:maven-deploy-plugin:2.4:deploy-file
at org.apache.maven.plugin.DefaultPluginManager.checkRequiredParameters(DefaultPluginManager.java:1042)
at org.apache.maven.plugin.DefaultPluginManager.getConfiguredMojo(DefaultPluginManager.java:659)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:429)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:558)
... 16 more
Any ideas?
有任何想法吗?
回答by Brian Fox
The reason why this happens is that when a plugin is invoked from the command line like you've done, it has no phase or execution associated with it. This means it picks up the unnamed execution configuration, which is the config outside the execution block.
发生这种情况的原因是,当像您一样从命令行调用插件时,它没有与之关联的阶段或执行。这意味着它会选择未命名的执行配置,即执行块之外的配置。
If you really want to run multiple executions, bind them to a phase and then invoke that phase. In this case each execution will run with its own configuration.
如果您真的想运行多个执行,请将它们绑定到一个阶段,然后调用该阶段。在这种情况下,每个执行都将以其自己的配置运行。
The real unasked question here is why you are using deploy-file to deploy a bunch of stuff like this? If it's 3rd party stuff, you should get a repo manager like Nexusand upload them once to a repository for your whole team to use.
这里真正没有问到的问题是为什么要使用 deploy-file 来部署一堆这样的东西?如果是 3rd 方的东西,你应该找一个像Nexus这样的仓库管理器,然后把它们上传到一个仓库,供你的整个团队使用。
回答by Steven Christenson
To do all the deploys at once (as described by Boris) you can add:
要一次完成所有部署(如 Boris 所述),您可以添加:
<profile>
<profiles>
<id>MyId1</id>
<activation><property>DeployAll</property></activation>
...
</profiles>
<profile>
<id>MyId2</id>
<activation><property>DeployAll</property></activation>
...
<profile>
<profiles>
<id>MyId1</id>
<activation><property>DeployAll</property></activation>
...
</profiles>
<profile>
<id>MyId2</id>
<activation> <property>DeployAll</property></activation>
...
And then use
然后使用
mvn -DDeployAll
mvn -DDeployAll
回答by eugcomax
Of cource it's a bug. Maven plugin is not supposed to work in this way.
这当然是一个错误。Maven 插件不应该以这种方式工作。
回答by Boris Pavlovi?
This is a bit verbose but may help:
这有点冗长,但可能会有所帮助:
<profiles>
<profile>
<id>deploy-j-interop</id>
<build>
<defaultGoal>deploy:deploy-file</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.4</version>
<configuration>
<repositoryId>openscada-external</repositoryId>
<url>${openscada.distrib.repository}</url>
</configuration>
<executions>
<execution>
<id>j-interop</id>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<file>../openscada_opc_dcom/lib/j-interop.jar</file>
<pomFile>../openscada_opc_dcom/lib/j-interop.pom</pomFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>deploy-j-interopdeps</id>
<build>
<defaultGoal>deploy:deploy-file</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.4</version>
<configuration>
<repositoryId>openscada-external</repositoryId>
<url>${openscada.distrib.repository}</url>
</configuration>
<executions>
<execution>
<id>j-interopdeps</id>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<file>../openscada_opc_dcom/lib/j-interopdeps.jar</file>
<pomFile>../openscada_opc_dcom/lib/j-interopdeps.pom</pomFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>deploy-jcifs</id>
<build>
<defaultGoal>deploy:deploy-file</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.4</version>
<configuration>
<repositoryId>openscada-external</repositoryId>
<url>${openscada.distrib.repository}</url>
</configuration>
<executions>
<execution>
<id>jcifs</id>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<file>../openscada_opc_dcom/lib/jcifs-1.2.9.jar</file>
<pomFile>../openscada_opc_dcom/lib/jcifs-1.2.9.pom</pomFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
You would run it using the command:
您将使用以下命令运行它:
mvn -P deploy-j-interop deploy-j-interopdeps deploy-jcifs
回答by siddhadev
I guess maven tries to also execute the default execution, where <file>is not specified.
It's usually a good idea to configure the plugins in pluginManagement, and explicitly bind the the different executions to specific phases.
我猜 maven 也尝试执行默认执行,其中<file>未指定。在 pluginManagement 中配置插件通常是一个好主意,并将不同的执行明确绑定到特定阶段。
Try to put an explicit '' and '' elements in the default plugin configuration. You can put garbage inside, to see if the default execution get executed, and if it does, make one of the executions a default.
尝试在默认插件配置中放置一个明确的 '' 和 '' 元素。您可以将垃圾放入其中,以查看是否执行了默认执行,如果执行了,则将其中一个执行设为默认执行。

