Reputation: 721
I am learning docker to work with my spring boot application. I am not able to load Snapshot versions of dependent project. I have two projects, Project A and Project B.
this is my docker-compose file
version: '2.1'
services:
projectA:
build:
context: ./projectA
dockerfile: Dockerfile
restart: always
working_dir: /app
command: mvn clean install
projectB:
build:
context: ./projectB
dockerfile: Dockerfile
restart: always
working_dir: /app
command: mvn clean spring-boot:run
This generates the Snapshot Jar projectA-1.1.0-SNAPSHOT.jar
I want to use this jar in projectB ( Spring Boot Application)
How can I point yo This local jar in POM.xml
My POM Should have
<dependency>
<groupId>com.project.test</groupId>
<artifactId>projectA</artifactId>
<version>1.1.0-SNAPSHOT</version>
</dependency>
I am getting errors while loading projectB due to changes in SNAPSHOT version.
Thanks,
this is the output when I do docker-compose up --build
[ERROR] COMPILATION ERROR :
[INFO] ----------------------------
[ERROR].../com/project/test/api/assembler/UserMapper.java:
[57,54] cannot find symbol
symbol: method getLastSessionTimestamp()
location: variable user of type com.project.test.domain.User
lastSessionTimestamp is added in local SNAPSHOT Jar.
Upvotes: 0
Views: 504
Reputation: 2555
The reason why your example can't work is that you have a misconception of what docker (compose) is and how it works. It is not a package manager for your java libraries but a tool to wrap entire applications together.
So in detail what you configured is the following: projectA builds a docker container using your Dockerfile builds projectA java libraries and finally installs the packaged jarfile into the docker container local filesystems maven folders. Additionally in parallel you are trying to start projectB. That means you have two problems:
To solve this you have a couple of options of which I would suggest to do the following: - Build A and B outside of containers on your machine using a multi module pom file that orchestrates the build and only add the final jar to a docker image that you can ship. If that works you can also execute the build in a container.
But to simply try out that both your builds work you can create a volume and mount it in both containers into the maven folder which is /root/.m2
assuming you didn't changed the default user.
But I strongly suggest you also have a read on how docker treats multistage builds and how it handles volumes here:
Upvotes: 0