How to find Spring dependencies after project is initialized? - java

I'm new to Spring world. I am following Spring Microservices in Action, where they recommend to use Spring Intializr to get Spring dependencies. However, post that whenever we need to add new dependencies, maven dependencies are provided in book. What would professionals do in such situation? How will new dependencies be found and added to the pom.xml?

You can find them in public repositories like https://mvnrepository.com or search for Maven Central alternatives.
Also, you can find your needed dependency on that third-party library's official website, for example, if you want to add Lombok dependency to your project simply find it in https://projectlombok.org/setup/maven
One the other way is Spring Initializr ad you said. Just find and add the dependency inside this website and then click on the Explore link at the bottom of the main page:
And take a look at the pom.xml file. You can see the dependency:
There are absolutely multiple other ways like finding and adding the dependency in your IDE (IntelliJ, Eclipse ...) and ...

Related

Gradle: figure out a Maven dependency scope by using `Configuration` and its dependency set

So I'd like given a Groovy Configuration and its Dependencies figure out the Maven dependency scope, of which there are six.
For some dependencies it is trivial, as implementation translates to Mavens compile neatly.
What to do about things like errorpone? This configuration has its own dependencies, but what is their Maven scope? Is there a way to tell programmatically? I'd like to avoid having a huge Map<Configuration, String> of configuration -> its maven scope.
Thanks in advance.
Gradle has a much richer model than the hardcoded scopes of Maven. Relationship to Maven scopes matters only when publishing a library to a Maven repository, using a pom.xml for the metadata.
I recommend reading documentation around configurations or watching the webinar on the topic of dependency management fundamentals (Note: I am co-presenter in this webinar)

How to retrieve avaliable versions of a maven dependency programmatically?

I want to find all available versions of a dependency in my project using a Mojo. I need this information to create a complete dependency tree where not only the transitive dependencies are included, but also all available versions and then their respective dependencies.
The problem is that I can't simply download each individual metadata file since that would make the plugin too slow. What other ways are there to find all other versions through a Mojo and the Maven plugin API, and how do I achieve it?
Example of tree I'm trying to generate.
If I only look at the components specified in the pom, I will miss out on the dependency a1.0 -> c1.1 and b1.0 -> d1.1.
To clarify what information I am missing; the following graph shows what would appear if I where to simply use dependency:tree.

Create common class, has dependency, how do I formally share this dependency?

I've extended an abstract class and implemented a method that I will use with Mule over and over. I want to add it to a library that I will repo on Maven central. It depends on a JAR that's provided in the Mule connector devkit (sdk for Mule connectors). How do I formally publish or tell others publicly that my common library will not work without the earlier dependency too? The dependencies org.json and fasterXML...Jackson..etc.
My code module is an HttpProcessMessage and the over-used method returns a String of formatted JSON. The message POJO gets loaded and then ultimately my method is like a toString() method but more sophisticated.
I would like for this class to be part of a common library that would become part of the community. I wish that my code here would be the foundation and have no dependencies. Now, I'm looking for an answer to address the dependencies and inform the public.
That's one of the main benefits of Maven and other dependency management tools, when your dependency is added to their Maven project, Maven will automatically fetch transitive dependencies. So there is no need to let people know what dependencies you rely on. It will automatically be handled and they can use Maven command if they wish or inspect the maven artefact to determine what transitive dependencies you rely on.
You will need to add the com.faster.xml dependencies and org.json dependencies to your Maven pom.xml and all this information is packaged alongside your Maven artefact and will be stored in a Maven repo.
More info on Maven dependencies here: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
If they are manually installing the jar outside of Maven/Gradle etc. then theres not much you can do except provide them a detailed README on installation instructions.

How Spring boot giving the dependencies and configuration?

I understand the concept of Spring boot, but I am looking for the logic how it is implemented and where it is maintaining the configuration. When we add any Starter-pom immediately it is giving the dependency and the configuration needed for it. How it automated that feature and where is that automating code in the spring boot?
Thanks in advance
The configuration classes for Spring Boot are in the module spring-boot-autoconfigure. A starter POM has a dependency on that (through the general spring-boot-starter module) and the required 3rd party libraries, and then the autoconfiguration for that library is activated.
The SpringBoot project has been put there so to be more productive & build production ready app in no time. SpringBoot project referes many starter projects like spring-boot-starter-jdbc, spring-boot-starter-logging, etc. All these starter libraries are like maven sub module projects and they add a set of libraries to respective project in turn. Like the spring-boot-starter-jdbc library adds these libraries -> spring-jdbc,spring-tx,tomcat-jdbc.
Now for the configuration part, spring boot has maintained another library called spring-boot-autoconfigure which auto configures all needed configs depending on the libraries present on your pom and the initial set of config annotation been used on the app. For Eg. if it sees ojdbc jar present in your pom then it will autoconfigure oracle datasource to your project
From my bare understanding, this feature are not provided by Spring Boot. It is the power of Maven. Maven allow you to declare dependencies, and the dependencies themselves, PLUS the transitive dependencies will be retrieved.
The starter POMs are simply normal Maven POM-type artifact which declared essential dependencies, and hence, when you include in your own POM, related dependencies will be downloaded.
You may get some more understanding on Maven from Maven Site or Maven Guide by Sonatype

spring-webflow jars not available

I have wasted a 4 hours on finding a reason for not adding of webflow jars tp the reference library of my my modular maven project which is generated from appfuse.I want to add a webflow to this project. But when I do the registering as below, I get an error (I have still not run the project).
error is
Multiple annotations found at this line:
- Class 'org.springframework.webflow.mvc.servlet.FlowHandlerAdapter'
not found
But I have included the webflow dependencies in my pom in my web module project. But when I go the the reference library I can not find the webflow jars as well. I think this is the reason for this, But I can not wind a way to get the jars in to the reference library.
The generated pom is very lengthy. I will add it if it is needed.
<dependency>
<groupId>org.springframework.webflow</groupId>
<artifactId>spring-webflow</artifactId>
<version>2.3.2.RELEASE</version>
</dependency>
Is there a compatibility issue with the spring versions. I am currently using 4.0.0.RELEASE I have changed it to 4.0.2.RELEASE as well. But no luck. I can not find a meaningful solution for this. I really appreciate some help on this.
Thanks
In Eclipse, right click the project and go to build path -> configure build path
From here, go to libraries and check that the Maven dependencies library is in there.
If its not click add library click maven managed dependencies, next, finish
Should add the libraries to the eclipse project

Categories