How to setup circular reference in maven modules? - maven

I have this problem with building a maven project...
A mvn project parent is set like this:
<groupId>com.company.system.ping</groupId>
<artifactId>system-ping</artifactId>
<name>system-ping</name>
<parent>
<artifactId>parent_lvl_1</artifactId>
<groupId>com.company.system</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
Then I look for said parent's POM and find this:
<groupId>com.company.system</groupId>
<artifactId>parent_lvl_1</artifactId>
<packaging>pom</packaging>
<name>_proj_test</name>
<version>1.0-SNAPSHOT</version>
<parent>
<artifactId>parent_lvl_0</artifactId>
<groupId>com.company</groupId>
<version>1</version>
</parent>
I finally look at the first parent and see this:
<groupId>com.company</groupId>
<artifactId>parent_lvl_0</artifactId>
<packaging>pom</packaging>
<name>_main</name>
<version>1</version>
<description>The whole Projects</description>
Now I check the modules:
<modules>
<module>../_proj_test</module>
...
</modules>
The first parent module is referencing a child! So when I try
mvn install
on '_main' I get this:
[ERROR] The project com.company.system:_proj_test:1.0-SNAPSHOT (C:\...\pom.xml) has 1 error
[ERROR] Non-resolvable parent POM: The repository system is offline but the artifact com.company:_main:pom:1 is not available in the local repository. and 'parent.relativePath' points at wrong local POM # line 4, column 10 -> [Help 2]
[ERROR]
I translate this to: you parent requieres a module which requires you back. If I comment out everything in modules I can install everything correctly but this is NOT OK for me! How can I build the parent without building the module dependencies?
Thank you!

The config looks very weird to me, mainly because your '_proj_test' which is a child for '_main' is located on the same level.
How can I build the parent without building the module dependencies?
Try mvn -N install.
As for the project structure, I'd do it in such a way:
1) $basedir with '_main' pom.xml which should contain this
<modules>
<module>_proj_test</module>
</modules>
2) $basedir/_proj_test with '_proj_test' pom.xml which should contain this
<modules>
<module>system-ping</module>
</modules>
3) $basedir/_proj_test/system-ping with 'system-ping' pom.xml (with correct groupId of parent - com.company.system instead of com.company)

Related

mvn Deployment failed: repository element was not specified in the POM

When I run mvn clean deploy on my project I get an error
Also my project in eclipse displays the following errors which I don't know if they are related to my current problem.
Project configuration not up-to-date with pom.xml
plugin configuration not covered by lifecycle configuration
In addition my eclipse doesn't seems to compile the files correctly. My SpringBoot java files aren't being compiled as java files. I can tell because if I deliberately induce syntax errors, there isn't a compilation error. This is all run on eclipse EE and is part of a maven project so I don't even know if a source folder is needed.
Also I'm displaying my main pom.xml file below and it has compilation errors on "pom" and both "&ndash"
I've tried the following solutions
Eclipse Blue, Maven: Project configuration is not up-to-date with pom.xml
Failed to resolve version for org.apache.maven.archetypes
repository element was not specified in the POM inside distributionManagement element or in -DaltDep loymentRepository=id::layout::url parameter
<?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.fanniemae.dfc</groupId>
<artifactId>dfc_app</artifactId>
<packaging>pom</packaging>
<version>0.0.1-SNAPSHOT</version>
<modules>
<module>dfc_angular</module>
<module>dfc_springBoot</module>
</modules>
<!--<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3RELEASE</version>
<relativePath/> <!– lookup parent from repository
–>
</parent>-->
</project>
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project dfc_app: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter
mvn deploy will deploy the produced artifact to a Maven Repository.
To do so it needs the configuration to which repository it must be deployed and this is missing.
But I assume that you don't want to deploy it to a repository but just build it.
That's mvn install This will install it in your local repository.
Maybe you should start with reading the docs: https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

Build child module without building parent module if there is some changes in parent pom

I have a multi module project with more than 70 modules and it takes 3 Hrs to build the project with tests.
Parent pom.xml
...
<version>${revision}</version>
<properties>
<app.version>1.0</app.version
<properties>
.....
<modules>
<module>a<module>
<module>b<module>
<module>c<module>
.....
...
Child pom.xml
<parent>
<groupId>com.test</groupId>
<artifactId>parent</artifactId>
<version>${revision}</version>
</parent>
<artifactId>b</artifactId>
How to build only module b only if we change the version number in parent pom.xml
After upgrading the parent POM to a new version (and the reference to it in b's pom.xml), you could run :
mvn --projects b <maven_phase_you_want> # or mvn -pl b [...]
From Maven's help :
-pl,--projects <arg> Comma-delimited list of specified
reactor projects to build instead
of all projects. A project can be
specified by [groupId]:artifactId
or by its relative path
However, this only works if the old version of your parent POM is already in your local repository, or at least is available (it have been deployed on a repository manager). Otherwise, you'll get an error because, even if specifying --projects b, Maven will try to resolve parent POM (that he won't find) for other modules a and c.

unable to resolve Maven dependency placeholder reference value

my project has dependencies on some framework jars:
<groupId>my-compamy</groupId>
<artifactId>my-project</artifactId>
<version>1.0</version>
<dependency>
<groupId>my-company</groupId>
<artifactId>child-jar1</artifactId>
<version>2.0</version>
</dependency>
recently the framework team changed their packaging, in the repository, they put a parent pom (used to be separated child jars) like this:
<properties>
<reivison>2.0</revision>
</properties>
<groupId>my-company</groupId>
<artifactId>framework-parent</artifactId>
<packaging>pom</packaging>
<version>${revision}</version>
<modules>
<module>child-jar1</module>
</modules>
in the child-jar1 pom:
<parent>
<artifactId>framework-parent</artifactId>
<groupId>my-company</groupId>
<version>${revision}</version> <!-- can find the value! -->
</parent>
<artifactId>child-jar1</artifactId>
<packaging>jar</packaging>
When I build my-project, I got error message like:
... Failed to collect dependencies at my-company:child-jar1:jar:2.0.
... cuased by: could not find framework-parent:pom ${revision}
and the child-jars are not downloaded.
it looks that it is the placeholder in the child pom caused the problem: my-project could not resolve the placeholder value in the dependent(chiild-jar1)'s pom.
tried multiple approaches to resolve the referenced value from my-project side but nothing worked. Can this be resolved from my-project side without altering any dependency framework's setting? Please help.
There is a way to replace the palceholder with concrete value: add flatten-maven-plugin in the framework parent pom file build section (first to run) - this does not impact the framework's functionality but has to be done in the framework side. I gave this suggestion to the framework owner and they took it. It works.
Thanks to all comment providers!

Can modules referring to parent pom by relative path be depended on by 3rd parties?

I have a parent module, which defines its version as follows:
<groupId>org.group</groupId>
<artifactId>parent-id</artifactId>
<packaging>pom</packaging>
<version>${library.version}</version>
<properties>
<library.version>1.0.0</library.version>
</properties>
Then I have a sub module, which points to its parent as follows:
<parent>
<groupId>org.group</groupId>
<artifactId>parent-id</artifactId>
<version>${library.version}</version>
<relativePath>../../</relativePath>
</parent>
<artifactId>child-id</artifactId>
<packaging>jar</packaging>
And I depend on it in my other projects like so:
<dependency>
<groupId>org.group</groupId>
<artifactId>child-id</artifactId>
<version>1.0.0</version>
</dependency>
This results in the following error for me:
Failed to read artifact descriptor for org.group:child-id:1.0.0: Failure to find org.group:parent-id:pom:${library.version}
Can this problem be solved without resorting to mvn versions:set in my multi module project to manage explicit versions in all poms?
/edit: currently solved this problem with a workaround that makes using mvn versions:set a little easier.

Maven can't get access to parent properties

I have following structure:
parent-pom (pom)
|
- base-component (with <parent> parent-pom </parent>)(pom)
|
-- child-component (with <parent> base-component </parent>)(jar)
-- some-folder/another-child (with <parent> base-component </parent>)(jar)
In parent-pom I have properties with versions like
<properties>
<product-version>3.7.8</product-version>
</properties>
When I build child-component and use there ${product-version} - it is built without errors.
But when I trying to build another-child(with child-component as dependency) - maven can't read ${product-version} or throws an error Could not find artifact base-component even if I set <relativePath>.
I think the problem is folder between base-component and another-child, but I can't move it to level up.
Any ideas?
Make sure that the relative path is set correctly in the another-child module. Since it's under another directory, its parent base-component should be up by two directories:
<parent>
<groupId>...</groupId>
<artifactId>base-component</artifactId>
<version>...</version>
<relativePath>../../pom.xml</relativePath>
</parent>
Also make sure that in the base-component project, the module definition includes the additional path for another-child, so it should be something like:
<modules>
<module>child-component</module>
<module>some-folder/another-child</module>
</modules>
Before building another-child (or any other sub-module), try to build (mvn install) the whole project, starting at the root parent.
Try setting on the pom the project directory.
Parent:
<properties>
<main.basedir>${project.basedir}</main.basedir>
</properties>
Sibbling/children:
<properties>
<main.basedir>${project.parent.basedir}</main.basedir>
</properties>
children/ grandchildren:
<properties>
<main.basedir>${project.parent.parent.basedir}</main.basedir>
</properties>

Resources