Is there any particular reason why Spring boot starters using Maven? Is it straightforward to use gradle for custom starter with artifactory? - maven

I am trying to balance time and avoid stepping on mines, on one side we have artifactory which is gradle based and need corresponding work to integrate with maven/gradle plugin(preferably with latter as most of our projects are gradle based) on another side all spring boot default starters in source are pom.xml + I only found single gradle custom repo:
https://github.com/web3j/web3j-spring-boot-starter in several pages of search results which uses gradle. But the build file looks pretty convoluted and includes a lot of maven parts.
I am happy to invest time into gradle if someone gives a green light with example/guide/share experience. Thanks. Just to understand if there is some particular reason why the situation is like that or I am afraid of ghosts?

A Spring Boot starter is a jar file containing some compiled classes and, typically, a META-INF/spring.factories file that lists some auto-configuration classes. As such, they can be built equally well with Maven or Gradle. Spring Boot's own starters are built with Maven purely because that's the build system that the whole project uses. If we were starting again from scratch now, we'd probably chose Gradle over Maven.
Some of the third-party starters listed here are build with Gradle, for example:
azure-application-insights-spring-boot-starter
charon-spring-boot-starter
session-couchbase-spring-boot-starter

Related

Spring starter dependencies

I just started out learning spring boot and I can immediately see that there are two types of dependencies, at least those I have encountered,those labelled starter and those that are not. My question is what is the difference and when should I use one over the other.
The starter dependencies are just dependencies that contain a bunch of transitive dependencies. Try to Ctrl + Click them, you will see what other dependencies they contain.
Spring has packaged these dependencies to make your life easier and make you able to add all common dependencies needed to do certain tasks.
This is all based on their motto of convention over configuration.
The short answer is that those "starter" packages are autoconfigurable. They don't need any particular configuration to work out of the box, but you may configure them to fit your particular needs, which makes them perfect for the Spring Boot's focus on simplicity.
Those dependencies are thought to be used with Spring Boot, but the others were/are there for Spring (non Boot) projects. I haven't really dived in to them to pinpoint specific differences, but they pretty much work the same (I've successfuly build and run projects with autoconfigurable dependencies in Spring non Boot projects, but take that with a grain of salt, as those were practice projects in controlled environments).
Ideally you'd want to use 'regular' dependencies with non Boot projects and you'd want to use 'starters' for Boot projects, but it is not a hard rule. Just make sure to use properly mantained dependencies.

why are the github projects of spring-boot-starter projects empty?

On looking at the spring-boot-starter-web, spring-boot-starter-security projects on github, i find them to be empty with just a build.gradle file present there.
I hope this is as expected, but this leads me to understand where the actual source code can be found. And I use maven, so I was expecting atleast a pom.xml in these projects. But since it is not present, I am wondering how spring boot team publishes there artifacts to maven central repo.
I hope this is as expected
This is as expected. Spring Boot's starter modules exist purely to being multiple dependencies together into a convenient "package". For example, if you want to write a Servlet-based web application using Spring MVC and Tomcat, a single dependency on spring-boot-starter-web provides all of the dependencies that you need. You can learn a bit more about the starters in the reference documentation.
Where the actual source code can be found
The majority of the code can be found in spring-boot-autoconfigure. For more production-focused features, you'll also find some code in spring-boot-actuator-autoconfigure. The code in these two modules is activated automatically when the dependencies that it requires are on the classpath. You can learn more about this conditional activation and auto-configuration in the reference documentation.
And I use maven, so I was expecting atleast a pom.xml in these projects. But since it is not present, I am wondering how spring boot team publishes there artifacts to maven central repo.
Spring Boot is built with Gradle which, unlike Maven, completely separates the configuration needed by the build system to build the project and the information needed by a build system to consume the project. The build.gradle files provide all of the information that Gradle needs to build the project. As part of this, it generates Gradle module metadata files and Maven pom.xml files that contain all of the information needed to consume the project with Gradle and Maven respectively. These generated files are then published to Maven Central alongside the jar files, source code, etc.

Can we use Springboot with multimodule for microservices

As Springboot multimodule produces single fat jar will that be good idea to use spring boot multimodule project for microservices
Yes, Actually it is a very good idea to use the multimodule project.
Below are some advantages of that:
Gives clarity about the code and project module
Decouples the layer.
Easy to modify/add the module. Suppose your persistence module is already implemented with Couchbase and now you wanted to switch to Mongo DB then you just need to change the persistence module(dependency, code, configuration) not other parts of a project.
Easy to maintain.
No, I believe. Actually, it is bad design to generate single fat jar for multimodule project in Spring Boot. Suppose, we have multimodule project having 3 sub-modules for different microservices. Then each module will have its individual pom right? that we need to refer in main project's pom as module. Now, assume anyhow we are able to define packaging in main module pom as single fat jar for all the sub-modules. Then, you are not following the microservices architecture guidlines. It will be a kind of monolithic architecture, because all your services are there in a single unit (a jar). Although it would be easy to maintain, but difficuilt to configure through Jenkins pipelines. I mean you have to customize your Jenkins pipelines.
You may refer following url for more details : https://thebasictechinfo.com/spring-boot/spring-boot-microservices-architecture-spring-cloud-netflix-oss

Is bad practice to have spring boot starter project for starter project?

Spring boot starter project provides extensive set of functionalities auto configured. But for our application we want to have only a subset of functionality. May be only one feature out of the spring boot starter project. So is it advised to have custom starter project on top of spring boot provided starter project to mask some of the features or write new starter project directly from lower level libraries?
Spring boot starter project provides extensive set of functionalities
auto configured
There are two separate concerns you are talking about.
I think the auto configured part is something which is Spring boot's opinionated way of configuring. As an example if in classpath it finds a in-memory database library ( like H2) it automatically creates a datasource (pointing to embedded in-memory database) which is available for autowiring without you writing the configuration in a Java config class. Of course you can create you own datasource of choice by including appropriate driver jar for that database. Similarly lots of other configurations are done by default by classpath scanning and availability of certain jars and classes.
The second part - is more of a dependency issue in general. Say you want to use web mvc part in Spring boot. This will require a consistent set of dependencies and transitive dependencies as well. Rather than finding and declaring the dependency in your build tool of choice ( maven, gradle etc) it has created the concept of starter projects where you simply mention the parent and all the right dependencies would be pulled on. This gives a great way to correctly lock your dependencies. However if you want to include any different version than what is provided by boot starter ( provided there is no compatibility issues with those different versions) you can still add explicitly in your build tool. For e.g., maven will by default include the highest version of a particular dependency among all available via transitive dependencies when it resolves dependency for an artifact.

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.

Resources