简体   繁体   中英

Importing two different classes from two modules with the same package path

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:

  1. app.B.src.main.java.di.AModule.kt //dependency injection module
  2. app.B.src.main.java.domain.App.java //main app
  3. 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?

PS Also I have a problem that maven doesn't see core.A.src.test.java.SomethingTest.kt during test-phase

Your projects:

+- 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
    ...
    <dependencies>
        <dependency>
            <groupId>...</groupId>
            <artifactId>A</artifactId>
            <version>...</version>
        </dependency>
    ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM