我工作的結構爲多模塊Maven項目如下:Maven的:如何將模塊依賴關係到普通依賴性的罐子文件夾
SQR
+ pom.xml
+ core
| + src
| + target
| | + dependency-jars
| pom.xml
+ connector
| + src
| pom.xml
+ xmlreader
| + src
| pom.xml
+ xmlwriter
| + src
| pom.xml
的SQR是頂級項目,而核心,連接器,xmlreader,xmlwriter是模塊。目前,核心將所有東西一起構建成一個帶有外部jar庫的可執行jar文件。核心使用幾個依賴關係,即log4j,commons。到現在爲止還挺好。出現問題的模塊正在使用特定的依賴關係,即http-client,commons-io。它們都被添加到類路徑中,但它們不會被複制到core/target/dependency-jar。另一個缺點是,我必須在使用依賴項時擴展每個模塊的pom.xml(例如複製依賴關係等)。
目前,我有以下文件:
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>
核心/ 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>
其他模塊的pom.xml文件看起來與上面列出的類似。它感覺像很多開銷,擴展每個pom.xml文件。有沒有解決這個問題的最佳做法?還是有這個問題的快速和乾淨的修復?
tl; dr:我想要一個多模塊項目,其中所有模塊及其依賴項都被構建爲單獨的.jar文件並鏈接在一起。如下:
+ 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)
您是否建議使用您建議的文件和內容創建另一個模塊,即'distro'?還是應該調整核心模塊的pom.xml?謝謝! – Velth
是的,我建議添加一個模塊 – thesmash