You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by "izak.wessels" <iz...@gmail.com> on 2010/03/18 12:38:36 UTC

How to Invoke different goals of 1 plugin

Hi, 

We would like to invoke different goals on 1 plugin. 

>From reading the documentation, it seems that the best way to achieve this
is to setup a profile and specify the same plugin but with a different goal. 

Here is the 1st time that the plugin is defined in the pom.xml. Take note of
the goal in this scenario 'check' (This should execute by default) 

<build>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-pmd-plugin</artifactId>
    <version>2.4</version>
    <executions>
      <execution>
        <phase>generate-sources</phase>
        <goals>
          <goal>check</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
</plugins>
</build>

And now for the profile, the goal in this case is 'pmd' : 

<profiles>
<profile>
  <id>sonar</id>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-pmd-plugin</artifactId>
        <version>2.4</version>
        <executions>
          <execution>
            <phase>generate-sources</phase>
            <goals>
              <goal>pmd</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</profile>
</profiles>

(Side note : We have to execute it during the generate-sources phase as we
have other plugins that alters the source and any other phase is too late
for this plugin in our environment)

However, this approach seems to ONLY be valid for the top level. Once it
decends into the child projects, then it seems to merge the goals, 'check'
first & 'pmd' thereafter (which doesn't seem to work correctly - see
http://jira.codehaus.org/browse/MNG-4022). The documentation does mention
that stuff will be merged but it fails to mention a.) is it possible to get
around it? and b.) if it is possible, how would one go about it.

We had a look into execution id's as well, but it seems that they are only
bound to a lifecycle and cannot be used in our scenario. 

Any help would be much appreciated, 

-- izak









-- 
View this message in context: http://n2.nabble.com/How-to-Invoke-different-goals-of-1-plugin-tp4755892p4755892.html
Sent from the maven users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to Invoke different goals of 1 plugin

Posted by "izak.wessels" <iz...@gmail.com>.
We still want the plugin to be inherited by the child projects. 

But thanks for the clarification on the syntax. 
-----Original Message-----
From: "stephenconnolly [via maven users]" <ml...@n2.nabble.com>
Date: Thu, 18 Mar 2010 04:16:17 
To: izak.wessels<iz...@gmail.com>
Subject: Re: How to Invoke different goals of 1 plugin




  <build>
    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.1</version>
        <executions>
          <execution>
            <id>echodir</id>
            <goals>
              <goal>run</goal>
            </goals>
            <phase>verify</phase>
*            <inherited>false</inherited>*   <!-- this is the
inherited you want -->
            <configuration>
              <tasks>
                <echo>Build Dir: ${project.build.directory}</echo>
              </tasks>
            </configuration>
          </execution>
        </executions>

      </plugin>
    </plugins>
  </build>



On 18 March 2010 11:59, izak.wessels <iz...@gmail.com> wrote:

>
>
> stephenconnolly wrote:
> >
> > give each execution a different <id>
> >
> > and if you don;t want something inherited by child projects, set
> > <inherited>false
> >
>
> Yup, we tried that.
>
> Example :
>
> <build>
> <plugins>
>  <plugin>
>    <groupId>org.apache.maven.plugins</groupId>
>    <artifactId>maven-pmd-plugin</artifactId>
>    <version>2.4</version>
>    <executions>
>      <execution>
>         <id>pmd-default</id>
>         <phase>generate-sources</phase>
>        <goals>
>          <goal>check</goal>
>        </goals>
>      </execution>
>       <execution>
>        <id>pmd-sonar</id>
>         <phase>generate-sources</phase>
>        <goals>
>          <goal>pmd</goal>
>        </goals>
>      </execution>
>    </executions>
>  </plugin>
> </plugins>
> </build>
>
> 2 issues with that approach:
>
>
> 1. How do we tell maven which execution we want to run?
>

You don't

It will run all the executions that are bound to the lifecycle automatically

If you want something different, use ANT, or hack away using profiles and
activation rules and then spend ages explainging to people why even though
you have used a build tool which has a standard lifecycle, you are ignoring
that and ending up back in the "what ant task do I run to do ___" mire


>
> 2. From what we understand you cannot just say <inherited>false</inherited>
> in the child pom.xml, you would have to do something like,
>
> <plugin>
>  <groupId>org.apache.maven.plugins</groupId>
>  <artifactId>maven-pmd-plugin</artifactId>
>  <inherited>false</inherited>
> </plugin>
>
> However, we still want our plugin to run in our child projects, just run
> against a different goal based on question 1
>
> --
> View this message in context:
> http://n2.nabble.com/How-to-Invoke-different-goals-of-1-plugin-tp4755892p4755993.html
> Sent from the maven users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


______________________________________
View message @ http://n2.nabble.com/How-to-Invoke-different-goals-of-1-plugin-tp4755892p4756077.html

To unsubscribe from Re: How to Invoke different goals of 1 plugin, click  (link removed) =


-- 
View this message in context: http://n2.nabble.com/How-to-Invoke-different-goals-of-1-plugin-tp4755892p4756104.html
Sent from the maven users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to Invoke different goals of 1 plugin

Posted by Stephen Connolly <st...@gmail.com>.
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.1</version>
        <executions>
          <execution>
            <id>echodir</id>
            <goals>
              <goal>run</goal>
            </goals>
            <phase>verify</phase>
*            <inherited>false</inherited>*   <!-- this is the
inherited you want -->
            <configuration>
              <tasks>
                <echo>Build Dir: ${project.build.directory}</echo>
              </tasks>
            </configuration>
          </execution>
        </executions>

      </plugin>
    </plugins>
  </build>



On 18 March 2010 11:59, izak.wessels <iz...@gmail.com> wrote:

>
>
> stephenconnolly wrote:
> >
> > give each execution a different <id>
> >
> > and if you don;t want something inherited by child projects, set
> > <inherited>false
> >
>
> Yup, we tried that.
>
> Example :
>
> <build>
> <plugins>
>  <plugin>
>    <groupId>org.apache.maven.plugins</groupId>
>    <artifactId>maven-pmd-plugin</artifactId>
>    <version>2.4</version>
>    <executions>
>      <execution>
>         <id>pmd-default</id>
>         <phase>generate-sources</phase>
>        <goals>
>          <goal>check</goal>
>        </goals>
>      </execution>
>       <execution>
>        <id>pmd-sonar</id>
>         <phase>generate-sources</phase>
>        <goals>
>          <goal>pmd</goal>
>        </goals>
>      </execution>
>    </executions>
>  </plugin>
> </plugins>
> </build>
>
> 2 issues with that approach:
>
>
> 1. How do we tell maven which execution we want to run?
>

You don't

It will run all the executions that are bound to the lifecycle automatically

If you want something different, use ANT, or hack away using profiles and
activation rules and then spend ages explainging to people why even though
you have used a build tool which has a standard lifecycle, you are ignoring
that and ending up back in the "what ant task do I run to do ___" mire


>
> 2. From what we understand you cannot just say <inherited>false</inherited>
> in the child pom.xml, you would have to do something like,
>
> <plugin>
>  <groupId>org.apache.maven.plugins</groupId>
>  <artifactId>maven-pmd-plugin</artifactId>
>  <inherited>false</inherited>
> </plugin>
>
> However, we still want our plugin to run in our child projects, just run
> against a different goal based on question 1
>
> --
> View this message in context:
> http://n2.nabble.com/How-to-Invoke-different-goals-of-1-plugin-tp4755892p4755993.html
> Sent from the maven users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: How to Invoke different goals of 1 plugin

Posted by "izak.wessels" <iz...@gmail.com>.

stephenconnolly wrote:
> 
> give each execution a different <id>
> 
> and if you don;t want something inherited by child projects, set
> <inherited>false
> 

Yup, we tried that. 

Example : 

<build>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-pmd-plugin</artifactId>
    <version>2.4</version>
    <executions>
      <execution>
        <id>pmd-default</id>
        <phase>generate-sources</phase>
        <goals>
          <goal>check</goal>
        </goals>
      </execution>
      <execution>
        <id>pmd-sonar</id>
        <phase>generate-sources</phase>
        <goals>
          <goal>pmd</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
</plugins>
</build>

2 issues with that approach: 


1. How do we tell maven which execution we want to run?

2. From what we understand you cannot just say <inherited>false</inherited>
in the child pom.xml, you would have to do something like, 

<plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-pmd-plugin</artifactId>
 <inherited>false</inherited>
</plugin>

However, we still want our plugin to run in our child projects, just run
against a different goal based on question 1

-- 
View this message in context: http://n2.nabble.com/How-to-Invoke-different-goals-of-1-plugin-tp4755892p4755993.html
Sent from the maven users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to Invoke different goals of 1 plugin

Posted by Stephen Connolly <st...@gmail.com>.
give each execution a different <id>

and if you don;t want something inherited by child projects, set
<inherited>false

On 18 March 2010 11:38, izak.wessels <iz...@gmail.com> wrote:

>
> Hi,
>
> We would like to invoke different goals on 1 plugin.
>
> From reading the documentation, it seems that the best way to achieve this
> is to setup a profile and specify the same plugin but with a different
> goal.
>
> Here is the 1st time that the plugin is defined in the pom.xml. Take note
> of
> the goal in this scenario 'check' (This should execute by default)
>
> <build>
> <plugins>
>  <plugin>
>    <groupId>org.apache.maven.plugins</groupId>
>    <artifactId>maven-pmd-plugin</artifactId>
>    <version>2.4</version>
>    <executions>
>      <execution>
>        <phase>generate-sources</phase>
>        <goals>
>          <goal>check</goal>
>        </goals>
>      </execution>
>    </executions>
>  </plugin>
> </plugins>
> </build>
>
> And now for the profile, the goal in this case is 'pmd' :
>
> <profiles>
> <profile>
>  <id>sonar</id>
>  <build>
>    <plugins>
>      <plugin>
>        <groupId>org.apache.maven.plugins</groupId>
>        <artifactId>maven-pmd-plugin</artifactId>
>        <version>2.4</version>
>        <executions>
>          <execution>
>            <phase>generate-sources</phase>
>            <goals>
>              <goal>pmd</goal>
>            </goals>
>          </execution>
>        </executions>
>      </plugin>
>    </plugins>
>  </build>
> </profile>
> </profiles>
>
> (Side note : We have to execute it during the generate-sources phase as we
> have other plugins that alters the source and any other phase is too late
> for this plugin in our environment)
>
> However, this approach seems to ONLY be valid for the top level. Once it
> decends into the child projects, then it seems to merge the goals, 'check'
> first & 'pmd' thereafter (which doesn't seem to work correctly - see
> http://jira.codehaus.org/browse/MNG-4022). The documentation does mention
> that stuff will be merged but it fails to mention a.) is it possible to get
> around it? and b.) if it is possible, how would one go about it.
>
> We had a look into execution id's as well, but it seems that they are only
> bound to a lifecycle and cannot be used in our scenario.
>
> Any help would be much appreciated,
>
> -- izak
>
>
>
>
>
>
>
>
>
> --
> View this message in context:
> http://n2.nabble.com/How-to-Invoke-different-goals-of-1-plugin-tp4755892p4755892.html
> Sent from the maven users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>