Reputation:
I have a Maven build that has two modules (Server / Client) and I wish to create a folder containing shared methods by both of them.
What should I add to my pom.xml
(s) in order to have a successful build?
I have 3 poms, a parent one in the root of the project, and two other ones respectively in the server
folder and the client
one.
Here is my parent 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>com.christopher.kade</groupId>
<artifactId>jcoinche</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>jcoinche</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<modules>
<module>client</module>
<module>server</module>
</modules>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId> <!-- Use 'netty-all' for 4.0 or above -->
<version>4.1.6.Final</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Upvotes: 1
Views: 239
Reputation: 1032
You can do something similar to this. Within your main(parent) pom.xml, add the module and its dependency.
<modules>
<module>client</module>
<module>server</module>
<module>jcoinche-common</module>
</modules>
<dependencies>
..
..
<dependency>
<groupId>com.christopher.kade</groupId>
<artifactId>jcoinche-common</artifactId>
<version>${project.version}</version>
<!-- ^=== assumes same version as project -->
</dependency>
..
..
Then, in your submodules that require the jcoinche-common module, just add a dependency there as well:
<dependency>
<groupId>com.christopher.kade</groupId>
<artifactId>jcoinche-common</artifactId>
</dependency>
Thats it.
Upvotes: 0
Reputation: 36163
You should place the classes you in client and server in a third module. and then add a dependency to that in the client and server modules.
Upvotes: 1