Specify archetype for archetype:generate on command line - maven

I'm generating a Maven archetype for a simple project. I use archetype:generate, and it gives me a list of types of archetypes to generate. I'm pretty sure I want
99: remote -> maven-archetype-quickstart (An archetype which contains a sample Maven project.)
I can just enter "99" interactively, but I'm trying to write a blog post. I don't want to tell my readers "search for maven-archetype-quickstart in the hundreds of options", and I know it won't always be number 99.
So, how do I specify on the command line the archetype to generate?
(A similar question discusses which archetype to use, but not how to specify it non-interactively)

You can provide arguments via system properties, as in:
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

Related

How to build a maven scaffold like spring initializr

As the title, is there such a maven plugin that can achieve such a function, I can manually select the required dependencies, or even generate the code automatically?
There is https://code.quarkus.io/ for generating projects from the browser and also the quarkus https://quarkus.io/guides/cli-tooling if you want to use a command line application
You can create Maven project with mvn archetype:generate command. For example:
mvn archetype:generate -DgroupId=com.roamch007 -DartifactId=my-app -DinteractiveMode=false
This command will create project in may-app directory.
If you need specific dependencies you can create Maven Archetype, and re-use this archetype while generating new projects.
Read more: Guide to Maven Archetype

Maven project initializer

Is there an easy way to initialize maven projects which is equal to spring initializer? (https://start.spring.io/).
What I meant was an easy interface rather than going through command line or without using paid IDE.
In Eclipse, you can create a new Maven Project in "File -> New -> Project". Then you can choose a Maven archetype (which is essentially a project template) and enter the parameters.
Or from the command line, using the spring-boot-sample-simple-archetype
mvn archetype:generate -DarchetypeGroupId=org.springframework.boot -DarchetypeArtifactId=spring-boot-sample-simple-archetype -DarchetypeVersion=RELEASE
For basic maven projects I have a shell script in my work directory, using the maven quick start archetype:
$ cat quickArch.sh
mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=RELEASE

Maven archetype - Run external commands after creation

I'm looking for a way, to execute additional commands (e.g. a perl script) after running mvn archetype:generate on my custom archetype automatically.
Is this possible?
Context
I'm writing an archetype, that creates OSGi bundles which i want to integrate into a parent project as modules. After generating the bundle, i wish to organise it into the parents directory structure and then manipulate poms and other configuration files automatically.
This has been asked on maven forums before 1, however no answer was given.
Thrau, you can invoke mojo post execution of archetype:generate by adding -Dgoals="your custom mojo plugin", within the plugin you can write your custom code. Hope this helps.

Maven 3: Stripes Archetype - cannot create project?

I'm following this guide:
http://www.stripesframework.org/pages/viewpage.action?pageId=1572995&decorator=printable
I run the following command, which reports BUILD SUCCESS:
mvn install:install-file
-Dfile=stripes-archetype-quickstart-1.0.jar
-DgroupId=net.sourceforge
-DartifactId=stripes-archetype-quickstart
-Dversion=1.0 -Dpackaging=jar
I had previously downloaded the file "stripes-archetype-quickstart-1.0.jar" from here :
http://sourceforge.net/projects/mvnstripes/files/stripes-quickstart-1.0/1.0/stripes-archetype-quickstart-1.0.jar/download
So far so good, now I continue with the guide and attempt to create a project based on the archetype with this command:
mvn archetype:generate
-DarchetypeArtifactId=stripes-archetype-quickstart
-DarchetypeGroupId=net.sourceforge
-DarchetypeVersion=1.0
But Maven doesn't appear to recognize the newly installed archetype; and it goes into interactive mode:
Your filter doesn't match any archetype (hint: enter to return to
initial list) Choose a number or apply filter (format:
[groupId:]artifactId, case sensitive contains): :
Is there a trick I'm missing here ?
You should use option "-DarchetypeCatalog=local" when referencing local archetype, e.g.
mvn archetype:generate -DarchetypeCatalog=local
with -DinteractiveMode=false will solve the issue

How to register my maven archetype so that it gets listed as part of archetype:generate

How to register my maven archetype so that it gets listed as part of mvn archetype:generate call?
the mvn archetype:generate command lists the archetype defined in the catalog file from the maven central repository...
This catalog is meant to contains stable and reliable archetypes...
If your archetype will help us to save the world, you should create a JIRA and ask for them to register you project: https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide
Otherwise you can setup a local catalog that will be used to spread your project.
HIH
M.
you can install the archtype ( mvn install) into your local repository first and then it will be available for mvn archetype:generate command.
mvn archetype:generate -DarchetypeGroupId=gpid -DarchetypeArtifactId=archetype

Resources