I'm working on a multi module maven project structured as follows:
SQR
+ pom.xml
+ core
| + src
| + target
| | + dependency-jars
| pom.xml
+ connector
| + src
| pom.xml
+ xmlreader
| + src
| pom.xml
+ xmlwriter
| + src
| pom.xml
The SQR is the top level project, whereas the core, connector, xmlreader, xmlwriter are modules. Currently the core builds everything together into a executable jar with external jar libs. The core uses several dependencies i.e. log4j, commons. So far so good. The problem arises modules are using specific dependencies i.e. http-client, commons-io. They all get added into class-path but they don't get copied to the core/target/dependency-jars. Another drawback is that I have to extend the pom.xml of every module when using dependencies (e.g. copy-dependencies etc.).
Currently I have the following files:
SQR/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>
<groupId>com.sqr</groupId>
<artifactId>SQR</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>SQR</name>
<url>http://maven.apache.org</url>
<modules>
<module>core</module>
<module>connector</module>
<module>xmlwriter</module>
<module>xmlreader</module>
</modules>
</project>
core/pom.xml:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.sqr</groupId>
<artifactId>SQR</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>core</artifactId>
<packaging>jar</packaging>
<name>core</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
[...]
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>com.sqr, org.apache.commons</includeGroupIds>
<outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Other module pom.xml files look similar to the one listed above. It feels like much overhead, extending each pom.xml file. Is there a best practice to solve this problem? Or is there a quick and clean fix for this problem?
tl;dr: I want a multi module project where all modules and their dependencies get build into seperate .jar files and linked together. As follows:
+ dependency-jars
| commons-lang3-3.3.2.jar (used by only xmlwriter)
| connector-1.0-SNAPSHOT.jar
| xmlreader-1.0-SNAPSHOT.jar
| xmlwriter-1.0-SNAPSHOT.jar
| log4j-1.2.17.jar (used by all modules)
core-1.0-SNAPSHOT.jar (being the main entry of the application)