0

objective::

  • give::

    3 projects AA, BB, CC; under developing.

    AA = master project

    CC depends on BB

  • requirement::

    I dont want to modify the subprojects.

    I want to manage the dependency in a master project AA.

    ie: add dependency through the pom in AA, not in BB or CC.

problem::

so I use Maven module, and I tried this, didnt work::

  1. link the modules together in AA.
    <modules>
        <module>../BB</module>
        <module>../CC</module>
    </modules>
  1. but then, CC is not able to import ClassB from BB.

=> How can I make CC depends on BB when only editing the pom in AA?


the common solution (that I try to avoid)::

I do know that, if I add dependency in the pom of CC, everything is fine, but I dont want to do this::

  1. add dependency in the pom of CC
    <dependencies>
        <dependency>
            <groupId>GG</groupId>
            <artifactId>BB</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
  1. now, CC is able to import ClassB from BB.
  • btw: some online answers say you need maven install then add the jar.

    1. here, I dont want to build a jar of BB. (as it wouldnt & dont-need-to produce a jar even if you use the "common solution" I wrote above.)

      cuz BB is under developing, it will be constantly modified.

    2. even if I use jar, I dont see how it helps in my case.

  • (in this case, the master project AA for <parent> in CC may not even be needed.)


Some resource that I looked through, I dont know why in my case it doesnt work::

Did I understand Maven module wrong?

How do I add a project as a dependency of another project?

https://www.jetbrains.com/help/idea/maven-support.html#maven_multi_module

how to add dependency of other maven project to my current maven project in java eclipse?

How can a maven project depend on another local maven project?

Nor.Z
  • 555
  • 1
  • 5
  • 13
  • First `I dont want to modify the subprojects.` Why? If you have a dependency you have to add that dependency. That's it. Simple as it. Furthermore the images are a bad idea better use text. – khmarbaise May 31 '22 at 11:21

1 Answers1

0

Create a structure like this:

root-directory
  +--- pom.xml
  +--- module-BB
          +-- src
          +-- pom.xml
  +--- module-CC
          +-- src
          +-- pom.xml

In mdoule CC you can simply define a dependency to module BB and build the whole project from root via mvn package...

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • 1. for `I dont want to modify the subprojects`, I simply want to organize the dependencies in a master project, not in the subprojects. 2. base on your answer & comment `If you have a dependency you have to add that dependency. That's it. Simple as it.`, `you can simply define a dependency to module BB`, seems like there is really no other way, but to modify on the subprojects. – Nor.Z Jun 02 '22 at 20:34
  • [^ continue] I thought the use of `module` made managing through a master project possible. But now it seems like I understood `Maven module` totally wrong. (3. I added back few lines of text for the image. I forgot about that when I inserted the image. But wont matter now.) – Nor.Z Jun 02 '22 at 20:35
  • Take a look here: https://github.com/khmarbaise/javaee (several modules) can be build from root and some of the modules (for example service https://github.com/khmarbaise/javaee/blob/master/service/pom.xml) has a dependency to another module...this also indirectly defines the build order of the modules... – khmarbaise Jun 03 '22 at 08:24