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

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

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

How to install Maven archetype from local JAR and POM, and also update local catalog

I want to distribute a custom archetype JAR and POM, without deploying them to a Maven repository, so that someone can grab them and install in their local repository with something like a mvn install:install-file -Dfile <file> -DpomFile <pom>.
But if one just does:
mvn install:install-file -Dfile=./my-archetype-1.0.jar -DpomFile=./my-archetype-1.0.pom
the local catalog doesn't get updated.
Though there are similar questions like this, this and this, they left me missing a small step.
I'm not sure how to run the mvn archetype:update-local-catalog that they mention. Where's the pom.xml?
Simply run mvn -f <archetypePomFile> archetype:update-local-catalog doing a mvn -f pointing to the archetype pom.
So altogether it's:
Install archetype
mvn install:install-file -Dfile=./my-archetype-1.0.jar -DpomFile=./my-archetype-1.0.pom
Update local catalog
mvn -f my-archetype-1.0.pom archetype:update-local-catalog
Maybe that's obvious to others reading the doc but I spent enough time on this that I thought I'd write it up.

Maven 3 - Unable to find archetype

I have created a customized archetype, customA-web-archetype. Within the project folder, customA-web-archetype , I ran mvn clean install archetype:update-local-catalog which was successful. Now when I run mvn archetype:generate -DarchetypeCatalog=local outside the folder to use the archetype, I am getting the following error:
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
Choose archetype:
Your filter doesn't match any archetype (hint: enter to return to initial list)
FYI- When I was setting up Maven, I moved the .m2 to a different directory rather than using the default home directory. I made the appropriate change to settings.xml so that it can find the .m2 in the updated directory structure.
I am not using any repo manager such as Nexus. Just a local m2 repo sitting on the same box as the archetype project.
To run the archetype command, you need to specify the groupId, artefactId and version of your archetype, as well as those of your future maven project.
You should try the following command, with your own parameters:
mvn archetype:generate -DarchetypeCatalog=local -DarchetypeGroupId=yourArchetypeGroupId -DarchetypeArtifactId=yourArchetypeArtifactId -DarchetypeVersion=yourArchetypeVersion -DgroupId=projectGroupId -DartifactId=projectArtifactId -DinteractiveMode=false
After upgrading from Maven 2 to 3 we found the same problem. The fix was to change the version of the archetype-packaging and maven-archetype-plugin from 2.2 to 3.0.0 in the archetype pom.
I looks like maven moved the location of it's archetype repository file from ~/.m2 to ~/.m2/repositories which is why generate wasn't finding it.
One strange behavior I'm still seeing is that if I just do
mvn archetype:generate
it doesn't show my local archetypes, however if I do a
mvn archetype:generate -DarchetypeCatalog=local
it shows up. Hope this helps.
Have you tried crawling the repo to create a catalog? Perhaps it's missing / broken? Archetype plugin has crawl goal, which parses the repo and creates catalog.xml.
mvn archetype:help
[... snip ...]
archetype:crawl
Crawl a Maven repository (filesystem, not HTTP) and creates a catalog file.

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

Is there any Apache Click maven archtype similar to Wicket's?

Is there any Apache Click maven archetype similar to Wicket's quick start? Similar to http://wicket.apache.org/start/quickstart.html
Basically what I need is a way to get started using Apache Click quickly using Maven.
Thanks in advance.
I never tried it myself, but this project provides a maven archetype for click. It doesn't look like they provide it in a public repository, so you will need to check the sources, compile&install it and than you'll be able to use it, e.g.:
$ svn checkout http://construtor.googlecode.com/svn/trunk/ construtor-read-only
$ cd construtor-read-only/maven-archetype-click/
$ mvn clean install
$ mvn archetype:generate
[...]
387: local -> maven-archetype-click (An archetype which generates a simplifed sample of the Apache Click Framework.)
[...]
For the benefit of future enquirers, there are instructions to achieve this here. However, the remote build did not work for me using Maven 3 nor did the local installation suggested without some modifications. This is what worked for me:
Download the archetype jar file
Install the archetype in the local maven 3 repo:
mvn install:install-file -DgroupId=com.google.constructor.archetypes -DartifactId=maven-archetype-click -Dversion=1.0 -Dpackaging=jar -Dfile=\maven-archetype-click-1.0.jar
Generate skeleton project:
mvn archetype:generate -DarchetypeGroupId=com.google.constructor.archetypes -DarchetypeArtifactId=maven-archetype-click -DarchetypeVersion=1.0 -DgroupId=com.test -DartifactId=clickprimer -DarchetypeCatalog=local
cd clickprimer
mvn clean package
mvn jetty:run

Resources