barathz
barathz

Reputation: 394

Use local m2 repository in docker build stage

I made a Java project which uses an own library, which is installed in my local m2 repository. Now, I'm trying to create a Docker image that generates the jar in a build stage. It fails because it can't resolve dependencies for project of my own library. Is there any way to tell maven (from container) to use my local m2 repository (outside container) so it could resolve my library dependency when I run mvn package?

Upvotes: 7

Views: 4645

Answers (2)

Konrad Botor
Konrad Botor

Reputation: 5043

Simple answer - you can't, because there is no way to mount a volume for docker build command.

I'm assuming your end goal is a Docker image that runs contains your project's built jar or war.

To accomplish that you need two Dockerfiles - one that can be used to create a container that will build your project and exit and a second one that will describe the image that you actually want - one that can be used to create a container that runs your project.

There is a nice article describing how to create and use the first one here. As for the second one, that depends on whether your project builds as jar or a war and how it needs to be started/deployed.

Upvotes: 3

GintsGints
GintsGints

Reputation: 855

There is two ways of managing libraries (including private):

  1. (old way) copy your compiled library to your project lib directory and make sure your project pick it up.

  2. use some repository management software. Good options is - Artifactory https://jfrog.com/artifactory or Nexus repository management - https://www.sonatype.com/product-nexus-repository

Upvotes: 1

Related Questions