English 中文(简体)
Maven-deploy-plugin中多个执行的Maven错误
原标题:
  • 时间:2009-03-16 11:00:02
  •  标签:

我找到了这个好方法,想要用它来部署一些第三方文件到我们的仓库中。

命令行中的呼叫为

mvn -P deploy-libs

如果我对一个文件这样做,它会按预期完成。

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

如果我使用一个带有多个执行的执行块,它就不起作用。这是一个错误还是预期行为?

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

我得到的错误是:

[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

有什么想法吗?

问题回答

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 Nexus and upload them once to a repository for your whole team to use.

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

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.

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.

To do all the deploys at once (as described by Boris) you can add:

<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

Of cource it s a bug. Maven plugin is not supposed to work in this way.





相关问题
热门标签