'Using Heroku to deploy a Spring Boot application that has dependencies to Maven submodules

I'd like to deploy a Spring Boot application - with Heroku - that is part to a multi-module Maven project and that references one of those submodules:

$ ls .
api/
models/
Procfile
pom.xml

The master parent pom.xml has the following modules:

<modules>
  <module>models</module>
  <module>api</module>
</modules>

The api project references the models module with:

<dependency>
  <groupId>com.test</groupId>
  <artifactId>models</artifactId>
  <version>1.0</version>
</dependency>

And the Procfile contents are:

web: java -Dserver.port=$PORT -jar $PATH_TO_JAR

Now, when I execute the git push heroku master command, I receive this error:

remote: [ERROR] Failed to execute goal on project api: 
Could not resolve dependencies for project com.test:api:jar:1.0: 
Could not find artifact com.test:models:jar:1.0 in central (https://repo.maven.apache.org/maven2) -> [Help 1]

How can I properly resolve the local submodule dependency?



Solution 1:[1]

Heroku builds the Maven reactor from scratch (upon git push) and it fails to find the api dependency because it is not in the local Maven nor in the Maven central.
Locally you would mvn install the sub-module first or use a system scope.

You can keep the same architecture if you deploy the application with Heroku Docker.

The Dockerfile packages the SpringBoot jar file you create locally:

FROM adoptopenjdk/openjdk11:latest
RUN mkdir -p /software
ADD target/mySpringBoot.jar /software/mySpringBoot.jar

CMD java -Dserver.port=$PORT $JAVA_OPTS -jar /software/mySpringBoot.jar

Create the SpringBoot application jar file then buiod/push the image to Heroku

# build project locally (ie Springboot jar file)
mvn clean package

# build/push to Docker
heroku container:push web -a myapp
heroku container:release web -a myapp

Don't forget to log into the Heroku Docker registry (heroku container:login), only necessary once.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Beppe C