Dependency not found error in pom.xml in a maven project - java

I created a maven project.
It is getting an error because of this dependency in the POM file.
POM.XML
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
<relativePath/>
</parent>
Project 'org.springframework.boot:spring-boot-starter-parent:2.2.0.RELEASE' not found. It gives error.
error description:
Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.2.0.RELEASE from/to central
Thank you for your help.

do this:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2enter code here.6.RELEASE</version>
<type>pom</type>
</dependency>
Note: Create Maven or anyone for spring using spring initializr(https://start.spring.io), so you will never face these kinds of problems

Related

Generated Spring pom.xml causes error "Error while fetching http://maven.apache.org/POM/4.0.0"

(I am aware that there are similar questions - but having tried the solutions to them I am still stuck)
I am trying to use the Demo project from Spring and cannot get the generated pom.xml to work under IntelliJ, I tried the solution suggested by IntelliJ to resolve URI is not registered - but this simply causes the titular error.
At first I believed this to be a network error, but upon loading the webpage in a browser it 404s. This leads me to believe it is an issue with my project setup in some way.
I imported the project by opening the pom.xml in IntelliJ and then clicking 'Open as Project'.
My pom.xml is as follows:
<?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.3.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>prs.ttg.spring</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>test</name>
<description>Test project for Spring Boot</description>
<properties>
<java.version>15</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
None of the dependencies get loaded and I cannot for the life of me find a working solution to this.
I appreciate help, and understand if this is just a stupid question - I'm a stupid person
Make sure you have Maven bundled plugin enabled in Preferences | Plugins. If you are behind proxy - set up proxy settings in IDE: https://www.jetbrains.com/help/idea/settings-http-proxy.html
If you have Maven plugin enabled open project via File | New | Project from Existing Sources and select pom.xml file to import project from.

Why you don't need to specify the version for some dependencies in Spring Boot project?

I'm learning about Spring Boot and I see that you don't need to specify the version for some dependencies, but you need to specify the version for other dependencies. Where does the version of this dependencies comes from?
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.dgs</groupId>
<artifactId>n-tier-and-jackson</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>n-tier-and-jackson</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<paypal.rest.easy.version>2.3.3-RELEASE</paypal.rest.easy.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>com.paypal.springboot</groupId>
<artifactId>resteasy-spring-boot-starter</artifactId>
<version>${paypal.rest.easy.version}</version>
</dependency>
...
For example in this code you don't need to specify the version for spring-boot-starter-jersey, but you need to specify the version for resteasy-spring-boot-starter. Where does the version for spring-boot-starter-jersey comes from? Thank you!
Dependencies versions are declared in the pom file that you have specified in the parent section of your pom file

Project build error: Non-resolvable parent POM fo

This is my first project using spring boot. So I tried to update the pom.xml with the parent as below:
<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.in28minutes.springboot</groupId>
<artifactId>first-springboot-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot-in-10-steps</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
However, I got an error in line:
Project build error: Non-resolvable parent POM for
com.in28minutes.springboot:first-springboot-project:0.0.1-SNAPSHOT:
Could not find artifact
org.springframework.boot:spring-boot-starter-parent:pom:2.0.0.BUILD-SNAPSHOT
and 'parent.relativePath' points at wrong local POM
any help please !
There no such thing as 2.0.0-BUILD-SNAPSHOT, you might have copied this directly from a Spring Boot project?
The released version of Spring Boot can be seen here;
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent
If you want the latest verison, <version>2.0.6.RELEASE</version> will work.
If you want to use SNAPSHOT, or Milestone releases see the documentation
https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/html/getting-started-installing-spring-boot.html#getting-started-maven-installation
which specifies the required repos.
Change 2.0.0.BUILD-SNAPSHOT to 2.0.0.RELEASE

Build War with multi module project

I have a multi module maven project with three different modules Module-Data, Module-Domain, Module-Web. All three projects are spring boot projects, however Module-Web is the web component of the project that handles everything web oriented which I want to build a war file for. I have a parent project with the following pom file which contains no code.
<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.somename</groupId>
<artifactId>My-Project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>module-data</module>
<module>module-domain</module>
<module>modele-web</module>
</modules>
Module-Domain depends on Module-Data and Module-Web depends on both Module-Data and Module-Domain. The problem I'm having is that when I try to build the project using maven it fails when building the Module-Domain with the following erros:
package com.somename.data.model does not exist // class file with this error
Module-Domain class files that imports from the Module-Data project fails with this error. I suspect this is because maven is not adding the Module-Data jar to the Module-Domain when building although its referenced in its pom file. How can I solve this problem and generate a war file with all dependencies?
Module-Domain pom.xml:
<dependency>
<groupId>com.somename.data</groupId>
<artifactId>module-data</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
Module-Web pom.xml
<dependency>
<groupId>com.somename.data</groupId>
<artifactId>module-data</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.somename.domain</groupId>
<artifactId>module-domain</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
This is a simple straight-forward approach that you are using. Should not cause a problem.
Module-Domain pom.xml:
<parent>
<groupId>com.somename</groupId>
<artifactId>My-Project</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>com.somename.data</groupId>
<artifactId>module-data</artifactId>
<version>0.0.1-SNAPSHOT</version> <!-- Make sure this version is correct -->
</dependency>
</dependencies>
Module-Web pom.xml:
<parent>
<groupId>com.somename</groupId>
<artifactId>My-Project</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>com.somename.domain</groupId>
<artifactId>module-domain</artifactId> <!-- pulls "module-data" as well : transitive dependency -->
<version>0.0.1-SNAPSHOT</version> <!-- Make sure this version is correct -->
</dependency>
</dependencies>
Do maven clean compile on the parent project that would build all the modules.
If you still see any compilation issues, you would need fix the source code.

Error parsing lifecycle processing instructions when using spring-boot-starter-parent 1.4.3 with maven (works well on 1.4.2)

The following pom.xml does not work for 1.4.3.RELEASE of spring-boot-starter-parent, and it says "Error parsing lifecycle processing instructions". But once I change the version to 1.4.2, the issue is automatically resolved.
So my question is, is the 1.4.3 version incompatible with the pom schema definition?
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
</parent>
<packaging>war</packaging>
<artifactId>SpringCloudConfig</artifactId>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
</dependencies>
Deleting the entire .m2 folder or the specific jar files might help, in case there are corrupted jar files in your maven local repository. I solved the problem by removing the C:\Users\yourUserName\ .m2 folder. And then switch back to Eclipse Mars.(I was using Eclipse Neon when the problem occurs). Eclipse Mars is compatible with both the 1.4.2 and 1.4.3 version.
There is no need to delete entire repo. This is caused by corruption of some spring related jars. Just delete following folder from local m2 repo and update Maven project
.m2\repository\org\springframework
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
org.springframework.boot
spring-boot-starter-parent
1.4.3.RELEASE
test
test
0.0.1-SNAPSHOT
test
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
</dependencies>

Categories