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

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).

Related

Arquillian ShrinkWrap cannot find parent with dynamic version

The POM of a submodule starts like that
<project>
<parent>
<groupId>mygroup</groupId>
<artifactId>mygroup-parent</artifactId>
<version>${revision}</version>
</parent>
The property revision is defined in the parents` POM. For Maven this is no Problem, but ShrinkWrap does not read the Project from bottom up.
When i try to find the dependencies with
Maven
.configureResolver()
.workOffline()
.useLegacyLocalRepo(true)
.withMavenCentralRepo(false)
.fromFile(getSettingsFile())
.loadPomFromFile("pom.xml")
.resolve()
.withTransitivity();
it fails with
Could not find artifact mygroup:mygroup-parent:pom:${revision}
Because the revision property is only known in the main module-pom.
Is there a way to point it first to the main pom or to set the property in any otherway?

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

Gradle not handling Maven parent POMs with version-range

I have a Gradle build that needs to fetch dependencies from a Nexus repo that has been populated using Maven. Some of the POMs there use version-ranges when specifying a parent POM.
In my build.gradle I put a dependency:
compile group: 'com.company.platform', name: 'abc-common', version: '[11.0,12.0['
The Gradle logs show that a request is made for the versions of abc-common, and its POM and its parent's POM are fetched:
abc-common-11.0.7-17042111.pom:
<parent>
<groupId>com.company.platform</groupId>
<artifactId>abc-parent</artifactId>
<version>11.0.7-17042111</version>
<relativePath>..</relativePath>
</parent>
abc-parent-11.0.7-17042111.pom:
<parent>
<groupId>com.company.corporate</groupId>
<artifactId>corporate-parent</artifactId>
<version>[11.0.7,11.0.8)</version>
<relativePath/>
</parent>
But Gradle fails to fetch the corporate-parent POM. Instead of requesting what versions are present on the repo, it tries to fetch using the version-range literal:
Loading http://nexus.company.com:8081/.../corporate-parent/[11.0.7,11.0.8)/corporate-parent-[11.0.7,11.0.8).pom
Am I doing something wrong? Is this a known problem with Gradle? Is there a work-around?
Any help is much appreciated. This is a show-stopper for me. If I can't find a solution, it's back to Maven.

Jenkins fails to build multi-module Maven project

I have a multi-module Maven project where I have multiple micro services as modules so I have modules listed in my parent pom.xml like below:
<modules>
<module>core</module>
<module>model-base</module>
<module>module1</module>
<module>module2</module>
...
<module>module5</module>
<module>module7</module>
<module>module6</module>
</modules>
Here the module7 is dependent on module5, 6 so I have dependencies listed like below in my module7 pom.xml:
<parent>
<artifactId>pojectA</artifactId>
<groupId>com.domain</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>module7</artifactId>
<dependencies>
<dependency>
<groupId>com.domain</groupId>
<artifactId>core</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.domain</groupId>
<artifactId>module5</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.domain</groupId>
<artifactId>module6</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
When I run mvn clean package in my local the module5, 6 called before the module7 as expected but in Jenkins it is trying to build module 5 then module7 making build fail saying:
[ERROR] Failed to execute goal on project module7: Could not resolve dependencies for project module7:jar:1.0-SNAPSHOT: Could not find artifact module6:jar:1.0-SNAPSHOT -> [Help 1]
Do I need to run any other jobs or re-order the modules in my pom.xml, how is it differ from local to Jenkins? Appreciate any help on this.
The order of modules is not relevant. Maven recognizes which project depends on which other project(s) and sets the build order in the reactor accordingly. See POM Reference, Aggregation (or Multi-Module):
You do not need to consider the inter-module dependencies yourself when listing the modules, i.e. the ordering of the modules given by the POM is not important. Maven will topologically sort the modules such that dependencies are always build before dependent modules.
Add Pre-Step as per below attached screenshot. This will compile all your top modules.
Then we can execute which ever module we want.
As is probably quite well understood, the issue is that the dependencies between the child modules fail because they aren't installed in the local repository yet (because they are yet to be built). The goal that causes this (for me anyway) is mvn test, which is invoked by mvn package. Your local build probably works because at some point you've done a mvn install and this has bootstrapped your system.
In Jenkins the only way I've found to make these builds work is to use the Pre-build step invoking a Maven target of install, and then build the main step as usual.

How to force maven to always download parent pom

I am using a parent pom to share dependencies and plugins across multiple projects. The parent pom is deployed to our nexus repository. In child project, parent pom is included like this:
<project>
<parent>
<groupId>com.mycompany.app</groupId>
<artifactId>app-parent</artifactId>
<version>1.0.0</version>
</parent>
<groupId>com.mycompany.app</groupId>
<artifactId>app-web</artifactId>
<version>1.2.0</version>
<repositories>
<repository>
<id>my-internal-site</id>
<url>http://nexus/repo</url>
</repository>
</repositories>
</project>
When parent pom gets updated, would like to keep the same version so child project automatically gets the updated dependencies without updates. However, it seems parent pom is not updated even if I use
mvn clean -U
How do I force maven (maven 3) to always download parent pom from remote repo even if it is already in local repository?
If you have defined such parent which is a release it will be downloaded exactly once. Afterwards it will not downloaded a second time cause release are imutable. As already mentioned you mind need to think about using SNAPSHOT's instead.
you should re-install parent project into your local repo, try run mvn install under app-parent directory!
FWIW I had a case where maven was not downloading a parent but just a .lastUpdated file (which listed a download failure). Even if I ran help:effective-pom it seem to just ignore the fact the parent was undownloadable and absent, and continue on its merry way.
Fix was to upgrade from maven 3.3.3 to 3.3.9

Resources