Spring downloading upgraded version automatically - java

In my application I am using grovvy dependency for using a class called GrovvyClassLoader. Earlier I was using spring version 2.2.11.RELEASE and my grovvy was on 2.5.13. Since I have upgraded to spring 2.6.6, it tends to download grovvy version 3.0.10 automatically.
I have tried to use <grovvy.version> tag inside <properties> tag in pom file to prevent spring from downloading grovvy automatically but even that is not helpful. Surprising is the fact that even grovvy dependency in my pom is set to version 2.5.13.
This my pom(parent pom),
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.6</version>
<relativePath/>
</parent>
<properties>
.
.
.
<groovy.version>2.5.13</groovy.version>
</properties>
This is a child pom to the above pom where I am actually setting dependency for grovvy,
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>2.5.13</version>
</dependency>
Can anybody tell me why is spring overriding my version and how can stop it.

Related

Spring dependency not found

I'm very new to Spring, and also Maven. I'm following along with the book Spring Start Here because it seems friendly. The very first project asks us to add a spring-context dependency to a new project (using maven). I'm using the Intellij Idea community version to follow along, as suggested in the book. But on following the instructions to add the dependency I get an error: Dependency 'org.springframework:spring-context:' not found
Here is my pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.myspring</groupId>
<artifactId>start</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
I think the idea is to add spring dependencies one by one in order to see their purpose. The autocompletion in idea shows an error for the lines
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
I have already tried updating the maven>repositories in the ide settings but still get the same error.
Also, I found the page https://mvnrepository.com/artifact/org.springframework/spring-context which seems to suggest I have used the correct groupId and artifactId names
Edit: I just removed the empty version tag in the dependency.
maven usually requires the version tag to specify the version
Most cases where no version is specified are when the project inherits pom files
For example
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
Unlike npm and pip, it does not automatically select the latest version

How to run Spring project on my local machine without Tomcat server by adding Spring Boot dependencies

I am working on a Spring project with many different folder structures inside it. I want to run one of the Spring module folder (project) on my local machine (want to create a local web container through Spring Boot dependency) without tomcat server.
I don't have Tomcat installed in my VMWare. So I have to add Spring Boot dependencies in pom.xml file. What should I do? Which dependencies should I add to run my project in local server?
No need of separate Tomcat installation. Spring Boot comes with embedded Tomcat. You can have parent and web dependency in your pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

Dependency 'org.springframework.boot:spring-boot-starter-security:2.2.6.RELEASE' not found

I am new to Spring so I would really appreciate if anyone of you can help me in this. I am adding a dependency of spring-boot-starter-security with a current version of 2.2.6.RELEASE and my parent is also having the same version. But still am getting an error-
Dependency 'org.springframework.boot:spring-boot-starter-security:2.2.6.RELEASE' not found .Tag name: artifactId Description : The unique id for an artifact produced by the project group, e.g. maven-artifact. Version : 3.0.0+ *
**Sorry in advance for any mistake ! **
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">*
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.arpita</groupId>
<artifactId>security_first</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>security_first</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>
file -> invalidate caches/restart and it will work.
BTW you don't need to specify version for starter POM. If you remove the version tag from security starter , it should work fine.
you no need to mention the version of the spring boot project it will take care by spring boot
add the below dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
finally, update the your project
My suggestion is to install maven yourself.
I have the same problem some times. And I think it is because of the Intellij. So I close the project which is a simple spring boot project to study and install maven by myself instead by Intellij. After configuring the environment variable in window 10, I reopen the project and it appears everything is ok now.
You don't need to mention the version but it depends. Your spring boot parens can have older version or newer version than you specify. If you specity older version it's not compiles. Erwin Smith wrote file -> invalidate caches/restart and it will work. which worked for me, but could not help you if the situation is as I wrote. Check the version in your parent pom if it's newer do invalidate caches/restart otherwise udate version to newer and it should work.

Override spring-boot version from parent POM

I have multiple spring projects that all have the same custom parent POM from which they all inherit their spring-boot version (1.5.18.RELEASE). Only one of the child projects need to be updated to version 2.1.4.RELEASE, but when I import spring-boot-dependencies, the spring-boot dependencies in the child project still remain at version 1.5.18.RELEASE.
Custom Parent POM:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.18.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>services</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Services :: Parent</name>
<description>Parent Project for Services</description>
Child POM:
<parent>
<artifactId>services</artifactId>
<groupId>com.example</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../services/pom.xml</relativePath>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.4.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
You have to update the parent to the 2.1.4.release. This is because there can be lots of development problems if the child and parent are not in sync.
Tip: You can delete the version tag in the child dependencies.
spring-boot-starter-parent not only defines dependencies but also configures plugins and ships properties. Because you are upgrading from Spring Boot 1.5.X to Spring Boot 2.X it most likely won't be enough just to bump versions, there are incompatible changes between major releases e.g. Spring Boot 1.5.X is Java 6+ but Spring Boot 2.X is Java 8+.
You should use spring-boot-starter-parent-2.1.4.RELEASE as a parent in your child pom.xml. Your current approach is tinkering, follow the Spring Boot docs and set up child module as a proper Spring Boot 2.X module or you will waste a lot of time debugging problems caused by partial setup.

Maven - how to work with multiple versions of dependencies?

I have project which used JIRA REST Java Client. It worked fine until I tried to integrate it with Spring Boot. Since that I am not able to invoke createWithBasicHttpAuthentication from AsynchronousJiraRestClientFactory without error. I get:
ClassNotFoundException: org.apache.http.util.Args
So I added HttpComponents Core blocking I/O(httpcore) dependency to my pom.xml, but I after that I got
ClassNotFoundException: org.apache.http.nio.NHttpMessageParserFactory
Which I resolved with adding HttpComponents Core non-blocking I/O(httpcore-nio) to pom.xml. Now I have
NoSuchMethodError: org.apache.http.nio.client.HttpAsyncClient.start()V
I've compared dependency:tree when project has spring boot parent and when it's commented out. It shown me that adding spring boot parent changes versions of my dependencies. You can check diff here( on left without spring boot, on right with spring boot)
It seems that JIRA REST Java Client need older versions of some dependencies.
How can I solve this problem?
pom.xml
...
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.0.0.RELEASE</version>
</parent>
...
<dependencies>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-core</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore-nio</artifactId>
<version>4.3</version>
</dependency>
</dependencies>
...
I was able to fix runtime in my Spring Boot application by overriding these properties in my pom.xml
<properties>
<httpasyncclient.version>4.0-beta3-atlassian-1</httpasyncclient.version>
<httpclient.version>4.2.1-atlassian-2</httpclient.version>
</properties>
Note that there can be other problems if you decide to use http-client and/or httpassync client in your project (eg. using RestTemplate).
Atlassian should definitely upgrade the dependencies.

Categories

Resources