Ive included following lines in my pom.xml
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
The specific spring-core JAR version I want is 4.1.6, but whenever I do an mvn clean install, the dependencies folder under my project in netbeans shows a downgraded version (currently 3.0.7.RELEASE).
I want to know how I can force maven to put 4.1.6.RELEASE jar in my dependencies folder. I've done
mvn dependency:purge-local-repository -DactTransitively=false -DreResolve=false
And I've the folder 4.1.6.RELEASE with correct jar in my local /.m2/repositories folder. I need to access org.springframework.util.MimeType class which is not available in spring-core 3.0.7.RELEASE jar.
See the result of mvn dependency:tree to know if another jar bring back the version 3.0.7. and exclude from this dependency the spring-core
See the same result to know if the right version is present
Add the pom.xml and the result of mvn dependency:tree in the question
Please follow these steps:
Check in .m2 local repository where the Spring 3.0.7 jar is downloaded(It should be under folder org->springframework)
Delete the folder present inside springframework, so that mvn will try to fetch required dependencies.
Let me know if it helps
The issue is that spring-core is a mandatory dependenecy of most spring artifacts. Most likely you are using a dependent artifact e.g spring-context which is of version 3.0.7. Then Maven is fetching spring-core of the same version as the dependent artifact using its transitive dependency mechanism.
To control the version of spring-core you need to move its declaration from the dependencies section to the dependency management section of your pom.xml as follows
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.6</version>
</dependency>
</dependencies>
</dependencyManagement>
Related
I am trying to install spring-security-core to my project and here's how I am doing it in my pom.xml
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
The issue is that when I build the project I see org.springframework.security.spring-security-core with version 4.2.9.RELEASE in my artifacts instead of 5.0.7.RELEASE. My pom.xml is deep down in my build tree and it's a part of a big spring boot project. artifact spring-security-core is not present in any other pom.xml in my tree.
From what I've read so far it looks like this is happening because something in the parent tree is downloading spring-security-core 4.2.9.RELEASE as a dependency without explicitly mentioning it in their pom.xml. How to debug this problem ?
In one of the parent pom.xml there's a dependency like this :
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.3.22.RELEASE</version>
</dependency>
Would that explain why spring-security-core old version is getting downloaded ? Any help is appreciated.
Check the dependency tree with this command
mvn dependency:tree
If spring-context-support also has spring-security, you can exclude that from the dependency by adding exclusions
example
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.3.22.RELEASE</version>
<exclusions>
<exclusion>
<groupId> groupid of the jar to be excluded </groupId>
<artifactId>artifact id of the jar to be excluded</artifactId>
</exclusion>
</exclusions>
</dependency>
Go to the location of parent pom.xml file and as run the command
mvn dependency:tree >> tree.txt
It will create a file with dependency tree. Search for "spring-security-core" you will find which version is downloaded.
There are couple of work around:
You can repeat this to each pom.xml as well to know from where it gets the reference.
If one of the pom referring the version then your dependency will not consider if its got resolve earlier.
Check if any po.xml file referring to any spring security related libraries. If so, what is there version. And if you need then as mentioned by #Vinay, exclude it so your library version gets referred.
If you want to download this version of library then mentioned it at the top, so it gets referred and no other version will downloaded.
There is no relation for spring security with spring-context-code. Refer this maven link.
I'm working first time with Maven project. Just created new Maven project in eclipse and in pom.xml I've added below configuration. Like Spring, log4j's jar version etc
<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>com.LearnJavaSpring</groupId>
<artifactId>TalendJavaSpring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
<properties>
<spring.version>5.1.4.RELEASE</spring.version>
</properties>
</project>
The moment I save my pom.xml file, It automatically creates folder at C:\Users\trisha\.m2 location with respective jars in it, the one I've mentioned in pom.xml.
1) My doubt is, From where maven got these jars automatically in above folder location ? Does maven downloads the dependencies automatically ?
2) Is it correct to think in this way that, Maven parse the pom.xml file when we save that and download all the dependencies or jars mentioned in pom.xml file ?
3) What if I want maven to download jars from the different location from where Maven does ? Does maven automatically downloads the latest jars ?
4) Is that possible to change this default folder location C:\Users\trisha\.m2 to other location ? If yes, How..?
1) My doubt is, From where maven got these jars automatically in above
folder location ? Does maven downloads the dependencies automatically
?
In pom.xml you mention something like this:
<groupId>xx</groupId>
<artifactId>yyy</artifactId>
<version>1.1</version>
It will download the xx version 1.1 library automatically.
Search xx in Maven local repository.
Search xx in Maven central repository.
Search xx in Maven remote repository (if defined in pom.xml).
2) Is it correct to think in this way that, Maven parse the pom.xml
file when we save that and download all the dependencies or jars
mentioned in pom.xml file ?
Yes, exactly.
Reference
3) What if I want maven to download jars from the different location
from where Maven does ? Does maven automatically downloads the latest
jars ?
yes , see the above 2 answers combined. You can also ad jars manually by building path and then selecting the required jars. Better suggestion is always to use maven.
To get the latest Jar there are some parenthesis tweaks which you can find here
4) Is that possible to change this default folder location
C:\Users\trisha.m2 to other location ? If yes, How..?
yes, it is possible.
In your settings.xml change the below lines:<localRepository>C:\Users\me\.m2\repo</localRepository> to point to your desired folder.
I created a small java application using intellij, later I updated that project as Maven project using "Add framework support" option. When I tired to add spring jar file on project I got following error saying,"No files were downloaded for org.springframework:org.springframework.core:3.2.2.RELEASE".
Following are the steps I did to add spring jar files
1)Clicked on File -> Project Structure -> Modules -> Clicked on "+" Sign -> Library -> From Maven
2)Searched for org.springframework.core and selected 3.2.2 Release
3)Downloaded to lib folder under my project.
4)Got Error.
I don't know where it went wrong. I am new to java and spring application.
As already mentioned, Maven downloads dependencies itself (a reason why it's a build automation tool).
To add Spring as a dependency, add this code to Maven's pom.xml (the file is in your module's root directory):
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.2.RELEASE</version>
</dependency>
</dependencies>
Also, delete the lib directory from your project root - Maven doesn't put jars there.
Maven downloads the dependencies automatically, can you try adding this to the pom.xml file. Maven should automatically download the dependencies..
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.2.RELEASE</version>
</dependency>
I am using Maven repository, I am trying to connect my application with MySQL database. I have added the required jar file as Maven dependency in my project.
I am able to build the project successfully but when I run the project it gives classNotFoundException.
I have added the jar location in CLASSPATH.
Gerold Broser is correct on top of that version it should be 5.1.37 not 5.1.37-bin
In maven this is the dependency :
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.37</version>
</dependency>
According to Maven Central the <groupId> for mysql-connector-java ist just mysql, not mysql-connector-java.
As mentioned in soorapadman's answer the (older) <version> is 5.1.37, not 5.1.37-bin, the latest is 6.0.3.
Additional hint: You don't have to declare <packaging>jar and <scope>compile explicitely, since these are the defaults anyway. (Remember Maven's core concept Convention over configuration.)
I am working on porting some legacy code to a new versions . one particular module (slf4j) in which 1.5x versions are incompatible with 1.6x and 1.7x , my problem is a project that my project depends on is included as an jar in the classpath . Is there a way to get around such a problem ?
If there is a direct dependency in pom Maven will use it and omit any transitive dependencies to the same artifact, eg here
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
camel-core has a transitive dependency slf4j-api-1.6.6 but Maven will choose slf4j-api-1.7.5
The way I solved my issue is to redeploy the project that my project depended on . Since it was a jar I had to recreate it in a maven format and add the necessary exclusion statements to stop all transitive dependencies at that level . This may not be best practice but worked in my case . I guess with the newer version of projects being all maven based exclude tags should be enough