I'm trying to create a maven project programmatically by running a java application. In the application, I have set the pom file as:
request.setPomFile(new File(thePomFile));
request.setGoals( Collections.singletonList( "archetype:generate" ) );
This is a pom file with archetype info that I want to use since I have my own project structure.
Two questions:
I tried looking up the api docs, and other stackoverflow questions but couldn't find anything close to this. Thank you!
I was able to supply the information in point 2, by answering the question in the first place.
In the request itself, you need to do:
request.setGoals(Collections.singletonList("archetype:generate -DgroupId=.....");
Then if you look at the api docs, there is a command line builder that I didn't notice before: https://maven.apache.org/shared/maven-invoker/apidocs/index.html
MavenCommandLineBuilder mavenCmd = new MavenCommandLineBuilder();
Set the necessary configurations like base directory, path to maven executable etc to this mavenCmd.
Then, you can send your previously created request to it, like:
Commandline result = mavenCmd.build(request);
To answer my first point, I ended up removing setting pom itself because I was fetching it remotely and mentioned the archetype in the command I sent to mavenCmd. There might be a better way but this worked for me and I'm good with it.