Denny
Denny

Reputation: 21

Spring Boot Docker Maven Plugin with module dependencies

I am using docker-maven-plugin(Spotify) to build my docker images generated by Dockerfile in my Spring Boot project. If the project has no any module dependency it works well. But if a module is dependent to another like:

<dependency>
    <groupId>com.mysite</groupId>
    <artifactId>helper</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>

When I run

./mvnw install dockerfile:build

I got

Could not resolve dependencies for project com.mysite:web:jar:0.0.1-SNAPSHOT: The following artifacts could not be resolved: com.mysite:helper:jar:0.0.1-SNAPSHOT

How can I solve this?

Upvotes: 0

Views: 515

Answers (1)

yomateo
yomateo

Reputation: 2377

You don't need a plugin to accomplish this.

1) Create a Dockerfile:

FROM openjdk:8-jre-alpine

COPY build/libs/yourapp-0.0.1-SNAPSHOT.jar /application.jar

CMD ["java", "-jar", "/application.jar"]

2) Create a shell script, or use a simple Makefile to do the building:

VERSION ?= $(shell git rev-parse HEAD)
APP     ?= k8specs-platform-api
IMAGE   ?= gcr.io/matthewdavis-devops/$(APP):$(VERSION)

.PHONY: build

all: build push

build:

    ./gradlew bootJar
    docker build -t $(IMAGE) .

run:

    docker run -p 8080:8080 $(IMAGE)

push:

    docker push $(IMAGE)

3) Just run make all and profit!

No need for a silly plugin ;)

Upvotes: 0

Related Questions