Project build error: Non-resolvable parent POM fo - java

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

Related

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

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

gradle doesn't resolve placeholder from parent properties in dependency version that is inside library that I specified in build.gradle

I have one interesting question about resolving dependencies versions by gradle. Here is my situation. I deployed my libraries to nexus. In this process I used the flatten-maven-plugin and resolveCiFriendliesOnly flattenMode. As result I have parent pom file and child pom files in nexus.
parent pom file from source:
<groupId>ru.example</groupId>
<artifactId>example-parent</artifactId>
<version>${revision}${changelist}</version>
<packaging>pom</packaging>
<properties>
<revision>0.0.1</revision>
<changelist>-SNAPSHOT</changelist>
<version.base>${revision}${changelist}</version.base>
<example-child.version>${version.base}</example-child.version>
<example-child-dependency.version>${version.base}</example-child-dependency.version>
</properties>
child pom file from source
<parent>
<groupId>ru.example</groupId>
<artifactId>example-parent</artifactId>
<version>${revision}${changelist}</version>
<relativePath>..</relativePath>
</parent>
<artifactId>example-child</artifactId>
<version>${example-child.version}</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>ru.example</groupId>
<artifactId>example-child-dependency</artifactId>
<version>${example-child-dependency.version}</version>
</dependency>
</dependencies>
parent pom file from nexus
<groupId>ru.example</groupId>
<artifactId>example-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<version.base>0.0.1-SNAPSHOT</version.base>
<revision>0.0.1</revision>
<changelist>-SNAPSHOT</changelist>
<example-child.version>${version.base}</example-child.version>
<example-child-dependency.version>${version.base}</example-child-dependency.version>
<properties>
child pom file from nexus
<parent>
<groupId>ru.example</groupId>
<artifactId>example-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<groupId>ru.example</groupId>
<artifactId>example-child</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>ru.example</groupId>
<artifactId>example-child-dependency</artifactId>
<version>${example-child-dependency.version}</version>
</dependency>
</dependencies>
After that I try to build java application with gradle. In build.gradle file of this application I have such line:
dependencies {
implementation("ru.example:example-child:0.0.1-SNAPSHOT")
}
And build fails with error:
> Task :java_application:compileJava
Resolving global dependency management for project 'java_application'
Errors occurred while build effective model from /u01/jenkins_slave/.gradle/caches/modules-
2/files-2.1/ru.example/example-child/0.0.1-
SNAPSHOT/809129e53f76bfb7b6a141e9aeb8ffb1a692e76c/example-child-0.0.1-SNAPSHOT.pom:
'dependencies.dependency.version' for ru.example:example-child-dependency:jar must be a
valid version but is '${example-child-dependency.version}'. in ru.example:example-
child:0.0.1-SNAPSHOT
Why gradle doesn't resolve placeholder of child project dependency?
gradle appearently does not evaluate ${example-child-dependency.version} and you might have to build with mvn in order to produce consumable/static *.pom for gradle. I mean, most likely mvn would evaluate *.pom, while gradle doesn't.
And that might rather be:
<artifactId>example-child-dependency</artifactId>
<version>${version.base}</version>

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.

How to update the dependency version in the parent pom when building in Jenkins

I have a project with the following pom :
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>2.5.1-RELEASE</version>
</parent>
<groupId>com.bb.cc.dd</groupId>
<artifactId>Proj1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>bla bla bla</name>
<description>abcfgd</description>
<!-- Configuration of repositories for dependency resolution -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>aa.bb.cc.dd</groupId>
<artifactId>dependencyProj</artifactId>
<version>2.0.0</version>
<type>war</type>
</dependency>
</dependencies>
</dependencyManagement>
</project>
What I am trying to achieve :
When I start a build in Jenkins for Proj1,I should have an option to start a build for dependencyProj and if that succeeds insert the new version(2.0.1) in the pom of the Proj1 and complete the build for Proj 1.So the updated pom (release version) should look like this (before the maven plugin updates it for the development iteration) :
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>2.5.1-RELEASE</version>
</parent>
<groupId>com.bb.cc.dd</groupId>
<artifactId>Proj1</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<name>bla bla bla</name>
<description>abcfgd</description>
<!-- Configuration of repositories for dependency resolution -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>aa.bb.cc.dd</groupId>
<artifactId>dependencyProj</artifactId>
<version>2.0.1</version>
<type>war</type>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Note : I tried the "Trigger build" option from the main project and the Post Build Step "Build other projects" from dependency project but none of them update the versions when cheking in to git.Just to add i used the maven release plugin here.
Is it possible to configure jenkins to update the version of the dependent projects in the pom?

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