I have maven project that has main POM module, for example Main. Main contains two pom-modules: "core" and "app". "core" contains jar-module "A", "app" contains jar-module "B" I have next classes:
- app.B.src.main.java.di.AModule.kt //dependency injection module
- app.B.src.main.java.domain.App.java //main app
- core.A.src.main.java.domain.BModule.kt //another injections
When i import AModule.kt and BModule.kt into App.java, it looks like
import di.AModule;
import di.BModule;
Maven can't finish install-phase and says "Cannot find symbol" pointing to import AModule, that is semantically closer to App.java
What should I do with pom-files or packages to fix this problem?
P.S. Also I have a problem that maven doesn't see core.A.src.test.java.SomethingTest.kt during test-phase
CodePudding user response:
Your projects (according to what can be extracted from your question):
- Main
- core
- src/main/java
| - di
| - AModule.kt
- target
| - A.jar
- pom.xml ... <artifactId>A
- app
- src/main/java
| - domain
| - App.java
| - BModule.kt
- target
| - B.jar
- pom.xml ... <artifactId>B
Projects A
and B
are independent of each other. Being both a <module>
of Main
just let you build them in one go (via building Main
).
To be able to reference AModule
in App
you have to declare its JAR A
as a <dependency>
in B
's POM:
...
<artifactId>B</artifactId>
...
<dependencies>
<dependency>
<groupId>...</groupId>
<artifactId>A</artifactId>
<version>...</version>
</dependency>
...
The <packaging>
type of projects that contain code, and should create an artifact, has to be jar
, war
, etc., not pom
.
It's also recommended to separate different source types like:
...
- app
| - src/main
| - java
| | - domain
| | - App.java
| - kotlin
| - domain
| - BModule.kt
...