How to create a maven plugin by using Spring Boot - spring

I am creating a Maven plugin following the maven tutorial https://maven.apache.org/guides/plugin/guide-java-plugin-development.html.
As my plugin is complex, I want to take advantage of Spring Boot projects (modules like Spring data Neo4j and others). My question is how can I use Spring Boot to create a maven plugin? Any example is appreciated if possible.

Related

What is the archetype to use to build a SpringBoot project?

For years, I've used Spring Initializr (at https://start.spring.io/) to create the initial SpringBoot application and then modify it to create the app. This works fine.
Is there a maven archetype I can use to create a SpringBoot app? Or is the Spring Initializr the only way to do this.
Searching I found this:
What archetype to choose for a simple java project
Which shows the command:
mvn archetype:generate -Dfilter=org.apache.maven.archetypes:
Which gives me a list of 14 items to choose from. None of them mention SpringBoot.
The closest match is org.apache.maven.archetypes:maven-archetype-webapp, so I tried it and it created a WebApp (*.war) which is not what I'm looking for.
The aim of the Maven archetype is for generating a project skeleton. The Spring Initialiser also does the same but I think you should find it more user friendly to use when compared to executing a maven archetype command.
If you insist to use maven archetype , you can simply search Github to see if there are people share their archetypes (search result at here)
If your aim is just to use command to generate a spring-boot project skeleton , Spring Initializr actually provide an HTTP API to do it.
Also you can checkout JHipster, which is another tool to generate a spring-boot project skeleton.
You could also use Spring Boot CLI to scaffold new Spring Boot projects:
spring init --dependencies=web,data-jpa my-new-project
It works just as Spring Initializr, but on the command line.
See section 2.4 "Initialize a New Project" on Spring Boot CLI documentation here: https://docs.spring.io/spring-boot/docs/current/reference/html/cli.html#cli.using-the-cli.initialize-new-project

How does Spring Boot 2.3.X Maven Project use Parent POM?

I got to know that Spring Boot 2.3.X is using Gradle.
If so, how does a Maven-based Spring Boot 2.3.X project uses a parent pom?
Spring Boot 2.3 uses Gradle for its own build but applications using Spring Boot can continue to use Maven (or any other build system they were using before). Spring Boot 2.3 publishes the same artifacts (jar files, pom files, etc) as Spring Boot 2.2 so a Maven-based project can continue to use spring-boot-starter-parent as its parent pom.
When you use spring initialiser, you can find the option to build with gradle. All the parent dependencies will be automatically added by the initialiser into the build.gradle file.
Maven based pom.xml shall also be created using same spring initializer by choosing appropriate properties in the initializer page.

Spring Boot support maven multi-module

I am trying to convert my existing multi-module maven Spring project to Spring Boot project. The reason is make it self contain and follow Martain Fowler's microservices concept.
However, the problem I have encounter is when try to clean build, seems the spring boot is trying to find the Main method from every module, which of course will failed.
Is this feature currently supported by Spring Boot 1.1.6.RELEASE or I did something wrong?
Thanks
It sounds like you've added Spring Boot's Maven plugin to every module in your build – it's what's looking for a main method. You should only add the Spring Boot plugin to a module if its a service that you want to run. If the module's just code that's shared between your services, the Spring Boot plugin isn't needed in that module.

Is Spring tightly coupled with maven

Is Spring tightly coupled with Maven ? Most of the examples in the internet shows Spring and Maven to configure spring dependent jars, this post explains so many cons of Maven. All commercial projects are should to be using only this combination ?
Please explain
Thanks
Both of them serve different purposes, Spring examples use Maven because maven is highly adopted as a build, dependency management framework. That has nothing to do with Spring coupling with Maven. Spring is a framework to build enterprise applications and Maven is a build and deploy tool.
You can use Gradle, ivy or even manually download the libraries instead of relying on Maven as the dependency management framework.
No. You can use whatever you want to build your Spring-based app. BTW, all the Spring tutorials show examples using Gradle (that Spring also uses internally).
What is true, though, is that Spring jars are available from the Maven central repository and the Spring repository, and that their dependencies is thus described in a Maven pom.xml file. But nothing prevents you from downloading the required jars manually and add them in the classpath.

Maven 3 Archetype for Project With Spring, Spring MVC, Hibernate, JPA

I'm trying to use Maven 3 to create a project which uses Spring 3, Spring MVC, Hibernate 4, and JPA. However, when I execute:
mvn archetype:generate
Non of the archetypes listed include all of these; and even those which are close seem to be special projects such as projects with Flex. I want to avoid having extra modules such as Flex that would crowd the project and configuration files. So, is there an archetype for Maven 3 that I can use to create such a project?
A great Spring MVC quickstart archetype is available on GitHub, courtesy of kolorobot. Good instructions are provided on how to install it to your local Maven repo and use it to create a new Spring MVC project. He’s even helpfully included the Tomcat 7 Maven plugin in the archetypical project so that the newly created Spring MVC can be run from the command line without having to manually deploy it to an application server.
Kolorobot’s example application includes the following:
No-xml Spring MVC 3.2 web application for Servlet 3.0 environment
Apache Tiles with configuration in place,
Bootstrap
JPA 2.0 (Hibernate/HSQLDB)
JUnit/Mockito
Spring Security 3.1
Possible duplicate: Is there a maven 2 archetype for spring 3 MVC applications?
That said, I would encourage you to think about making your own archetype. The reason is, no matter what you end up getting from someone else's, you can do better in not that much time, and a decent sized Java project is going to end up making a lot of jar projects.
Take a look at http://start.spring.io/ it basically gives you a kick starter with either maven or gradle build.
Note: This is a Spring Boot based archetype.
With appFuse framework, you can create an Spring MVC archetype with jpa support, etc ...
Take a look at it's quickStart guide to see how to create an archetype based on this Framework.
Foundational frameworks in AppFuse:
Bootstrap and jQuery
Maven, Hibernate, Spring and Spring Security
Java 7, Annotations, JSP 2.1, Servlet 3.0
Web Frameworks: JSF, Struts 2, Spring MVC, Tapestry 5, Wicket
JPA Support
For example to create an appFuse light archetype :
mvn archetype:generate -B -DarchetypeGroupId=org.appfuse.archetypes
-DarchetypeArtifactId=appfuse-light-struts-archetype -DarchetypeVersion=2.2.1
-DgroupId=com.mycompany -DartifactId=myproject

Resources