How to build a maven scaffold like spring initializr - spring

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

Related

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 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.

Creating a Maven Project Programmatically Runtime

I have created a number of java classes using sun code model library. Now, I would like to create a maven project add those classes and upload it to a Nexus Sonatype Internal Maven Repository. Does anyone know how to create a maven project programmatically. Any help will be appreciated.
It is not really programmatically, but maven archetype can generate a project squeleton for you:
mvn archetype:generate -DgroupId={project-packaging}
-DartifactId={project-name}
-DarchetypeArtifactId=maven-archetype-quickstart
You can also run simply :
mvn archetype:generate
And choose an archetype from the list displayed.
Once done, you can put your java file in src/main/java.
https://maven.apache.org/guides/introduction/introduction-to-archetypes.html

Build,Unit test,Compile using maven

I want to some operation on my xcode project that is compile,build and unit test using the "Maven" command like "mvn clean install","mvn validate". do we need to create Pom.xml? how can we create Pom.xml
Thanks
sure, u need pom.xml. how to build your pom? you can read maven's manual:
http://maven.apache.org/guides/introduction/introduction-to-the-pom.html

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