1

I've googled and stack-overflowed everything, but maybe not enough as I'm still not clear how one adds a module of a Maven project as a dependency in another.

So for example let's say we've got:

MajorPager
  |___ POM.xml
  |___ chuck-commons-core
  |    |____POM.xml
  |____rajni-commons-core
       |____POM.xml

Now I want to add chuck-commons-core but not rajni-commons-core. If I do it directly, it can't find the module. So I ran across the following discussions on stack-overflow and my old friend Guggal:

In summary, the below discussions talk of how to create multi-module projects but not really how to include the sub-modules in a top-level POM into another project.

Useful discussions for context

Concretely, I'd just like a summary from an expert how they add a sub-module of a Parent POM as a dependency to another project.

Community
  • 1
  • 1
Rohan Kumar
  • 726
  • 10
  • 17
  • 1
    Maybe I did not understand you correctly, but if you have a module `chuck-commons-core`, then it has groupId, artifactId and version. You can reference it from other projects as a normal dependency using the groupId, artifact and version. – J Fabian Meier Mar 21 '19 at 08:04

1 Answers1

0

As of now, I think this is the best solution - to add the following ccodee to the POM.xml of the MajorPager.

Code block 1 incoming

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.teachme.how</groupId>
            <artifactId>MajorPager</artifactId>
            <version>0.6-SNAPSHOT</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Code block 2 incoming

<dependencies>
    ...
    <dependency>
        <groupId>com.teachme.how</groupId>
        <artifactId>norris-commons-core</artifactId>
        <version>0.6</version>
    </dependency>
    ...
</dependencies>

When you do so enables Maven to find out where the dependency are - and so Maven picks them up with mvn clean -U install or mvn package -U -DskipTests. And I should like to be educated if this isn't the most effective pattern. Or if any of the fields above are optional that Maven doesn't want me to specify because it can derive it on it's own (say for example, version tag?) - please let me know if that's case as well.

Rohan Kumar
  • 726
  • 10
  • 17
  • Using the import scope for the MajorPager will only work if in MajorPager the dependencies have been defined via dependencyManagement otherwise not. – khmarbaise Mar 21 '19 at 08:36