I want to create multi module in Maven.
The structure looks like this:
parent
-> application (spring boot app)
-> acceptance-test
In the acceptance-test module I want to have access to classes from applications necessary for testing. The problem is that during the compilation acceptance-test module I am getting the error that classes are not found. Intellij doesn't indicate some problem.
parent pom.xml
<modules>
<module>application</module>
<module>acceptance-test</module>
</modules>
The acceptance-test module use maven-shade-plugin to build jar as executable jar
CodePudding user response:
You can add the application
module as dependency in the acceptance-test
module.
Basically
For a project structure as:
Parent Project: sampleproject
|-- child A: Module1
|-- child A: Module1
|-- child B: UtilMethods
Here UtilMethods has classes to be used in both Module1 and Module2.
This is how pom.xml of Parent Project looks like:
<groupId>com.parent</groupId>
<artifactId>sampleproject</artifactId>
<version>1.0.0</version>
.
.
<modules>
<module>Module1</module>
<module>Module2</module>
<module>UtilMethods</module>
</modules>
And the pom for Modules will look like this:
UtilMethods:
<parent>
<groupId>com.parent</groupId>
<artifactId>sampleproject</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>UtilMethods</artifactId>
Module1:
<parent>
<groupId>com.parent</groupId>
<artifactId>sampleproject</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>Module1</artifactId>
<dependencies>
<dependency>
<groupId>com.parent</groupId>
<artifactId>UtilMethods</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
Module2
<parent>
<groupId>com.parent</groupId>
<artifactId>sampleproject</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>Module2</artifactId>
<dependencies>
<dependency>
<groupId>com.parent</groupId>
<artifactId>UtilMethods</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
CodePudding user response:
Spring Boot
produce a jar
with custom content.
Application classes and dependencies are placed in special custom location in Spring Boot
jar.
So you can not use Spring Boot Application
as dependency for another modules, classes will not found in such jar.
You can create next standard jar module with shared classes which you can use in Spring Boot Application
and in other like mentioned acceptance-test