You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Steffen Stundzig <ko...@stundzig.de> on 2010/08/10 18:20:15 UTC
maven3 embedder
Hi folks,
I've tried the whole day on how can i embedd a call for a maven goal
into my java src. I'm working with maven-3.0-beta-1.
Here are my sample snippets which the appropriate error messages:
public class MavenEmbedTest {
public static void main(String[] args) {
File workingDir = new File("/path/to/a/maven/project");
// [1]
MavenCli cli = new MavenCli();
cli.doMain(new String[] { "package" }, workingDir.getAbsolutePath(),
System.out, System.err);
// [2]
DefaultMaven maven = new DefaultMaven();
DefaultMavenExecutionRequest request = new
DefaultMavenExecutionRequest();
request.setBaseDirectory(workingDir);
List<String> goals = new ArrayList<String>();
goals.add("package");
request.setGoals(goals);
MavenExecutionResult result = maven.execute(request);
// [3]
File pom = new File(workingDir, "pom.xml");
DefaultProjectBuilder projectBuilder = new DefaultProjectBuilder();
ProjectBuildingResult project = projectBuilder.build(pom, new
DefaultProjectBuildingRequest());
}
}
As result of [1] running as local java program, i got:
[ERROR] Error executing Maven.
[ERROR] Cycle detected in component graph in the system:
[ERROR] Caused by: Cyclic requirement detected
[ERROR] Caused by: Edge between
'Vertex{label='org.apache.maven.lifecycle.LifecycleExecutor:default'}'
and
'Vertex{label='org.apache.maven.project.MavenProjectBuilder:default'}'
introduces to cycle in the graph
org.apache.maven.project.MavenProjectBuilder:default -->
org.apache.maven.project.ProjectBuilder:default -->
org.apache.maven.model.building.ModelBuilder:default -->
org.apache.maven.model.plugin.LifecycleBindingsInjector:default -->
org.apache.maven.lifecycle.LifecycleExecutor:default -->
org.apache.maven.project.MavenProjectBuilder:default
As result of [2] I got a NullPointerException, because of the annotated
components were not injected. How can I start the PlexusContainer correctly?
The result of [3] is "RepositorySystem is missing" which is nearly the
same problem as in [2].
What I need is to start a maven plugin, which is deployed in my local
repo and is based on maven3.
Could anybody help my please? Are there any samples or code snippets,
which I could use?
Currently I'm working on a hudson build trigger for maven3 based free
style projects. The trigger checks updates on the maven dependencies and
the schedules a rebuild.
Regards
Steffen...
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: maven3 embedder
Posted by Olivier Lamy <ol...@apache.org>.
Hi,
You have to look at the MavenCli code base to understand what to populate.
So currently I'm working on a plexus component which do something like :
MavenExecutionRequest getMavenExecutionRequest( String[] args,
PrintStream printStream ).
So this should be available soon here :
http://github.com/olamy/hudson-maven3-support.
Btw I'm interesting how do you work with your trigger and specially
ClassLoading stuff in hudson.
Because I had some issues. (and it can work without any hack in hudson core)
2010/8/10 Steffen Stundzig <ko...@stundzig.de>:
> Hi folks,
>
> I've tried the whole day on how can i embedd a call for a maven goal
> into my java src. I'm working with maven-3.0-beta-1.
>
> Here are my sample snippets which the appropriate error messages:
>
> public class MavenEmbedTest {
> public static void main(String[] args) {
> File workingDir = new File("/path/to/a/maven/project");
>
> // [1]
> MavenCli cli = new MavenCli();
> cli.doMain(new String[] { "package" }, workingDir.getAbsolutePath(),
> System.out, System.err);
>
> // [2]
> DefaultMaven maven = new DefaultMaven();
> DefaultMavenExecutionRequest request = new
> DefaultMavenExecutionRequest();
> request.setBaseDirectory(workingDir);
> List<String> goals = new ArrayList<String>();
> goals.add("package");
> request.setGoals(goals);
> MavenExecutionResult result = maven.execute(request);
>
> // [3]
> File pom = new File(workingDir, "pom.xml");
> DefaultProjectBuilder projectBuilder = new DefaultProjectBuilder();
> ProjectBuildingResult project = projectBuilder.build(pom, new
> DefaultProjectBuildingRequest());
> }
> }
>
> As result of [1] running as local java program, i got:
> [ERROR] Error executing Maven.
> [ERROR] Cycle detected in component graph in the system:
> [ERROR] Caused by: Cyclic requirement detected
> [ERROR] Caused by: Edge between
> 'Vertex{label='org.apache.maven.lifecycle.LifecycleExecutor:default'}'
> and
> 'Vertex{label='org.apache.maven.project.MavenProjectBuilder:default'}'
> introduces to cycle in the graph
> org.apache.maven.project.MavenProjectBuilder:default -->
> org.apache.maven.project.ProjectBuilder:default -->
> org.apache.maven.model.building.ModelBuilder:default -->
> org.apache.maven.model.plugin.LifecycleBindingsInjector:default -->
> org.apache.maven.lifecycle.LifecycleExecutor:default -->
> org.apache.maven.project.MavenProjectBuilder:default
>
> As result of [2] I got a NullPointerException, because of the annotated
> components were not injected. How can I start the PlexusContainer correctly?
>
> The result of [3] is "RepositorySystem is missing" which is nearly the
> same problem as in [2].
>
> What I need is to start a maven plugin, which is deployed in my local
> repo and is based on maven3.
>
> Could anybody help my please? Are there any samples or code snippets,
> which I could use?
>
> Currently I'm working on a hudson build trigger for maven3 based free
> style projects. The trigger checks updates on the maven dependencies and
> the schedules a rebuild.
>
> Regards
> Steffen...
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
--
Olivier
http://twitter.com/olamy
http://fr.linkedin.com/in/olamy
http://www.viadeo.com/fr/profile/olivier.lamy7
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org