Ok. It seems I found the answer.
The answer were here:
Can anyone give a good example of using org.apache.maven.cli.MavenCli programattically?
And here:
https://groups.google.com/forum/#!topic/daisy-pipeline-dev/tubf3KXClM4
http://code.google.com/p/phloc-parent-pom/source/browse/trunk/pom.xml?r=47
Basically you should end up with this pom.xml (all about dependencies!):
<!-- maven api-->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<version>3.0.5</version>
</dependency>
<dependency> <!-- https://stackoverflow.com/questions/4206679/can-anyone-give-a-good-example-of-using-org-apache-maven-cli-mavencli-programatt -->
<groupId>org.sonatype.aether</groupId>
<artifactId>aether-connector-wagon</artifactId>
<version>1.13.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http</artifactId> <!-- https://groups.google.com/forum/#!topic/daisy-pipeline-dev/tubf3KXClM4 -->
<version>2.1</version> <!-- http://code.google.com/p/phloc-parent-pom/source/browse/trunk/pom.xml?r=47 -->
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0.10</version>
</dependency>
Then, if you have an error like:
Non-resolvable parent POM: Failure to find com.mycompany.common:commons:pom:2.0.6
then make sure you use right version for your parent project. Parent should have the same version that real LOCAL root pom.xml has.
If you still have that error then the path to your parent like this:
<relativePath>../pom.xml</relativePath>
This is actually default value. But in your case it might be
<relativePath>../../pom.xml</relativePath>
if you have deeper folder structure (like I had)
my client code is:
System.setProperty("user.home", "C:\\my"); // ~/.m2/repository lives here
MavenCli cli = new MavenCli();
// THIS IS IMPORTANT AS WELL !!!
int result = cli.doMain(
new String[]{"-DincludeScope=runtime", "dependency:copy-dependencies", "clean", "validate"},
projectPath,
System.out,
System.out);
It creates: c:/.m2/repository
folder. But it is empty for now.