Reputation: 16281
I am working with Maven and creating my own modules.
I have the 01CentralDomain project with the simple com.manuel.jordan.domain package with three @Entities one of them is for example Product
Part of its pom.xml is:
<modelVersion>4.0.0</modelVersion>
<groupId>com.manuel.jordan.centraldomain</groupId>
<artifactId>central-domain</artifactId>
<packaging>jar</packaging>
<name>01CentralDomain</name>
<version>1.0.1</version>
<url>https://github.com/manueljordan/</url>
I have the other 02CentralDomain project again with the same simple com.manuel.jordan.domain package with two new @Entities one of them is for example User
Consider this how an extension of the first project
Part of its pom.xml is:
<modelVersion>4.0.0</modelVersion>
<groupId>com.manuel.jordan.centraldomain</groupId>
<artifactId>central-domain</artifactId>
<packaging>jar</packaging>
<name>02CentralDomain</name>
<version>1.0.2</version>
<url>https://github.com/manueljordan/</url>
...
<dependencies>
<dependency>
<groupId>com.manuel.jordan.centraldomain</groupId>
<artifactId>central-domain</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
Therefore practically my second project has access to the first project, it about to be able to reference the three entities, like Product, we can assume my domain package now has a total of 5 entities, 3 from the first + 2 for the second.
Now I have a third project (02CentralExecution)
Part of its pom.xml is:
<modelVersion>4.0.0</modelVersion>
<groupId>com.manuel.jordan.centralexecution</groupId>
<artifactId>central-execution</artifactId>
<packaging>jar</packaging>
<name>02CentralExecution</name>
<version>1.0.2</version>
<url>https://github.com/manueljordan/</url>
...
<dependencies>
<dependency>
<groupId>com.manuel.jordan.centraldomain</groupId>
<artifactId>central-domain</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
Theoretically the third project has access to the second project source code and therefore for the first project source code too.
It does not work, the third project only can access the second project source code. I can use the User class but not the Product class.
Even if I declare both
<dependencies>
<dependency>
<groupId>com.manuel.jordan.centraldomain</groupId>
<artifactId>central-domain</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>com.manuel.jordan.centraldomain</groupId>
<artifactId>central-domain</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
It does not work.
How I can get working this?
Upvotes: 0
Views: 579
Reputation: 22514
You should use different artifactId's. Maven considers (roughly) groupId:artifactId as the "primary key" for your module, and if you depend on two different versions of module XXX:YYY then it will just include the "most appropiate one", which is usually the one with the higher version.
Furthermore, it turns out that two different modules is what you actually want, as you do not really have two versions of the same module, but a module X that depends on a different one Y, and a third module Z that depends on both X and Y (direct dependency on X, and indirect dependency on Y through X).
So if you have:
01CentralDomain pom.xml:
<modelVersion>4.0.0</modelVersion>
<groupId>com.manuel.jordan.centraldomain</groupId>
<artifactId>central-domain-01</artifactId><!-- note renamed artifactId -->
<packaging>jar</packaging>
<name>01CentralDomain</name>
<version>1.0.1</version>
<url>https://github.com/manueljordan/</url>
02CentralDomain pom.xml:
<modelVersion>4.0.0</modelVersion>
<groupId>com.manuel.jordan.centraldomain</groupId>
<artifactId>central-domain-02</artifactId><!-- note renamed artifactId -->
<packaging>jar</packaging>
<name>02CentralExecution</name>
<version>1.0.1</version><!-- Not a higher version, but a different module!!! -->
<url>https://github.com/manueljordan/</url>
...
<dependencies>
<dependency>
<groupId>com.manuel.jordan.centraldomain</groupId>
<artifactId>central-domain-01</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
02CentralExecution pom.xml:
<modelVersion>4.0.0</modelVersion>
<groupId>com.manuel.jordan.centralexecution</groupId>
<artifactId>central-execution</artifactId>
<packaging>jar</packaging>
<name>02CentralExecution</name>
<version>1.0.1</version><!-- Version 1.0.2 makes no sense now, just use 1.0.1 -->
<url>https://github.com/manueljordan/</url>
...
<dependencies>
<dependency>
<groupId>com.manuel.jordan.centraldomain</groupId>
<artifactId>central-domain-02</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
Then everything should "just work"
Upvotes: 1