I'm new to springboot and using spring.io to create project in order to create microservices.
When creating a project using spring.io website, a pom is created with all the relevant
dependencies but versions are not added.
Should I add the versions myself looking the maven repository jar (all jars include
versions on them)?
All dependencies (and configurations) are managed by Spring Boot. The parent of the project you generated with Spring Initializr has the parent set to spring-boot-starter-parent:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
The parent of spring-boot-starter-parent is spring-boot-dependencies which defines all dependency versions.
Therefore you don't need to specify any versions of the starter dependencies or their dependencies manually.
Please take a look at The Spring Boot Starter Parent on Baeldung for a quick overview.
Related
I am using spring-boot-starter-parent 2.3.9.RELEASE which according to Maven Central should give me spring-boot-starter-security 2.3.9.RELEASE which in turn should give me spring-security-config 5.3.8.RELEASE.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
However, when I look at Eclipse I see spring-security-config 5.3.5.RELEASE. I dont understand why my local is not reflecting spring-security-config 5.3.8.RELEASE for this artifact even though spring boot starter parent and spring boot starter security (both parents of this) are correctly showing 2.3.9.RELEASE. Also I'm not sure I understand what "Managed from 5.3.8.RELEASE" means in the screenshot. Could someone assist ?
This means that an entry in your <dependencyManagement> section of the POM overrode the version.
This may be a direct entry or a BOM, which you recognise by <scope>import</scope>.
I was understanding something in spring boot and to being with, used a very simple snippet, like adding this in pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
</parent>
As I understand <parent> in this context means that in my pom.xml, there we have a parent pom.xml (saw the pom.xml file for spring-boot-starter-parent) which will have list of dependencies.
The important thing is that it is only pom packaging, and NOT a real jar / binary (please correct if I am wrong)
I saw the following in mvn repository:
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<type>pom</type>
</dependency>
My doubt is:
How can we include it as an dependency , it is just a pom packaging (and not a real jar / war), which acts as central place which holds common dependencies? Is it allowed? I tried adding in my project, but saw errors in STS IDE.
How does this get downloaded? Can we see the contents of this "parent"
First off, you've probably missed the meaning of parent pom in this case.
Spring boot of any specific version (2.2.1 in this case) comes with a bunch of possible integrations with many technologies / libraries. So it provides "default" versions of the libraries to work with because its very hard to check that it compatible with all possible versions of all libraries. You can of course provide your own version but then you should test a compatibility as an application maintainer.
So If you'll checkout the source code of spring-boot-starter-parent pom, you'll see that it provides some plugins and plugin management and more importantly inherits from another pom called spring-boot-dependencies
Note it doesn't add any dependencies to your project. It only defines a dependencyManagement section. This means that once you'll use the dependency in your project (that inherits) from this pom, you don't have to specify a version, only group id and artifact id.
Again, that's because spring boot offers by default very specific versions of thirdparties - the version that it was verified that it's compatible with...
Now as for the second part of the question - indeed it doesn't make sense to include dependency with packaging pom like you've posted, could you please provide a link where exactly you've seen this?
Sometimes when people adopt spring boot in their projects they already have have some parent, so they can't use the inheritance, in this case they can use a very special maven scope "import" and use the dependency on pom treating it as BOM (bill of materials) - frankly a pretty advanced stuff in maven. But spring boot uses this feature for these cases.
The dependency inclusion looks like this:
<dependencies>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
Note, the `import line. From maven's site: This is meant to allow dependency management information such as versions and excludes be retrieved from a remote POM file.
Here is a tutorial about this topic
#CuriousMind, including the spring-boot-starter-parent as a dependency is like trying to instantiate an interface or Abstract Class in Java. As you noticed, its packaging is pom, meaning it is just a maven artifact to help configure your maven project. Jar and War will contain some java binaries. I think the MVN repository code automatically generate all sample as dependencies..
When generating a JHipster project with 4.13.3, and doing a Maven integration of QueryDSL (like described in http://www.querydsl.com/static/querydsl/4.1.3/reference/html_single/#d0e132), the Query types are not generated into target/generated-sources/java.
Before I used JHipster 4.10.x and it worked.
What changed? What I noticed with 4.13.3, that the pom.xml changed, for example the parent is not present any more, before it was:
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>1.5.7.RELEASE</version>
<relativePath/>
</parent>
Now with JHipster 4.13.3 this is missing. I also had to define in the properties of the pom.xml
<querydsl.version>4.1.3</querydsl.version>
otherwise when doing a mvn clean install it throws an ERROR.
What to do to do a Maven integration of QueryDSL into a JHipster project with 4.13.3?
Cheers
I have a simple spring boot app that I am trying to add spring cloud consul to. Spring cloud consul relies on a newer version of spring boot. In my POM I have specified version 1.3.5.RELEASE for all my spring boot artifacts.
The problem is that, even though version 1.3.5 is specified for spring-boot-starter-web it still downloads dependencies with version 1.2.3
Is there a way to have maven get the 1.3.5.RELEASE for ALL spring boot artifacts, including transitive dependencies? I know I can explicitly list them all, but is there a better way?
Here is the POM depenency view from eclipse:
Yes, simple use correct parent:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.6.RELEASE</version>
<relativePath/>
</parent>
and remove versions from spring boot dependencies.
We have a Spring Boot app (exposing REST services) with multiple modules and for dev purposes we're using the default Spring Boot build approach - Maven builds it as one executable war file, that has Tomcat embedded into it.
For productive deployment purposes this doesn't work. We already have web app servers setup and we need a regular, non-executable war, that can be deployed on those servers. I already figured out, how I can build it.
We also will have another, related web apps (war files) deployed on the same productive servers (e.g. - simulator of the app). Of course, they will use (some of) the same modules, so the question it raises is how to setup maven to build the war and the module jars outside of it, so the other apps (war files deployed on the same server) could have dependencies on them. I couldn't find a good explanation/example how to do that.
Any ideas, links, blogs?
This is really more of a Maven question than Spring Boot. When you have a multi-module project Maven still creates individual artifacts for each module so you can still reference them as dependencies elsewhere.
For example in my setup with Spring boot I have the parent project and the modules underneath it. Most of the modules are jar artifacts, some with dependencies on other modules in the project and of course some external dependencies as well. By using the parent we can standardize some of the versions used in the dependencies using placeholders in the parent. Since the artifacts are still built and published separately you can reference them in other projects, which is what I believe you are asking.
For example (just the main tags and not all of them):
Parent:
<groupId>com.somecompany</groupId>
<artifactId>project-parent</artifactId>
<packaging>pom</packaging>
<version>1.1.2-SNAPSHOT</version>
<modules>
<module>module1</module>
<module>module2</module>
</modules>
Module1:
<parent>
<groupId>com.somecompany</groupId>
<artifactId>project-parent</artifactId>
<version>1.1.2-SNAPSHOT</version>
</parent>
<groupId>com.somecompany.tools</groupId>
<artifactId>project-tools-core</artifactId>
<version>1.1.2-SNAPSHOT</version>
<packaging>jar</packaging>
Module2:
<parent>
<groupId>com.somecompany</groupId>
<artifactId>project-parent</artifactId>
<version>1.1.2-SNAPSHOT</version>
</parent>
<groupId>com.somecompany.apps</groupId>
<artifactId>project-webapp</artifactId>
<version>1.1.2-SNAPSHOT</version>
<packaging>war</packaging>
<!-- dependency on other module -->
<dependency>
<groupId>com.somecompany.tools</groupId>
<artifactId>project-tools-core</artifactId>
<version>${project.version}</version>
</dependency>
Some Other Project:
<groupId>com.somecompany.apps</groupId>
<artifactId>project-webapp-services</artifactId>
<version>1.3.0-SNAPSHOT</version>
<packaging>war</packaging>
<!-- dependency on other module which is published -->
<dependency>
<groupId>com.somecompany.tools</groupId>
<artifactId>project-tools-core</artifactId>
<version>1.1.1</version>
</dependency>
So in this case assuming you had published version 1.1.1 of your parent and its modules you can have another project refer to any of those published artifacts. Maybe it is the release and publishing step you are missing.