0

I am writing a package (PACK-A) that is consumed by another (PACK-B). For local development I want to use a local jar that is produced from PACK-A and use it in PACK-B.

The workflow would be

  1. cd PACK-A; mvn clean; mvn package
  2. cd PACK-B; mvn clean; mvn package (but pulls in the local PACK-A jar file)

I thought the way to do it was through the <repositories /> tag in the pom.xml file so my POM.xml file looks like this (lots taken out for brevity):

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.company.team</groupId>
  <artifactId>PACK-B</artifactId>
  <version>1.0.0</version>
  
  <dependencies>
      <groupId>com.company.team</groupId>
      <artifactId>service-name</artifactId>
      <version>0.3.0-master+17</version>
    </dependency>    
  </dependencies>

  <repositories>
    <repository>
      <id>service-name</id>
      <url>file:///Users/username/Projects/service-name/target</url>
    </repository>
  </repositories>
</project>

file:///Users/username/Projects/service-name/target is the directory that compiles (mvn package) the service.jar.

It isn't picking it up and I've confirmed it using a decompiler. How do I get maven to use my local jar in the service that I compiled? Or is my <url> directory written out incorrectly?

Also, I've confirmed, via the decompiler, that the service does compile with my changes. It just isn't picked up by my consumer.

1 Answers1

1

For local development I want to use a local jar that is produced from PACK-A and use it in PACK-B.

To achieve this, you "only need":

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.company.team</groupId>
  <artifactId>PACK-B</artifactId>
  <version>1.0.0</version>

  <dependencies>
    <dependency>   
      <groupId>com.company.team</groupId>
      <artifactId>PACK-A</artifactId>
      <!-- same version, or which ever suits you -->
      <version>${project.version}</version> 
    </dependency>    
  </dependencies>
</project>

And to run mvn install (which additionally to package installs the artifact into the local repository).

See also: How to build dependent project when building a module in maven and What does mvn install in maven exactly do

It is a "complex field" (multi-module...), but the thing You are trying to achieve is really simple/101.

xerx593
  • 12,237
  • 5
  • 33
  • 64