I have multi-module maven project. The acceptance-tests module has dependency from api module in pom.xml (Replacing real company name by xxx to keep confidentiality). I am trying to import some classes from api module in my acceptance-tests.
Here is my pom.xml dependency of acceptance-tests module:
<dependency>
<artifactId>xxx-api</artifactId>
<groupId>com.xxx</groupId>
<version>${xxx.api.version}</version>
</dependency>
The api module separately is being installed and packaged (mvn install, mvn package) by maven without any issue. The jar file is being created in my local .m2.
However, when I try to compile the acceptance-tests module, I get a compilation error saying that the the classes cannot be imported because the package is not found.
Here is the actual error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project xxx-acceptance-tests: Compilation failure: Compilation failure:
[ERROR] /Users/andranik_chorokhyan/mydisk/Projects/XXX/automation/xxx-project-test-automation/xxx-acceptance-tests/src/main/java/com/xxx/xxx/utilities/api/ApiPayloadUtils.java:[17,38] package com.xxx.domain.dto does not exist
[ERROR] /Users/andranik_chorokhyan/mydisk/Projects/XXX/automation/xxx-project-test-automation/xxx-acceptance-tests/src/main/java/com/xxx/xxx/utilities/api/ApiPayloadUtils.java:[18,38] package com.xxx.domain.dto does not exist
[ERROR] symbol: class MappingData
[ERROR] location: class com.xxx.utilities.api.ApiPayloadUtils
One more interesting fact is that there is no error visible in Intellij IDEA. No red underline, no compilation error, no problem with navigating to the appropriate imported file. And in reality, the com.xxx.domain.dto package does exist and the MappingData class as well.
I removed whole xxx directory from my local .m2 repository and executed mvn clean dependency:resolve
command. It succeeded as well.
Does anybody know what's the problem here and how it can be solved? Thanks in advance!
Finally I have found the solution. Thanks JF Meier and khmarbaise for hints.
It appeared Maven doesn't allow dependency from executable jar. This was my case. My api module was an executable Spring Boot application and not reusable library.
So, the solution was the following:
Application.java
file in api
module.maven-jar-plugin
with exclusion of the Application.java
file and specification of some classifieracceptance-tests
module from the above specified classifier instead of standard jarPlugin specification in api module below:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>qa</classifier>
<excludes>
<exclude>**/Application*</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
Dependency in acceptance-tests module below:
<dependency>
<artifactId>xxx-api</artifactId>
<groupId>com.xxx</groupId>
<version>${api.version}</version>
<classifier>qa</classifier>
</dependency>