How to define parent-version in maven as property? - spring

I'm using the following dependency as parent in my maven pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.6.RELEASE</version>
</parent>
If I define the version as property <version>${spring-boot.version}</version> I'm getting the following error:
Project build error: Non-resolvable parent POM: Failure to transfer
org.springframework.boot:spring-boot-starter-parent:pom:${spring-boot.version}
from http://repo.spring.io/milestone was cached in the local
repository, resolution will not be reattempted until the update
interval of spring-milestones has elapsed or updates are forced.
Original error: Could not transfer artifact
org.springframework.boot:spring-boot-starter-parent:pom:${spring-boot.version}
from/to spring-milestones (http://repo.spring.io/milestone): Illegal
character in path at index 85:
http://repo.spring.io/milestone/org/springframework/boot/spring-boot-starter-parent/${spring-boot.version}/spring-boot-starter-parent-${spring-boot.version}.pom
and 'parent.relativePath' points at wrong local POM
So is it not possible to define the parent version as maven property?

Try updating Maven to 3.2.3.
Check these release notes:
Maven 3.2.1
Maven 3.2.2
There was some work done this front in the latest versions of Maven and it should be possible to do it with version 3.2.1 (at least), but if you're upgrading Maven anyway, go with the latest.

Related

Invalid spring-boot-dependency version when using jgitver and local repo in maven

When I use spring-boot-starter-parent combined with local repository and jgitver I get the following error:
[ERROR] The project tmplsvcpkg:TMPL_SVC_NAME-parent:0.0.0-27-a592e4fb-feature_gitlabci-dirty (/home/user/git/service-template/pom.xml) has 1 error
[ERROR] Non-resolvable parent POM for org.springframework.boot:spring-boot-starter-parent:[unknown-version]: Could not find artifact org.springframework.boot:spring-boot-dependencies:pom:0.0.0-27-a592e4fb-feature_gitlabci-dirty in internal-repository (https://mvnrepo) # org.springframework.boot:spring-boot-starter-parent:[unknown-version], /home/user/git/service-template/.m2/repository/org/springframework/boot/spring-boot-starter-parent/2.2.0.RELEASE/spring-boot-starter-parent-2.2.0.RELEASE.pom, line 3, column 11 -> [Help 2]
Note unknown-version for spring-boot-starter-parent and 0.0.0-27-a592e4fb-feature_gitlabci-dirty for spring-boot-dependencies. The 0.0.0-27-... version is the version calculated by the jgitver. It looks like the version resolution gets messed up somehow. If I change the local repository to any directory outside of my project it starts working again. If I supress jgitver it starts working again. If I define the local repo even deeper in my project (like maven.repo.local=x/y/z/.m2/repository, the error is still present.
I defined the parent in my pom.xml in this way:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
</parent>
And I run my maven in this way:
mvn compile -Dmaven.repo.local=.m2/repository -U
If I add jgitver.skip=true, everything works.
I suspect it might have something to do with the fact that spring-boot-starter parent defines it's parent (spring-boot-dependencies) as relative to it's position:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.0.RELEASE</version>
<relativePath>../../spring-boot-dependencies</relativePath>
</parent>
Has anyone any ideas why it might be happening and how to fix it?
It turns out it's a well known issue and is resolved by a certain configuration of the plugin (you have to exclude the .m2 directory in plugin config). More details are in this issue:
https://github.com/jgitver/jgitver-maven-plugin/issues/60

Maven fails to download parent pom because it appends wrong version?

When maven tries to build a project that includes dependency A, it fails because it can't find the correct version of the parent pom P.
Note that in this case, the child pom A is a different version from the parent. What I see in the logs is that it is trying to download the parent pom, but with the wrong version.
Child pom:
<parent>
<artifactId>foo-parent</artifactId>
<groupId>org.foo</groupId>
<version>3.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>foo-bar</artifactId>
<version>3.0.1</version>
In the logs, the build then shows:
Failed to collect dependencies at org.foo:foo-bar:jar:3.0.1: Failed to read artifact descriptor for org.foo:foo-bar:jar:3.0.1: Could not find artifact org.foo:foo-parent:pom:3.0.1 in nexus
I would've expected it to look for the pom of 3.0.0, not 3.0.1, which does exist in the remote (nexus).

Issue in Jenkins build not Eclipse

In jenkins there are two project A and B both are maven project and both the projects are running fine when do clean and install from the STS.
However,when the same project is refered in jenkins as a maven project.Its not able to resolve the dependency of Project A.
When I put explicitly the Dependency in jenkins .m2 folder repository it works
Projects A jar is created here.
4.0.0
<groupId>com.XYZ.k</groupId>
<artifactId>abc</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>abc</name>
Referring in Project B POM like below.
<dependency>
<groupId>com.XYZ.k</groupId>
<artifactId>abc</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
Problem is coming like not able to resolve dependency:
enter code here
[ERROR] Failed to execute goal on project rpg4xref: Could not resolve dependencies for project com.xyz.xa:B:jar:13.2.00-SNAPSHOT: Failure to find com.xyz.abc:abc:jar:1.0.0-SNAPSHOT in file:/// was cached in the local repository, resolution will not be reattempted until the update interval of localRepsoitory has elapsed or updates are forced -> [Help 1]

artifactory force update of remote repos

I have had a working artifactory for over a year now. I have set up a virtual repo that has my local (company) artifacts, along with the maven repo (https://repo1.maven.org/maven2) and a few others.
I have a working spring boot app, and I am simply updating to the new 2x version (Currently 2.0.0.M6) my POM parent looks like this:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.M6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
When I try and do a mvn install -U I get an error:
[FATAL] Non-resolvable parent POM for org.springframework.boot:myProject:[unknown-version]:
Could not find artifact org.springframework.boot:spring-boot-starter-parent:pom:2.0.0.M6 in central (http://xxx/artifactory/myVirtualRepo/) and 'parent.relativePath' points at no local POM # line 9, column 12
Now when I change that back to my original version (1.5.7.RELEASE) it works fine.
If I manually go and check my artifactory, I do NOT see a 2.0.0.M6 version there. So the error makes sense, but how do I get my Artifactory to "update" or whatever, the newer versions listed on maven central?
Well I am not seeing the artifact you are looking for in Maven central :-)
According to https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-starter-parent/, the artifact's latest version is 1.5.9
If you look at https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent, you can see that the 2.0.0-MX versions are only available on the springio-milestone mirror.
You probably need to add another remote repository that relies on http://repo.spring.io/milestone/, and add it to your virtual repository.
This should fix it.

Spring STS spring boot project maven pom error

Hello I am trying to learn spring boot. I have installed Spring STS
Spring Tool Suite
Version: 3.6.4.RELEASE
Build Id: 201503100339
Platform: Eclipse Luna SR1 (4.4.2)
Java 1.7.
I am trying to create a spring starter project. After I do it with the sts I get the project generated but the Maven pom contains errors.
It always says : Project build error:
Project build error: Non-resolvable import POM: Failure to transfer org.springframework:spring-framework-bom:pom:4.1.6.RELEASE from repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.springframework:spring-framework-bom:pom:4.1.6.RELEASE from/to central repo.maven.apache.org/maven2): The operation was cancelled.
Failure to transfer org.springframework:spring-framework-bom:pom:4.1.6.RELEASE from //repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.springframework:spring-framework-bom:pom:4.1.6.RELEASE from/to central repo.maven.apache.org/maven2): The operation was cancelled.
Project build error: Non-resolvable import POM: Failure to transfer org.springframework.security:spring-security-bom:pom:3.2.7.RELEASE from repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.springframework.security:spring-security-bom:pom:3.2.7.RELEASE from/to central ( repo.maven.apache.org/maven2): The operation was cancelled.
The POM is automatically generated when I create a spring starter project and it always generates that error.
I understand that there is something wrong the the spring files but I don't know how to solve that problem.
Can someone here give me please an advice how to solve this.
Thanks.
Best regeards.
Khelvan
I was getting the same issue while importing maven project from spring initialzr.
Spring Tool Suite 4 Version: 4.1.0.RELEASE
Just add below lines in pom.xml file:-
<properties>
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
</properties>
Happy Coding ;
I had the same problem, using NetBeans 8.1, Maven 3.0.1, and Spring MVC versions 4.0.1 and 4.2.5.
The first solution I found on the web was to update Maven to version 3.3.9, which did not solve my problem. However, with more search I found a useful link. There it explains for including Maven's "bill of materials" (BOM) dependency you can use:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.2.5.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
Before I was missing <type> and <scope> tags in the auto-generated code. After adding them the problem was solved.
Since I am not sure if updating Maven also helped or not, you might also try that.
Check the version of the bom you are using. When I changed mine to 4.3.5.RELEASE, the error went away

Resources