You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Wim Deblauwe <wi...@gmail.com> on 2005/11/21 11:55:37 UTC

[m2] Copy the dependencies of a project in a custom plugin

Hi,

I'm writing a custom plugin and I need to copy the project's dependencies
from the local repository to a certain directory. How can I do this best?

I already managed to get a list of dependencies in my Mojo:

Iterator iterator = dependencies.iterator();
while (iterator.hasNext())
{
Dependency dependency = (Dependency)iterator.next();

}

So, now I need to get the path of the Depency in the local repository and
then copy the file.


question 2:
When my plugin works, it will produce a different artifact (.msm), how
should I handle the 'instal' and 'deploy' of that artifact? Do I need to
write my own custom mojo for that or can I re-use the plugins already
written for .jar files?

regards,

Wim

Re: [m2] Copy the dependencies of a project in a custom plugin

Posted by Wim Deblauwe <wi...@gmail.com>.
The collection of artifacts is empty. When I was using dependencies, it was
not empty. What am I doing wrong? This is my code:

/**
* @goal process-resources
* @description Copy the dependencies for the InstallShield Merge Module
*/
public class MsmProcessResourcesMojo extends AbstractMojo
{
/**
* @parameter expression="${project.artifacts}"
* @requiresDependencyResolution
*/
private Collection artifacts;

/**
* @parameter expression="${project.build.directory}/resources"
*/
private File targetDirectory;

public MsmProcessResourcesMojo()
{
}

public void execute() throws MojoExecutionException, MojoFailureException
{
try
{
getLog().info( "Process Resources for InstallShield Merge Module..." );
Iterator iterator = artifacts.iterator();
while (iterator.hasNext())
{
Artifact artifact = (Artifact)iterator.next();
FileUtils.copyFileToDirectory( artifact.getFile(), new File(
targetDirectory, artifact.getType() + "s" ) );
}
}
catch (IOException e)
{
throw new MojoExecutionException( "Error copying artifacts", e );
}
}
}

thank you,

Wim

2005/11/21, Brett Porter <br...@gmail.com>:
>
> maven-artifact and maven-project (though you may not need the project
> dependency if you are just using the expression below as it is
> runtime, and Mavne provides it).
>
> - Brett
>
> On 11/21/05, Wim Deblauwe <wi...@gmail.com> wrote:
> > What dependency do I need for the Artifact and Project classes in my
> Mojo?
> >
> > 2005/11/21, Brett Porter <br...@gmail.com>:
> > >
> > > On 11/21/05, Wim Deblauwe <wi...@gmail.com> wrote:
> > > > Hi,
> > > >
> > > > I'm writing a custom plugin and I need to copy the project's
> > > dependencies
> > > > from the local repository to a certain directory. How can I do this
> > > best?
> > >
> > > You should use ${project.artifacts} instead which includes all the
> > > transitive artifacts, and for which you can call artifact.getFile().
> > >
> > > Make sure you include @requiresDependencyResolution
> > >
> > > > question 2:
> > > > When my plugin works, it will produce a different artifact (.msm),
> how
> > > > should I handle the 'instal' and 'deploy' of that artifact? Do I
> need to
> > > > write my own custom mojo for that or can I re-use the plugins
> already
> > > > written for .jar files?
> > >
> > > You can reuse the mojos, but you will still need to define the
> > > customisations, which will require a plugin. There are examples in the
> > > "introduction to the build lifecycle".
> > >
> > > Cheers,
> > > Brett
> > >
> > > ---------------------------------------------------------------------
> > > 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: [m2] Copy the dependencies of a project in a custom plugin

Posted by Brett Porter <br...@gmail.com>.
maven-artifact and maven-project (though you may not need the project
dependency if you are just using the expression below as it is
runtime, and Mavne provides it).

- Brett

On 11/21/05, Wim Deblauwe <wi...@gmail.com> wrote:
> What dependency do I need for the Artifact and Project classes in my Mojo?
>
> 2005/11/21, Brett Porter <br...@gmail.com>:
> >
> > On 11/21/05, Wim Deblauwe <wi...@gmail.com> wrote:
> > > Hi,
> > >
> > > I'm writing a custom plugin and I need to copy the project's
> > dependencies
> > > from the local repository to a certain directory. How can I do this
> > best?
> >
> > You should use ${project.artifacts} instead which includes all the
> > transitive artifacts, and for which you can call artifact.getFile().
> >
> > Make sure you include @requiresDependencyResolution
> >
> > > question 2:
> > > When my plugin works, it will produce a different artifact (.msm), how
> > > should I handle the 'instal' and 'deploy' of that artifact? Do I need to
> > > write my own custom mojo for that or can I re-use the plugins already
> > > written for .jar files?
> >
> > You can reuse the mojos, but you will still need to define the
> > customisations, which will require a plugin. There are examples in the
> > "introduction to the build lifecycle".
> >
> > Cheers,
> > Brett
> >
> > ---------------------------------------------------------------------
> > 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: [m2] Copy the dependencies of a project in a custom plugin

Posted by Wim Deblauwe <wi...@gmail.com>.
What dependency do I need for the Artifact and Project classes in my Mojo?

2005/11/21, Brett Porter <br...@gmail.com>:
>
> On 11/21/05, Wim Deblauwe <wi...@gmail.com> wrote:
> > Hi,
> >
> > I'm writing a custom plugin and I need to copy the project's
> dependencies
> > from the local repository to a certain directory. How can I do this
> best?
>
> You should use ${project.artifacts} instead which includes all the
> transitive artifacts, and for which you can call artifact.getFile().
>
> Make sure you include @requiresDependencyResolution
>
> > question 2:
> > When my plugin works, it will produce a different artifact (.msm), how
> > should I handle the 'instal' and 'deploy' of that artifact? Do I need to
> > write my own custom mojo for that or can I re-use the plugins already
> > written for .jar files?
>
> You can reuse the mojos, but you will still need to define the
> customisations, which will require a plugin. There are examples in the
> "introduction to the build lifecycle".
>
> Cheers,
> Brett
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: [m2] Copy the dependencies of a project in a custom plugin

Posted by Brett Porter <br...@gmail.com>.
On 11/21/05, Wim Deblauwe <wi...@gmail.com> wrote:
> Hi,
>
> I'm writing a custom plugin and I need to copy the project's dependencies
> from the local repository to a certain directory. How can I do this best?

You should use ${project.artifacts} instead which includes all the
transitive artifacts, and for which you can call artifact.getFile().

Make sure you include @requiresDependencyResolution

> question 2:
> When my plugin works, it will produce a different artifact (.msm), how
> should I handle the 'instal' and 'deploy' of that artifact? Do I need to
> write my own custom mojo for that or can I re-use the plugins already
> written for .jar files?

You can reuse the mojos, but you will still need to define the
customisations, which will require a plugin. There are examples in the
"introduction to the build lifecycle".

Cheers,
Brett

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