I have 3 projects Parent,Child,SubChild.
Project Parent pom is as follows:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
</parent>
<groupId>mu.parent</groupId>
<artifactId>parent-system</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
....
Project Child pom is defined below and its Parent is defined follows:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>mu.parent</groupId>
<artifactId>parent-system</artifactId>
<version>1.0</version>
</parent>
<groupId>mu.dummy.child</groupId>
<artifactId>child-backend</artifactId>
<name>child-backend</name>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>subChild-app</module>
</modules>
...
Now subChild pom is as follows and the child is defined as parent for subChild :
<parent>
<groupId>mu.dummy.child</groupId>
<artifactId>child-backend</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>mu.dummy.subchild</groupId>
<artifactId>subchild-backend</artifactId>
<name>subchild-backend</name>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>org.project.test</groupId>
<artifactId>project</artifactId>
<version></version> --version of parent-system???
</dependency>
</dependencies>
Is it possible to get version of parent-system(1.0) in subchild-backend please without hardcoding it?
You can use CI-friendly versions and write ${revision} for the versions, setting this property in the main pom (from which you build everything).
You need to use the flatten Maven plugin, though, to get proper POMs in the repository.
I asked a similar question a while back and determined that tthe groovy-maven-plugin works for this. See this answer.
Related
Assuming I have Maven pom (let's say Maven 3.8) like this:
<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>some.group</groupId>
<artifactId>my-parent</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>some.group</groupId>
<artifactId>my-artifact</artifactId>
</dependency>
</dependencies>
</project>
...where my-parent has a dependency management section, maybe bom imports and further parents up the chain with it's own dependency management sections, how can I find the source of the version of some.group:my-artifact that actually used in the child pom?
Let's say, I build this and see that the effective pom contains version 1.2.3 for this artifact, how can I find out the pom that actually contains that version?
I have the following project structure:
Parent
-- Module A
-- Module B
-- Module C
-- Module D
Parent has the following properties:
<properties>
<ModuleA.version>1.8</ModuleA.version>
</properties>
In module C, I am specifying dependency of A, using ${ModuleA.version}.
Module D depends on Module C, which in turn depends on Module A. Now, when I am running mvn clean install on Module D, considering that they share the same parent, I am expecting that the properties defined in parent would be available and hence ModuleA.version would be resolved to 1.8 and used.
However, the command is failing with the error:
The following artifacts could not be resolved: ModuleA:jar:${ModuleA.version}
Can someone help me with what I am missing here.
In all the modules I am specifying parents correctly.
That is: Module C and Module D mentions Module B as parent. Module B and Module A mentions Parent as parent.
Actual POM's below:
Parent:
<groupId>com.dummy</groupId>
<artifactId>parent</artifactId>
<version>0.15-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Parent</name>
<properties> <store-version>0.19-SNAPSHOT</store-version>
<data-version>0.16-SNAPSHOT</data-version>
</properties>
Data POM
<parent>
<groupId>com.dummy</groupId>
<artifactId>parent</artifactId>
<version>0.15-SNAPSHOT</version>
<relativePath>../../parent</relativePath>
Store POM:
<parent>
<groupId>com.dummy</groupId>
<artifactId>parent</artifactId>
<version>0.15-SNAPSHOT</version>
<relativePath>../../parent</relativePath>
</parent>
<dependency>
<groupId>com.dummy</groupId>
<artifactId>data</artifactId>
<version>${data-version}</version>
<scope>compile</scope>
</dependency>
When I use mvn clean install for Store project, it finds Data version and gives no errors.
Source POM
<parent>
<groupId>com.dummy</groupId>
<artifactId>parent</artifactId>
<version>0.15-SNAPSHOT</version>
<relativePath>../parent</relativePath>
</parent>
<artifactId>source</artifactId>
<packaging>pom</packaging>
<version>0.6-SNAPSHOT</version>
Source API POM
<parent>
<groupId>com.dummy</groupId>
<artifactId>source</artifactId>
<version>0.6-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<dependency>
<groupId>com.dummy</groupId>
<artifactId>store</artifactId>
<version>${store.version}</version>
<scope>compile</scope>
</dependency>
Source API builds fine, finds proper versions.
Source WS
<parent>
<groupId>com.dummy</groupId>
<artifactId>source</artifactId>
<version>0.6-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<dependency>
<groupId>com.dummy</groupId>
<artifactId>source-api</artifactId>
<version>${project.version}</version>
</dependency>
When I try to build source-ws, the build fails with error, ${data-version} not found.
I created the following projects according to your description:
+- P
+- A -> parent P
+- B -> parent P
+- C -> parent B, depends on A
+- D -> parent B, depends on C
P's POM
<groupId>so.55374493</groupId>
<artifactId>P</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<ModuleA.version>1.8</ModuleA.version>
<revision>1.8</revision>
</properties>
<modules>
<module>../A</module>
<module>../B</module>
</modules>
A's POM
<parent>
<groupId>so.55374493</groupId>
<artifactId>P</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../P</relativePath>
</parent>
<artifactId>A</artifactId>
<version>${ModuleA.version}</version>
<!-- use the following instead to omit:
"[WARNING] 'version' contains an expression but should be a constant." -->
<!-- <version>${revision}</version> -->
B's POM
<parent>
<groupId>so.55374493</groupId>
<artifactId>P</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../P</relativePath>
</parent>
<artifactId>B</artifactId>
<packaging>pom</packaging>
<modules>
<module>../C</module>
<module>../D</module>
</modules>
C's POM
<parent>
<groupId>so.55374493</groupId>
<artifactId>B</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../B</relativePath>
</parent>
<artifactId>C</artifactId>
<dependencies>
<dependency>
<groupId>so.55374493</groupId>
<artifactId>A</artifactId>
<version>${ModuleA.version}</version>
</dependency>
</dependencies>
D's POM
<parent>
<groupId>so.55374493</groupId>
<artifactId>B</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../B</relativePath>
</parent>
<artifactId>D</artifactId>
<dependencies>
<dependency>
<groupId>so.55374493</groupId>
<artifactId>C</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
mvn install on P and D both succeed (where A at the former prints the well-known [WARNING] 'version' contains an expression but should be a constant., which can be resolved by ${revision} since Maven 3.5).
Can you confirm that your POMs look equally in terms of <parent>s, <properties> (except ${revision}), <version>s and <dependencies>?
error message:
The POM for rc:common:jar:1.0 is missing, no dependency information available
parent pom.xml
<modelVersion>4.0.0</modelVersion>
<groupId>rc</groupId>
<artifactId>springboot-multiple-maven-modules</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>rest</module>
<module>common</module>
</modules>
rest pom.xml
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>rc</groupId>
<artifactId>springboot-multiple-maven-modules</artifactId>
<version>1.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>rest</artifactId>
<name>zeyo rest</name>
<!--<version>1.0</version>-->
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>rc</groupId>
<artifactId>common</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
common pom.xml
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>rc</groupId>
<artifactId>springboot-multiple-maven-modules</artifactId>
<version>1.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>common</artifactId>
<name>common</name>
<version>1.0</version>
<packaging>jar</packaging>
Once you have a dependency called rc -> rest -> common.
Why is this happening?
That simply says that common project not yet built and we started rest.
First run the maven install on parent project so that 'common' project will be built as well.
spring-boot:run : does not build the dependent jars.
Hope this helps.
I have a multi-module MVN project, which has 1 aggregator pom, another parent pom, and 3 other modules, as follows:
project-all
-project-parent
-project-common
-project-maintainance
-project-webApp
project-WebApp has a dependency on project-common and project-maintenance.
When I run a clean install on project-all, it tries to download the modules from repositories instead of building them.
My understanding of a multi-module project is that it runs an install on all the modules as well, but that is not what is happening.
If I run a clean install on all the modules separately, the project-all clean install works fine. It also works when I run the mvn build in Eclipse with the Resolve Workspace Artifacts option selected.
However, both of these options are not viable options, since the idea of using a multi-module project is to run multiple poms from a single location.
Am I missing something, what would be the process of asking mvn to build those modules instead of looking for them in the repository.
Pom for project-all:
<?xml version="1.0" encoding="UTF-8"?>
<groupId>com.midtier.api</groupId>
<artifactId>project-all</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>project-all</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<modules>
<module>project-parent</module>
<module>project-data</module>
<module>project-maintenance</module>
<module>project-WebApp</module>
</modules>
POM for project-parent:
<?xml version="1.0" encoding="UTF-8"?>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<groupId>com.midtier.api</groupId>
<artifactId>project-parent</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<name>${project.artifactId}</name>
<description>${project.artifactId}</description>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<elasticsearch.version>6.2.4</elasticsearch.version>
<jsonsimple.version>1.1.1</jsonsimple.version>
<slf4j-version>1.7.25</slf4j-version>
</properties>
<dependencyManagement>
<!--Dependencies Here-->
</dependencyManagement>
Pom for project-Webapp:
<?xml version="1.0" encoding="UTF-8"?>
<project>
<parent>
<groupId>com.midtier.api</groupId>
<artifactId>project-parent</artifactId>
<version>1.0</version>
</parent>
<groupId>com.rbc.midtier.api</groupId>
<artifactId>project-webapp</artifactId>
<packaging>jar</packaging>
<version>${project.parent.version}</version>
<name>${project.artifactId}</name>
<description>${project.artifactId}</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.midtier.api</groupId>
<artifactId>project-data</artifactId>
</dependency>
<dependency>
<groupId>com.midtier.api</groupId>
<artifactId>project-maintenance</artifactId>
</dependency>
</dependencies>
</project>
project-data and project-maintenance are similar to project-web app but they don't have any internal dependencies.
Again, what I want to do is, just run the clean install command on all, and not have to worry about building any of the modules individually.
I think the problem is that you define the parent as a module. When you run „clean“ the parent used by the other modules is still not available so Maven tries to find it within the repository. Better define the parent information within the project-all pom because during the build phase the parent has to be available.
I have like 10 maven projects(and behind them Jenkins jobs) which have quite the same configuration. They all have a parent, call it ancient.
<parent>
<groupId>com.example</groupId>
<artifactId>ancient</artifactId>
<version>1.0.0</version>
</parent>
<groupId>com.example</groupId>
<artifactId>child_10</artifactId>
<version>1.0.0</version>
<properties >
<reports.to.keep>20</reports.to.keep>
</properties>
Now I don't want to add the properties which are the same for all those members, so I created a parent for all my 10 children:
<parent>
<groupId>com.example</groupId>
<artifactId>ancient</artifactId>
<version>1.0.0</version>
</parent>
<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
<properties >
<reports.to.keep>20</reports.to.keep>
</properties>
I adapted the children to point to that one.
<parent>
<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
</parent>
Thats for the concept. Now I got the problem that I can not deploy my parent to my repository, as it always like wants to build whats configured in the ancient.
I am quite new to Maven: is this even possible? Or is there an other way to manage multiple maven projects with inheritance?
Problem is that ancient is configured so that I can not use deploy or deploy-file as they are configured to deploy something else. I also want them configured like that for my child-projects.