tags:

views:

11

answers:

1

hey, I have a deploy pojo plugin (deploying a war to a remote server). I have the remote-deploy plugin in the build section of pom definition, I need package phase to be triggered before deploy-remote goal, for it the war be already created before I secure-copy it to a remote server.

With the execution elements (according to a documentation), I can attach my goal to a particular phase, for instance bind it to the phase after, so in my case, install phase ...but that's just a workaround.

  <build>
    <plugins>
      <plugin>
        <groupId>sample.plugin</groupId>
        <artifactId>maven-hello-plugin</artifactId>
        <version>1.0-SNAPSHOT</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>sayhi</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

simply put, if I place only my goal into the build section, and run it, package phase is not run before. Please help

+1  A: 

Maven Mojo plugin, how to define phases that must be triggered before this goal ?

You can't.

I have the remote-deploy plugin in the build section of pom definition, I need package phase to be triggered before deploy-remote goal, for it the war be already created before I secure-copy it to a remote server.

Just bind it to the package phase, your goal will be called after the goals bounds to package by default (so the war will be there).

Here is an example demonstrating this behavior with the Maven AntRun plugin configured like this:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version>
    <executions>
      <execution>
        <phase>package</phase>
        <configuration>
          <target>
            <echo message="Hi!!!!!"/>
          </target>
        </configuration>
        <goals>
          <goal>run</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

And the output of mvn package:

$ mvn package
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Q3934833 Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
...
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ Q3934833 ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.5:test (default-test) @ Q3934833 ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-war-plugin:2.1:war (default-war) @ Q3934833 ---
[INFO] Packaging webapp
[INFO] Assembling webapp [Q3934833] in [/home/pascal/Projects/stackoverflow/Q3934833/target/Q3934833]
[INFO] Processing war project
[INFO] Copying webapp resources [/home/pascal/Projects/stackoverflow/Q3934833/src/main/webapp]
[INFO] Webapp assembled in [317 msecs]
[INFO] Building war: /home/pascal/Projects/stackoverflow/Q3934833/target/Q3934833.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] 
[INFO] --- maven-antrun-plugin:1.6:run (default) @ Q3934833 ---
[INFO] Executing tasks

main:
     [echo] Hi!!!!!
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
...

The antrun plugin is executed after package, as expected.

Pascal Thivent
@Pascal Thivent, I tried it this way, and the war was not created. I tried exactly as it is in the example I pasted and I got "war does not exist"
lisak
It works with the install phase, but not with package...but that workaround wouldn't be good, because I'd have to always install the artifact before deployment
lisak
@lisak It just works as advertised. If you get a different behavior, show your configuration and the output demonstrating the problem.
Pascal Thivent
Sorry, I should probably go to sleep :-) I was running "mvn myGoal:myPhase" instead of "mvn package" ... so this is OK finally, thank you
lisak
@lisak No problem, glad we got it sorted out.
Pascal Thivent