You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Rinku <ra...@gmail.com> on 2006/05/28 22:10:54 UTC

Re: Delegating to other Mojo

You can use Maven Embedder to call another Mojo from within your Mojo.

Below is a snippet that I hope will help.

Cheers,
Rahul

-------------------- snip --------------------
MavenEmbedder maven = new MavenEmbedder ();

ClassLoader classLoader = Thread.currentThread ().getContextClassLoader
();

maven.setClassLoader (classLoader);

maven.setLogger (new MavenEmbedderConsoleLogger ());

try {

maven.start ();

File targetDirectory = new File (targetDir);

File pomFile = new File (targetDirectory, pomXml);

MavenProject pom = maven.readProjectWithDependencies (pomFile);

EventMonitor eventMonitor = new DefaultEventMonitor (new
PlexusLoggerAdapter (new MavenEmbedderConsoleLogger ()));

if (getLog ().isDebugEnabled ())

getLog ().debug ("Executing embedded Maven instance...");

if (getLog ().isInfoEnabled ())

getLog ().info ("delegating goal(s) now to embedded m2 instance.");

maven.execute (pom, goals, eventMonitor, new ConsoleDownloadMonitor (),
null, targetDirectory);

if (getLog ().isInfoEnabled ())

getLog ().info ("Embedded Maven executed successfully!");

} catch (Exception e) {

  // TODO : catch specific Exceptions (this is for demonstration)

}

------------------- snip -------------



----- Original Message ----- 
From: "Wilfred Springer" <wi...@agilejava.com>
To: "Maven Users List" <us...@maven.apache.org>
Sent: Monday, May 29, 2006 2:10 AM
Subject: m2: Delegating to other Mojo


> All,
>
> Is there any way to force execution of some Mojo from another Mojo?
>
> Thanks,
>
> Wilfred
>
>


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