You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Martin Monsorno <mo...@gmx.de> on 2008/03/05 14:02:26 UTC

Extending maven to accomplish some tasks

Hi *,

there's one point I do not understand with maven: how can I use it to accomplish some tasks that doesn't seem to fit into the standard phases.  The question arised when implementing continuous integration.  For this I want to

- Copy a artefact to another directory.  (more precisely: to deploy the generated war-file to the app server)  This is no job for deploying something to a maven repository or generating a site, but just a plain copy task.

- Call a special goal of a subproject.  (more precisely: my db subproject uses the hibernate-tools-plugin to execute some sql on the database)  The subproject includes a plugin for a specific task, but I want to call this from the major build)

With maven 1.x, I wrote a maven.xml and defined goals for this.  But what is the maven 2 way?  Must I write a plugin?

Thanks for your thoughts,

Martin.

-- 
Martin


GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen!
Jetzt dabei sein: http://www.shortview.de/?mc=sv_ext_mf@gmx

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


Re: Extending maven to accomplish some tasks

Posted by VUB Stefan Seidel <ss...@vub.de>.
Tomasz Pik wrote:
> On 3/6/08, VUB Stefan Seidel <ss...@vub.de> wrote:
>> Tomasz Pik wrote:
>>  > On 3/6/08, VUB Stefan Seidel <ss...@vub.de> wrote:
>>
>>>>             <phase>install</phase>
>>  >
>>  > Is there a way to setup it so maven will 'copy' artifact
>>  > in 'package' phase, without installing artifact to local repo?
>>  >
>>
>> <phase>package</phase>?
>>  Maybe even <phase>verify</phase>.
>>  Then run "mvn package".
> 
> nop :(
> If this is being bind to 'package', then maven:
> 1. builds and package project into 'target/...'
> 2. use dependency mechanism to locate artifact
>   defined in configuration for plugin through repositories
>   (both local and remote) and copy one  from repository,
>   not the new one.
> Should I report it as a feature request?

Ah. Yes, this is correct behaviour, but not very helpful.

Then you can use the outputDirectory option of the jar plugin (or war 
plugin) in a second execution of the plugin to build the file agaijn 
into the directory you need.

Stefan

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


Re: Extending maven to accomplish some tasks

Posted by Tomasz Pik <to...@gmail.com>.
On 3/6/08, VUB Stefan Seidel <ss...@vub.de> wrote:
> Tomasz Pik wrote:
>  > On 3/6/08, VUB Stefan Seidel <ss...@vub.de> wrote:
>
> >>             <phase>install</phase>
>  >
>  > Is there a way to setup it so maven will 'copy' artifact
>  > in 'package' phase, without installing artifact to local repo?
>  >
>
> <phase>package</phase>?
>  Maybe even <phase>verify</phase>.
>  Then run "mvn package".

nop :(
If this is being bind to 'package', then maven:
1. builds and package project into 'target/...'
2. use dependency mechanism to locate artifact
  defined in configuration for plugin through repositories
  (both local and remote) and copy one  from repository,
  not the new one.
Should I report it as a feature request?

Regards,
Tomek

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


Re: Extending maven to accomplish some tasks

Posted by VUB Stefan Seidel <ss...@vub.de>.
Tomasz Pik wrote:
> On 3/6/08, VUB Stefan Seidel <ss...@vub.de> wrote:
>>             <phase>install</phase>
> 
> Is there a way to setup it so maven will 'copy' artifact
> in 'package' phase, without installing artifact to local repo?
> 
<phase>package</phase>?
Maybe even <phase>verify</phase>.
Then run "mvn package".

Stefan

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


Re: Extending maven to accomplish some tasks

Posted by Tomasz Pik <to...@gmail.com>.
On 3/6/08, VUB Stefan Seidel <ss...@vub.de> wrote:
> Ah, the universal antrun solution. Guys, maven is better than ant, why
>  do you keep using ant?
>
>  For copying the built file use dependency plugin:
>   <build>
>     <plugins>
>       <plugin>
>         <groupId>org.apache.maven.plugins</groupId>
>         <artifactId>maven-dependency-plugin</artifactId>
>         <executions>
>           <execution>
>             <id>copy-installed</id>
>             <phase>install</phase>

Is there a way to setup it so maven will 'copy' artifact
in 'package' phase, without installing artifact to local repo?

Thanks,
Tomek

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


Re: Extending maven to accomplish some tasks

Posted by VUB Stefan Seidel <ss...@vub.de>.
Ian Hummel wrote:
> Fair enough...
> 
> I had never heard of the maven-invoker-plugin.  How about for the first 
> part of his question?  Which plug to use for copying a directory?
http://maven.apache.org/plugins/maven-invoker-plugin/

As I understood the first question, it was about copying the artifact 
into a directory, which is what the dependency plugin does.

A whole directory may also be copied with the resources plugin, although 
if it is really about external files copies to an external location, the 
ant task is not too wrong there.

For copying external resources for inclusion into the artifact, there is 
another plugin.

See http://maven.apache.org/plugins/ for a good start, and also 
http://mojo.codehaus.org/plugins.html.

Stefan


-- 
best regards,

Stefan Seidel
software developer
________________________
VUB Printmedia GmbH
Chopinstraße 4
D-04103 Leipzig
Germany
tel.    +49 (341) 9 60 50 07
fax.    +49 (341) 9 60 50 92
mail.   sseidel@vub.de
web.    www.vub.de

HRB Köln 24015
UStID DE 122 649 251
GF Dr. Achim Preuss Neudorf,
Dr. Christian Preuss Neudorf

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


Re: Extending maven to accomplish some tasks

Posted by Ian Hummel <hu...@parityinc.net>.
Fair enough...

I had never heard of the maven-invoker-plugin.  How about for the  
first part of his question?  Which plug to use for copying a directory?

- ian.


On Mar 6, 2008, at 9:17 AM, VUB Stefan Seidel wrote:

> Ah, the universal antrun solution. Guys, maven is better than ant, why
> do you keep using ant?
>
> For copying the built file use dependency plugin:
>  <build>
>    <plugins>
>      <plugin>
>        <groupId>org.apache.maven.plugins</groupId>
>        <artifactId>maven-dependency-plugin</artifactId>
>        <executions>
>          <execution>
>            <id>copy-installed</id>
>            <phase>install</phase>
>            <goals>
>              <goal>copy</goal>
>            </goals>
>            <configuration>
>              <overWriteReleases>true</overWriteReleases>
>              <overWriteSnapshots>true</overWriteSnapshots>
>              <stripVersion>true</stripVersion>
>              <artifactItems>
>                <artifactItem>
>                  <groupId>${project.groupId}</groupId>
>                  <artifactId>${project.artifactId}</artifactId>
>                  <version>${project.version}</version>
>                  <type>${project.packaging}</type>
>                </artifactItem>
>              </artifactItems>
>
> <outputDirectory>/home/stefan/jboss/server/default/deploy</ 
> outputDirectory>
>            </configuration>
>          </execution>
>        </executions>
>      </plugin>
>    </plugins>
>  </build>
>
> To invoke things from other poms, use maven-invoker-plugin.
>
> Regards,
>
> Stefan
>
>
> Ian Hummel wrote:
>> I use the antrun-maven-plugin to do things like this.  I'm not sure  
>> if
>> that's the right way though!
>>
>> In your specific case you could try
>>
>>
>>    <build>
>>        ...
>>      <plugin>
>>        <artifactId>maven-antrun-plugin</artifactId>
>>        <executions>
>>        <!-- bind to the "install" phase of the default lifecycle -->
>>          <execution>
>>            <phase>install</phase>
>>            <goals>
>>              <goal>run</goal>
>>            </goals>
>>            <configuration>
>>              <tasks>
>>                <copy todir="${todir}">
>>                  <fileset dir="${fromdir}" />
>>                </copy>
>>              </tasks>
>>            </configuration>
>>          </execution>
>>          <execution>
>>        <!-- not sure in which phase you want to execute your sql
>> command -->
>>            <phase>???</phase>
>>            <goals>
>>              <goal>run</goal>
>>            </goals>
>>            <configuration>
>>              <tasks>
>>                <!-- ant task to call subproject... -->
>>              </tasks>
>>            </configuration>
>>          </execution>
>>        </executions>
>>      </plugin>
>>    ...
>> </build>
>>
>>
>> here is some more info on lifecycles/phases:
>> http://docs.codehaus.org/display/MAVENUSER/introduction-to-the-lifecycle
>>
>>
>>
>> On Mar 5, 2008, at 8:02 AM, Martin Monsorno wrote:
>>
>>> Hi *,
>>>
>>> there's one point I do not understand with maven: how can I use it  
>>> to
>>> accomplish some tasks that doesn't seem to fit into the standard
>>> phases.  The question arised when implementing continuous
>>> integration.  For this I want to
>>>
>>> - Copy a artefact to another directory.  (more precisely: to deploy
>>> the generated war-file to the app server)  This is no job for
>>> deploying something to a maven repository or generating a site, but
>>> just a plain copy task.
>>>
>>> - Call a special goal of a subproject.  (more precisely: my db
>>> subproject uses the hibernate-tools-plugin to execute some sql on  
>>> the
>>> database)  The subproject includes a plugin for a specific task,  
>>> but I
>>> want to call this from the major build)
>>>
>>> With maven 1.x, I wrote a maven.xml and defined goals for this.  But
>>> what is the maven 2 way?  Must I write a plugin?
>>>
>>> Thanks for your thoughts,
>>>
>>> Martin.
>>>
>>> --
>>> Martin
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> 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
>


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


Re: Extending maven to accomplish some tasks

Posted by VUB Stefan Seidel <ss...@vub.de>.
Ah, the universal antrun solution. Guys, maven is better than ant, why 
do you keep using ant?

For copying the built file use dependency plugin:
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-installed</id>
            <phase>install</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <overWriteReleases>true</overWriteReleases>
              <overWriteSnapshots>true</overWriteSnapshots>
              <stripVersion>true</stripVersion>
              <artifactItems>
                <artifactItem>
                  <groupId>${project.groupId}</groupId>
                  <artifactId>${project.artifactId}</artifactId>
                  <version>${project.version}</version>
                  <type>${project.packaging}</type>
                </artifactItem>
              </artifactItems>
 
<outputDirectory>/home/stefan/jboss/server/default/deploy</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

To invoke things from other poms, use maven-invoker-plugin.

Regards,

Stefan


Ian Hummel wrote:
> I use the antrun-maven-plugin to do things like this.  I'm not sure if 
> that's the right way though!
> 
> In your specific case you could try
> 
> 
>     <build>
>         ...
>       <plugin>
>         <artifactId>maven-antrun-plugin</artifactId>
>         <executions>
>         <!-- bind to the "install" phase of the default lifecycle -->
>           <execution>
>             <phase>install</phase>
>             <goals>
>               <goal>run</goal>
>             </goals>
>             <configuration>
>               <tasks>
>                 <copy todir="${todir}">
>                   <fileset dir="${fromdir}" />
>                 </copy>
>               </tasks>
>             </configuration>
>           </execution>
>           <execution>
>         <!-- not sure in which phase you want to execute your sql 
> command -->
>             <phase>???</phase>
>             <goals>
>               <goal>run</goal>
>             </goals>
>             <configuration>
>               <tasks>
>                 <!-- ant task to call subproject... -->
>               </tasks>
>             </configuration>
>           </execution>
>         </executions>
>       </plugin>
>     ...
> </build>
> 
> 
> here is some more info on lifecycles/phases:  
> http://docs.codehaus.org/display/MAVENUSER/introduction-to-the-lifecycle
> 
> 
> 
> On Mar 5, 2008, at 8:02 AM, Martin Monsorno wrote:
> 
>> Hi *,
>>
>> there's one point I do not understand with maven: how can I use it to 
>> accomplish some tasks that doesn't seem to fit into the standard 
>> phases.  The question arised when implementing continuous 
>> integration.  For this I want to
>>
>> - Copy a artefact to another directory.  (more precisely: to deploy 
>> the generated war-file to the app server)  This is no job for 
>> deploying something to a maven repository or generating a site, but 
>> just a plain copy task.
>>
>> - Call a special goal of a subproject.  (more precisely: my db 
>> subproject uses the hibernate-tools-plugin to execute some sql on the 
>> database)  The subproject includes a plugin for a specific task, but I 
>> want to call this from the major build)
>>
>> With maven 1.x, I wrote a maven.xml and defined goals for this.  But 
>> what is the maven 2 way?  Must I write a plugin?
>>
>> Thanks for your thoughts,
>>
>> Martin.
>>
>> -- 
>> Martin
>>
>>
> 
> 
> ---------------------------------------------------------------------
> 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: Extending maven to accomplish some tasks

Posted by Ian Hummel <hu...@parityinc.net>.
I use the antrun-maven-plugin to do things like this.  I'm not sure if  
that's the right way though!

In your specific case you could try


	<build>
		...
       <plugin>
         <artifactId>maven-antrun-plugin</artifactId>
         <executions>
		<!-- bind to the "install" phase of the default lifecycle -->
           <execution>
             <phase>install</phase>
             <goals>
               <goal>run</goal>
             </goals>
             <configuration>
               <tasks>
                 <copy todir="${todir}">
                   <fileset dir="${fromdir}" />
                 </copy>
               </tasks>
             </configuration>
           </execution>
           <execution>
		<!-- not sure in which phase you want to execute your sql command -->
             <phase>???</phase>
             <goals>
               <goal>run</goal>
             </goals>
             <configuration>
               <tasks>
                 <!-- ant task to call subproject... -->
               </tasks>
             </configuration>
           </execution>
         </executions>
       </plugin>
	...
</build>


here is some more info on lifecycles/phases:  http://docs.codehaus.org/display/MAVENUSER/introduction-to-the-lifecycle



On Mar 5, 2008, at 8:02 AM, Martin Monsorno wrote:

> Hi *,
>
> there's one point I do not understand with maven: how can I use it  
> to accomplish some tasks that doesn't seem to fit into the standard  
> phases.  The question arised when implementing continuous  
> integration.  For this I want to
>
> - Copy a artefact to another directory.  (more precisely: to deploy  
> the generated war-file to the app server)  This is no job for  
> deploying something to a maven repository or generating a site, but  
> just a plain copy task.
>
> - Call a special goal of a subproject.  (more precisely: my db  
> subproject uses the hibernate-tools-plugin to execute some sql on  
> the database)  The subproject includes a plugin for a specific task,  
> but I want to call this from the major build)
>
> With maven 1.x, I wrote a maven.xml and defined goals for this.  But  
> what is the maven 2 way?  Must I write a plugin?
>
> Thanks for your thoughts,
>
> Martin.
>
> --
> Martin
>
>


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