Jon Onstott
Jon Onstott

Reputation: 13727

Maven - moved code to new artifact; transitive dependencies issue

Here is my situation:

And here is the problem:

Does anyone know how I can solve this? Thanks!


EDIT:

Would doing 'relocation' of 'web' to 'web-ng-framework' maybe work better? In ProjectA, I could include a dependency on 'web' so that Maven would see that what it really needs is 'web-ng-framework'. Would that work?

Upvotes: 1

Views: 515

Answers (3)

maba
maba

Reputation: 48075

I suggest that you use optional dependencies

This can be acheived by making web depencency optional in projectA.

<project>
  <groupId>some.group</groupId>
  <artifactId>projectA</artifactId>
  ...
  <dependencies>
    <!-- declare the dependency to be set as optional -->
    <dependency>
      <groupId>some.group</groupId>
      <artifactId>web</artifactId>
      <version>1.0</version>
      <scope>compile</scope>
      <optional>true</optional>
    </dependency>
  </dependencies>
</project>

When declaring some other project that depends on projectA the web dependency will not be included.

<project>
  <groupId>some.group</groupId>
  <artifactId>projectB</artifactId>
  ...
  <dependencies>
    <dependency>
      <groupId>some.group</groupId>
      <artifactId>projectA</artifactId>
      <version>1.0</version>
    </dependency>
    <dependency>
      <groupId>some.group</groupId>
      <artifactId>web-ng-framework</artifactId>
      <version>1.0</version>
    </dependency>
  </dependencies>
</project>

Now projectB will only have a dependency on projectA and web-ng-framework, not web.

Upvotes: 0

GeertPt
GeertPt

Reputation: 17854

A classic solution to this problem is the 'Version 99' hack.

To do this, use the following in your root pom:

<dependencyManagement>
  <dependency>
     <groupId>your.group</groupId>
     <artifactId>web</artifactId>
     <version>99.0-does-not-exist</version>
  </dependency>
</dependencyManagement>

Then put an empty web-99.0-does-not-exist.pom and web-99.0-does-not-exist.jar in your repository. This ensures that every project that inherits from this root pom will not get the old version of the web.jar anymore.

Upvotes: 1

Andreas Wederbrand
Andreas Wederbrand

Reputation: 39991

When including ProjectA in ProjectB exclude web. Like this

<dependency>
  <groupId>your.group</groupId>
  <artifactId>projectA</artifactId>
   <exclusions>
     <exclusion>
       <groupId>your.group</groupId>
       <artifactId>web</artifactId>
     </exclusion>
   </exclusions>
</dependency>

Upvotes: 9

Related Questions