You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by motes motes <mo...@gmail.com> on 2011/01/18 17:50:25 UTC

Create a common/shared task for the maven-antrun-plugin ?

In a parent I define some properties that are used in a lot of sub
modules in the maven-antrun-plugin. All these sub modules needs to
execute the exact same tasks so it could be nice to define this task
once in the parent.

But is it possible to define a "global"  maven-antrun task in a parent
that can be optionally used in a sub module?

I have tried to move the maven-antrun-plugin to the parent's
pluginManagement and then define the tasks there. But I have another
sub module that don't need to to run this "global" task. But since its
inherited from the parent I am a bit stuck here.


Is it possible to define only a a task that can be inserted without
having to modify the  maven-antrun-plugin for all sub modules??

Here is how its used in a sub module:

      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.6</version>
        <executions>
          <execution>
            <id>test</id>
            <phase>deploy</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <tasks>
                		<!-- run a bunch of sshexec and scp tasks. Could be
nice if we could do the following: -->
                    <my.task> run special task defined in parent </my.task>


              </tasks>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant-jsch</artifactId>
            <version>${ant.jsch.version}</version>
          </dependency>
        </dependencies>
      </plugin>

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


Re: Create a common/shared task for the maven-antrun-plugin ?

Posted by lukewpatterson <lu...@gmail.com>.
you might consider throwing it in a maven plugin (sounds scary, it isn't)

use groovy's ant dsl to slap it together
http://groovy.codehaus.org/Using+Ant+from+Groovy

i'm using that pattern now to wrap around an ant task, you can take a look
at it if you want:

http://code.google.com/p/indoorsdog/source/browse/jacoco/trunk/jacoco-maven-plugin/src/main/groovy/org/indoorsdog/jacoco/maven/plugin/internal/AgentMojo.groovy
-- 
View this message in context: http://maven.40175.n5.nabble.com/Create-a-common-shared-task-for-the-maven-antrun-plugin-tp3346449p3346458.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: Create a common/shared task for the maven-antrun-plugin ?

Posted by lukewpatterson <lu...@gmail.com>.

morty wrote:
> 
> ... I need to use this "custom" task across different projects. Do you
> suggest that I create a full separate native maven project...

If you want to share build logic across different projects, and especially
if "you code to" (via Ant task markup in your case) the custom logic, the
logic needs to have "coordinates" (groupId, artifactId, version) so you can
reference it.

Yes, the "custom plugin/task" would be a full-blown Maven project.  It would
have its own POM, its own coordinates (groupId, artifactId, version), you
would install/deploy it just like library/consumer jars.  You could make it
a Maven plugin (probably the better choice) or an Ant task.  If you make it
an Ant task, then your consumers would need to route through antrun to use
it.

>From my experience (others may have better ideas), that is really the only
way to go in a case like this.  If the custom logic "codes to you" (put
gmaven or antrun configuration in a parent pom with a bunch of conditionals
to decide what to do), then you can probably get away with not writing a
custom plugin.
-- 
View this message in context: http://maven.40175.n5.nabble.com/Create-a-common-shared-task-for-the-maven-antrun-plugin-tp3346449p3346983.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: Create a common/shared task for the maven-antrun-plugin ?

Posted by lukewpatterson <lu...@gmail.com>.
I'll try to address some of your questions/concerns/suggestions with info on
what I see as practical/supported/reasonable today.  I'll leave the bigger
philosophical and architectural ruminations to those more qualified.  (I
will say though that you might be interested in the "composition versus
inheritance" topic at:
http://www.sonatype.com/people/2009/11/maven-3x-paving-the-desire-lines-part-one-2/)


antrun isn't for creating build logic that _non-inheriting_ poms can use. 
e.g. references like ${project.artifactId} always refer to the
containing/inheriting pom, and are only relevant/resolved/evaluated when the
antrun:run goal is executed on the containing/inheriting pom.  the
antrun:run goal only executes the logic when the containing/inheriting pom
is going through _its_build_process_, not when some other pom depends
(either through <dependency> or <plugin>) on it.

the quickest way to slap together some ant and wrap a maven plugin around it
is to either use 
groovy+antdsl: http://groovy.codehaus.org/Using+Ant+from+Groovy
or
ant-based-plugin:
http://maven.apache.org/guides/plugin/guide-ant-plugin-development.html


I mentioned the groovy+antdsl route because it seems easier and more
powerful to me.  You don't have to manually construct the plugin metadata
file (you have to with direct ant-based plugins) and you can use all your
java/groovy/ant knowledge and capability together in the same source file.
-- 
View this message in context: http://maven.40175.n5.nabble.com/Create-a-common-shared-task-for-the-maven-antrun-plugin-tp3346449p3349900.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: Create a common/shared task for the maven-antrun-plugin ?

Posted by motes motes <mo...@gmail.com>.
Yeah I like the idea about writing my own maven-plugin, its about time
I get around to do that :-) But why add all the complexity of:

http://groovy.codehaus.org/Using+Ant+from+Groovy

http://code.google.com/p/indoorsdog/source/browse/jacoco/trunk/jacoco-maven-plugin/src/main/groovy/org/indoorsdog/jacoco/maven/plugin/internal/AgentMojo.groovy

which was Luke's initial suggestion?

I don't want to modify the ant-run-plugin I just want to execute  a
specific sequence of tasks for the existing implementation of ant-run
and encapsulate this in a plugin that can be used during the build
phase for a bunch of projects.

>From this link:

http://maven.apache.org/guides/plugin/guide-java-plugin-development.html

this basically just boils down to create a pom file with
<packaging>maven-plugin</packaging> and then just add whatever needs
to be done. This "custom" plugin can then be included in another
project.

Here is an example pom file which defines a few tasks:


<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
         <groupId>com.test.maven.plugins</groupId>
	<artifactId>my-maven-plugin</artifactId>
	<version>1.0.0-SNAPSHOT</version>
	<packaging>maven-plugin</packaging>
	<dependencies>
		<dependency>
			<groupId>org.apache.maven</groupId>
			<artifactId>maven-plugin-api</artifactId>
			<version>2.0</version>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<artifactId>maven-antrun-plugin</artifactId>
				<version>1.6</version>
				<executions>
					<execution>
						<id>test</id>
						<phase>deploy</phase>
						<goals>
							<goal>run</goal>
						</goals>
						<configuration>
							<tasks>

								<!-- run task A, B and C-->
							</tasks>
						</configuration>
					</execution>
				</executions>
				<dependencies>
					<dependency>
						<groupId>org.apache.ant</groupId>
						<artifactId>ant-jsch</artifactId>
						<version>1.8.1</version>
					</dependency>
				</dependencies>
			</plugin>
		</plugins>
	</build>
</project>


Then in another project I just add the above plugin to the build phase:


...
  <build>
    <plugins>
			<plugin>
				<groupId>com.test.maven.plugins</groupId>
				<artifactId>my-maven-plugin</artifactId>
				<version>1.0.0-SNAPSHOT</version>
			</plugin>
    </plugins>
  </build>




Unfortunately the "my-maven-plugin" never gets executed when the
project using the plugin is deployed. Any suggestion why this simple
approach does not work?






On Tue, Jan 18, 2011 at 11:47 PM, Wayne Fay <wa...@gmail.com> wrote:
>> But I need to use this "custom" task across different projects. Do you
>> suggest that I create a full separate native maven project where one
>
> In that case... I like Luke's initial suggestion of turning this into
> a plugin even more.
>
> Wayne
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

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


Re: Create a common/shared task for the maven-antrun-plugin ?

Posted by Wayne Fay <wa...@gmail.com>.
> But I need to use this "custom" task across different projects. Do you
> suggest that I create a full separate native maven project where one

In that case... I like Luke's initial suggestion of turning this into
a plugin even more.

Wayne

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


Re: Create a common/shared task for the maven-antrun-plugin ?

Posted by motes motes <mo...@gmail.com>.
But I need to use this "custom" task across different projects. Do you
suggest that I create a full separate native maven project where one
of the sub modules specifies the custom task and then use this module
as a dependency in the other projects?



On Tue, Jan 18, 2011 at 10:36 PM, lukewpatterson
<lu...@gmail.com> wrote:
>
> if one of your modules _is_ the custom ant task (one of the modules is a
> maven project that codes to ant api and contains the ant task), then you can
> do this:
>
>      <plugin>
>        <artifactId>maven-antrun-plugin</artifactId>
>        <executions>
>          <execution>
>            ...
>            <configuration>
>              <tasks>
>                    <my.task> run special task defined in another
> module</my.task>
>              </tasks>
>            </configuration>
>          </execution>
>        </executions>
>        <dependencies>
>          <dependency>
>            <groupId>my.groupId</groupId>
>            <artifactId>my-ant-task-project</artifactId>
>          </dependency>
>        </dependencies>
>      </plugin>
>
> the only thing I would wonder about is if the reactor inter-dependency logic
> can correctly "see" that the "my-ant-task-project" needs to be built before
> its consumers
> --
> View this message in context: http://maven.40175.n5.nabble.com/Create-a-common-shared-task-for-the-maven-antrun-plugin-tp3346449p3346860.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
>
>

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


Re: Create a common/shared task for the maven-antrun-plugin ?

Posted by lukewpatterson <lu...@gmail.com>.
if one of your modules _is_ the custom ant task (one of the modules is a
maven project that codes to ant api and contains the ant task), then you can
do this:

      <plugin> 
        <artifactId>maven-antrun-plugin</artifactId> 
        <executions>
          <execution>
            ...
            <configuration> 
              <tasks> 
                    <my.task> run special task defined in another
module</my.task> 
              </tasks> 
            </configuration> 
          </execution> 
        </executions> 
        <dependencies> 
          <dependency> 
            <groupId>my.groupId</groupId> 
            <artifactId>my-ant-task-project</artifactId> 
          </dependency> 
        </dependencies> 
      </plugin> 

the only thing I would wonder about is if the reactor inter-dependency logic
can correctly "see" that the "my-ant-task-project" needs to be built before
its consumers
-- 
View this message in context: http://maven.40175.n5.nabble.com/Create-a-common-shared-task-for-the-maven-antrun-plugin-tp3346449p3346860.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