Import from other module
You have to add the project of module2 as dependency (maven dependency) in the project of module1. multimodules doesn't mean that all modules have automatically dependency to each other
The mechanism in Maven that handles multi-module projects does the following:
- Collects all the available modules to build
- Sorts the projects into the correct build order
- Builds the selected projects in order
Declare dependency to module2 in module1/pom.xml, something like this:
<dependencies>
...
<dependency>
<groupId>XX</groupId>
<artifactId>module2</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
...
</dependencies>
In build.gradle of module 2:
dependencies {
compile(project(":module1")) {
transitive = false
}
...
//Other dependencies
...
}
transitive = false
ensures dependencies of dependencies are not imported . Only your source part is imported
N.B. - Though the question uses Maven, but most of us use Gradle.