maven nested modules

1 min readDec 28, 2021


following up with, there are times it needs a set up of nested modules.

where for example, module A could contain module A1, module A2 for example.

the needed changes/set up for nested maven module is similar to the multi module set up. however, now module A needs to be with



similarly, the submodule should be included in module A.

<parent> <groupId></groupId> <artifactId>ParentModule</artifactId> <version>1.0-SNAPSHOT</version> </parent> <artifactId>ModuelA</artifactId> <packaging>pom</packaging> <modules> <module>ACore</module> <module>A1</module> <module>A2</module> </modules>

among the submodules, if A1 needs to use the code from ACore, the dependency scope should be compile, so that it would build A1 shaded with the classes from ACore.

<artifactId>A1</artifactId> <properties> <maven.compiler.source>8</maven.compiler.source> <>8</> </properties> <dependencies> <dependency> <groupId></groupId> <artifactId>ACore</artifactId> <version>1.0-SNAPSHOT</version> <scope>compile</scope> </dependency> </dependencies>

this will work out within IDE. as for build or packaging, the command to build the nested jars are

mvn clean package -pl ModuleA-am -amd

-am will include upstream dependency for example module Core

where -amd will include the nested modules, for example ACore, A1 and A2.


Originally published at on December 28, 2021.