i'm facing a build error in maven, which i'm unable to explain, my project layout is:
root
|--parent
|--project
where root (aggregator) and project both use "parent" as their parent.
i used this layout in another project, which maven is able to build.
however, in this project, if i'm trying to build, i get a failure on non-resolvable parent pom:
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for maven.test:maven-test-project:9.9.9-SNAPSHOT: Could not find artifact maven.test:maven-test-parent:pom:9.9.9-SNAPSHOT and 'parent.relativePath' points at wrong local POM # line 11, column 10
if i remove the parent node from the root (aggregator) pom, maven is able to build the project successfully.
if i use an older version of maven (3.3 instead of 3.6) the project is built successfully as well.
here are the poms for all 3 projects:
root
<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>
<groupId>maven.test</groupId>
<artifactId>maven-test</artifactId>
<version>9.9.9-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Maven Test</name>
<parent>
<groupId>maven.test</groupId>
<artifactId>maven-test-parent</artifactId>
<version>9.9.9-SNAPSHOT</version>
<relativePath>parent/pom.xml</relativePath>
</parent>
<modules>
<module>parent</module>
<module>project</module>
</modules>
</project>
parent
<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>maven.test</groupId>
<artifactId>maven-test-parent</artifactId>
<version>9.9.9-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Maven Parent</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
</project>
project
<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>
<artifactId>maven-test-project</artifactId>
<version>9.9.9-SNAPSHOT</version>
<name>Maven Project</name>
<parent>
<groupId>maven.test</groupId>
<artifactId>maven-test-parent</artifactId>
<version>9.9.9-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
</project>
There's a conception issue.
"root" cannot be at the same time a parent and child of the same Maven module "parent".
Related
I have a project demo-parent which contains 2 subprojects child1 and child2.
demo-parent is building a pom.
child1 and child2 are building one jar each. And all these are getting uploaded to the artifactory.
demo-parent(also used flatten plugin)
<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>
<groupId>com.demos</groupId>
<artifactId>demo-parent</artifactId>
<packaging>pom</packaging>
<version>${revision}</version>
<properties>
<revision>1.0-SNAPSHOT</revision>
</properties>
...
</project>
child1 and child 2
<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>
<groupId>com.demos</groupId>
<artifactId>child1</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>com.demos</groupId>
<artifactId>demo-parent</artifactId>
<version>${revision}</version>
</parent>
<properties>
<revision>1.0-SNAPSHOT</revision>
</properties>
...
</project>
This project is building and uploading fine. Now when I use this child1 or child2 as a dependency in other projects, it fails with the error:
Failed to execute goal on project maven-webapp: could not resolve dependencies for the project com.demos:maven-webapp:war:1.01: Failed to collect dependencies at com.demos:child1:jar:1.0-SNAPSHOT: Failed to read artifact descriptor for com.demos:child1:jar:1.0-SNAPSHOT: Could not find artifact com.demos:demp-parent:pom:{revision} in artifactory .
I am not getting why it is searching for com.demos:demo-parent:pom:{revision}, even if searching why revision is not getting replaced by 1.0-SNAPSHOT as I have used <revision>1.0-SNAPSHOT</revision> in child1.
I have 2 maven projects in- parent and child, both having 0.0.1-SNAPSHOT.
The pom of parent:
<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.tmn</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>parent</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
The pom of child:
<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.tmn</groupId>
<artifactId>child</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>com.tmn</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<name>child</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
I updated the version of the parent pom to some release version, say 1.0.0 and did mvn clean install on my parent. So, my maven local repo contains the released pom. Now, I want to update the parent.version and the version of my child pom. I run
mvn versions:update-parent -DparentVersion=1.0.0 -DgenerateBackupPoms=false -Dmaven.repo.local=/path/to/repo
I want it to blindly update the parent.version to the parentversion I supply in my command. But I get this WARNING and it is not updated.
artifact com.tmn:parent: checking for updates
[WARNING] Not updating version: could not resolve any versions
There is a similar issue logged here but I didn't understand the solution to this: https://github.com/mojohaus/versions-maven-plugin/issues/121
I have a test project which is based on a parent project. This parent is build beforehand and is available on local artifactory server. The parent project is not available locally and this should stay this way.
As you see I am not using the relativePath element.
Still, when running "mvn clean install -U" I get an error about missing parent.
[ERROR] Non-resolvable parent POM for com.test.example:test:0.0.1-SNAPSHOT: Could not find artifact com.test:projects-parent:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM # line 6, column 10 -> [Help 2]
The test project pom.xml is:
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.example</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>test</name>
<parent>
<groupId>com.test</groupId>
<artifactId>projects-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<dependencies>
...
</dependencies>
<build>
...
</build>
</project>
Here is the parent pom.xml
<?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 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>2.0.3.RELEASE</version>
</parent>
<groupId>com.test</groupId>
<artifactId>projects-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
</project>
According to this, the default value for <relativePath> is ../pom.xml, so Maven will look locally first.
If you want to force the lookup to occur in your repository manager, use this trick:
<parent>
<groupId>com.test</groupId>
<artifactId>projects-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath/> <!— This forces a lookup against the repo —>
</parent>
I'm new to Maven, so I'm wondering why Maven will actually download the parent.
Here is my sample directory:
├── hazriq-module
│ ├── document-generator
│ | ├── src folder
│ | └── pom.xml (document-generator)
│ └── pom.xml (hazriq-module)
└── pom.xml (hazriq-parent)
My hazriq-parent .pom file:
<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>
<groupId>com.hazriq</groupId>
<artifactId>hazriq-parent</artifactId>
<version>${hazriq.verion}</version>
<packaging>pom</packaging>
<properties>
<hazriq.verion>1.0.0</hazriq.verion>
</properties>
<modules>
<module>hazriq-module</module>
</modules>
</project>
My hazriq-module .pom file:
<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>com.hazriq</groupId>
<artifactId>hazriq-parent</artifactId>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>hazriq-module</artifactId>
<name>hazriq-module</name>
<packaging>pom</packaging>
<version>${hazriq.verion}</version>
<modules>
<module>document-generator</module>
</modules>
</project>
My document-generator .pom file:
<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>com.hazriq</groupId>
<artifactId>hazriq-module</artifactId>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>com.hazriq.hazriq-module</groupId>
<artifactId>document-generator</artifactId>
<dependencies>
...
</dependencies>
When I try to run mvn install:
$ mvn install
[INFO] Scanning for projects...
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project com.hazriq:hazriq-module:${hazriq.verion} (C:\development\hzrqmvn\hazriq-module\pom.xml) has 1 error
[ERROR] Non-resolvable parent POM: Failure to find com.hazriq:hazriq-parent:pom:1.0.0 in https://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 and 'parent.relativePath' points at wrong local POM # line 3, column 10 -> [Help 2]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
My questions are:
1. Why will Maven actually go and try to download the hazriq-parent? from the repo.maven.apache.org? (Refer to the output of my mvn clean install above.
2. How can I successfully build my project?
Why wouldn't it? If you build a module, all its parent modules have to be resolved recursively. Same goes for all dependencies.
This means those artefacts have to be either in the configured remote repository (Maven Central by default) or your local one. You can add it to your local repository by doing a mvn install.
The reason my one is failing is because of the placeholder in the <version>.
I changed my parent .pom to:
<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>
<groupId>com.hazriq</groupId>
<artifactId>hazriq-parent</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<modules>
<module>hazriq-module</module>
</modules>
</project>
My module .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>com.hazriq</groupId>
<artifactId>hazriq-parent</artifactId>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>hazriq-module</artifactId>
<name>hazriq-module</name>
<packaging>pom</packaging>
<version>1.0.0</version>
<modules>
<module>document-generator</module>
</modules>
</project>
My document-generator .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>com.hazriq</groupId>
<artifactId>hazriq-module</artifactId>
<version>1.0.0</version>
</parent>
<groupId>com.hazriq.hazriq-module</groupId>
<artifactId>document-generator</artifactId>
</project>
A good read on this issue: https://jeanchristophegay.com/maven-unique-version-multi-modules-build-en/
Suppose there are two 3rd-party Maven artifacts with the following POM.XMLs:
artifact1 POM.XML:
<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>group1</groupId>
<artifactId>artifact1</artifactId>
<version>${artifact1.version}</version>
<packaging>pom</packaging>
<properties>
<artifact1.version>0.0.1-SNAPSHOT</artifact1.version>
</properties>
<modules>
<module>../artifact2</module>
</modules>
artifact2 POM.XML:
<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>
<artifactId>artifact2</artifactId>
<parent>
<groupId>group1</groupId>
<artifactId>artifact1</artifactId>
<version>${artifact1.version}</version>
<relativePath>../artifact1</relativePath>
</parent>
They are built normally using
mvn clean install
Now, if I try to reuse artifact2 in a 3rd POM.XML:
<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>group2</groupId>
<artifactId>artifact3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>group1</groupId>
<artifactId>artifact2</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
After executing...
mvn clean install
...the build fails trying to locate group1:artifact1:pom:${artifact1.version}
[ERROR] Failed to execute goal on project artifact3: Could not resolve dependencies for project group2:artifact3:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at group1:artifact2:jar:0.0.1-SNAPSHOT: Failed to read artifact descriptor for group1:artifact2:jar:0.0.1-SNAPSHOT: Could not find artifact group1:artifact1:pom:${artifact1.version} in central (https://repo.maven.apache.org/maven2) -> [Help 1]
And setting the property in the command-line doesn't work either:
mvn clean install -Dartifact1.version=0.0.1-SNAPSHOT
How can I use artifact2 as a dependency?
<parent> doesn't allow variables. Because in order to get a list of variables Maven first has to build Effective POM and for this it needs to resolve parents.
Even if there is some version of Maven that allowed such module to be installed it's not a working solution in general. Maven's ideology is that all the dependencies (including parent) could be downloaded from a repo and are not necessarily present on local FS/in the reactor. With properties in the parent dependency definition you violate this rule.