1
Project A
   --Module B    
      --pom.xml
   --Module C    
      --pom.xml    
pom.xml

I am working with a multimodule project where project A, module B, and Module C all have their own pom files. Module A and Module B reference the ProjectA pom file.

I am using ModuleA as a dependency in moduleB's pom file.

I added few packages in moduleA and performed mvn clean install

It updated my .m2 repository with the latest changes I made.

I then did mvn clean install on moduleB, however the moduleB still doesnt recognize the latest changes in module A.

I tried the following, but dint work for me

  1. Deleting .m2 folder and doing maven clean install
  2. Building mvn clean install on the root folder
  3. Using Intellij, Invalidate cache and restart, enable update snapshots etc
Karan Sharma
  • 475
  • 1
  • 5
  • 16

1 Answers1

0

Module A and Module B reference the ProjectA pom file

ProjectA should have packaging "pom" and be an "aggregator" of other modules. Its pom.xml should look like this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.foo.bar</groupId>
    <artifactId>myartifactname</artifactId>
    <version>0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <modules>
      <module>ModuleB</module>
      <module>ModuleC</module>
    </modules>
</project>

ProjectA should not contain any source files, so it doens't make sense to declare a dependency on it in modules B and C.

However Module's A pom.xml can contain definitions common for all the modules (like plugin configurations, properties, etc.) In this case you can use inheritance in modules B and C. For example modules B and C (but not A) can have a "parent" section where they'll declare ProjectA as a "parent" hence inheriting the aforementioned definitions.

I am using ModuleA as a dependency in moduleB's pom file

Again as I've explained above this doesn't make sense. ProjectA is not a java module, and since it has packaging pom there is no real artifact (read jar) that gets built from this module.

Mark Bramnik
  • 39,963
  • 4
  • 57
  • 97
  • I have a shade plugin to package the jar inside the module. – Karan Sharma Feb 03 '20 at 04:56
  • shade plugin can manipulate the artifacts (output of the build), but for that you should build artifacts in a correct way first... I really suggest you to try the configuration I've explained first before using shade plugin. – Mark Bramnik Feb 03 '20 at 05:12