I have a multi-module project in Maven that compiles correctly but does not package correctly.
In the main maven, pom.xmlI include the following modules:
<modules>
<module>module1</module>
<module>module1/test</module>
<module>module2</module>
<module>module2/test</module>
...
<module>moduleN</module>
<module>moduleN/test</module>
</modules>
Unlike maven conventions, this project should have its test source trees compiled as separate modules, because compilation dependencies for test code are different from the dependencies of the main source code. Thus, the solution is to install all the test modules depending on any main source modules so that they are compiled in the correct order.
. pom.xml , , , . , - . :
/
+- pom.xml
+- module1/
+- pom.xml
+- src/
+- com/
+- company/
+- Module1.java
+- test/
+- pom.xml
+- src/
+- com/
+- company/
+- Module1Test.java
...
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>
<parent>
<groupId>com.company</groupId>
<artifactId>project</artifactId>
<version>5.3.1-SNAPSHOT</version>
</parent>
<artifactId>module1</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.company</groupId>
<artifactId>modulex</artifactId>
<version>${product.version}-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<sourceDirectory>src</sourceDirectory>
<directory>target</directory>
<outputDirectory>target/classes</outputDirectory>
<testOutputDirectory>target/test-classes</testOutputDirectory>
...
</build>
</project>
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>
<parent>
<groupId>com.company</groupId>
<artifactId>project</artifactId>
<version>5.3.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>module1.test</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.company</groupId>
<artifactId>module1</artifactId>
<version>${product.version}-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>src</testSourceDirectory>
<directory>target</directory>
<outputDirectory>target/classes</outputDirectory>
<testOutputDirectory>target/test-classes</testOutputDirectory>
...
</build>
</project>
, , , module.test:
[ERROR] Failed to execute goal on project module1.test: Could not resolve dependencies for project com.company:module1.test:jar:5.3.1-
SNAPSHOT: Could not find artifact com.company:module1:jar:5.3.1-SNAPSHOT in repo1.maven.org (http://repo1.maven.org/maven2/) -> [Help 1]
- Maven , , ....
pom.xml module1/test , ? , pom.xml?