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 2013/03/27 13:24:16 UTC
Calling versions plugin from code?
I am writing a java class where I need to use the
versions-maven-plugin to basically do what I normally do from command
line:
mvn versions:set -DnewVersion=1.0.1-SNAPSHOT
Having maven installed locally (and on the path) is not an option. In
a project I have added:
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.0</version>
</dependency>
an started work on at test:
SetMojo ss = new SetMojo();
Model model = new Model();
MavenProject project = new MavenProject(model);
project.setFile(new File("test/pom.xml"));
ss.setProject(project);
try {
ss.execute();
} catch (MojoExecutionException e) {
e.printStackTrace();
} catch (MojoFailureException e) {
e.printStackTrace();
}
But it could be nice with some examples/unit tests that shows how to
do this the right way. Any recommendations for this?
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: Calling versions plugin from code?
Posted by Baptiste MATHUS <bm...@batmat.net>.
Hi,
Plugins run in a managed environment, parameters are injected, etc.
So instantiating the mojos manually is not going to working.
You should have a look at maven embedder.
Cheers
2013/3/27 motes motes <mo...@gmail.com>
> I am writing a java class where I need to use the
> versions-maven-plugin to basically do what I normally do from command
> line:
>
> mvn versions:set -DnewVersion=1.0.1-SNAPSHOT
>
> Having maven installed locally (and on the path) is not an option. In
> a project I have added:
>
> <dependency>
> <groupId>org.codehaus.mojo</groupId>
> <artifactId>versions-maven-plugin</artifactId>
> <version>2.0</version>
> </dependency>
>
> an started work on at test:
>
> SetMojo ss = new SetMojo();
> Model model = new Model();
> MavenProject project = new MavenProject(model);
> project.setFile(new File("test/pom.xml"));
> ss.setProject(project);
> try {
> ss.execute();
> } catch (MojoExecutionException e) {
> e.printStackTrace();
> } catch (MojoFailureException e) {
> e.printStackTrace();
> }
>
> But it could be nice with some examples/unit tests that shows how to
> do this the right way. Any recommendations for this?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
--
Baptiste <Batmat> MATHUS - http://batmat.net
Sauvez un arbre,
Mangez un castor !