Reputation: 3661
I am planning a multi-module maven project.
Parent POM defines two modules, A and B
My Questions:
1. Is a multi-module maven project the correct approach to achieve these aims?
2. Do both modules needs to be published separately to maven central?
Upvotes: 1
Views: 569
Reputation: 97427
This looks like a typical scenario for multi-module build.
.
├── mod-a
│ └── pom.xml
├── mod-b
│ └── pom.xml
└── pom.xml (parent)
The parent contains simply a list of module (two) which looks similar 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.soebes.smpp</groupId>
<artifactId>smpp</artifactId>
<version>0.7.1</version>
</parent>
<groupId>com.soebes.training.first</groupId>
<artifactId>project-parent</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Project : Parent</name>
<scm>
Define the SCM information here...
</scm>
<modules>
<module>mod-a</module>
<module>mod-b</module>
</modules>
</project>
Every child should look similar 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>com.soebes.training.first</groupId>
<artifactId>project-parent</artifactId>
<version>0.1.0-SNAPSHOT</version>
</parent>
<name>Project : Mod-A</name>
<artifactId>mod-a</artifactId>
</project>
And you module-b should look 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>com.soebes.training.first</groupId>
<artifactId>project-parent</artifactId>
<version>0.1.0-SNAPSHOT</version>
</parent>
<name>Project : Mod-B</name>
<artifactId>mod-b</artifactId>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mod-a</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Now you can build from parent module and all these should be deployed to central and there is no need to do this separately you can do that in one go from parent...
Upvotes: 2