fabric8io / docker-maven-plugin

Maven plugin for running and creating Docker images
https://dmp.fabric8.io
Apache License 2.0
1.88k stars 642 forks source link

Maven build changed with 0.40.3 #1633

Open mszalbach opened 1 year ago

mszalbach commented 1 year ago

Description

With versions before 0.40.3 it was possible to have a multi module project and use the Simple Dockerfile build configuration (Dockerfile at parent level) and separate the package step and the docker:build step. With the version 0.40.3 the plugin changes something in the Maven build process and Maven wants to download one of the child dependencies from a repository, which was not necessary with version 0.40.2.

Probably easier to see in the example project > https://github.com/mszalbach/maven-docker-plugin-403

Checkout and call ./mvnw package and afterwards try a ./mvnw docker:build the build will fail with

Could not resolve dependencies for project com.example:main:jar:0.0.1-SNAPSHOT: Could not find artifact com.example:m1:jar:0.0.1-SNAPSHOT

When changing the version of the docker maven plugin to 0.40.2 it works.

Info

rohanKanojia commented 1 year ago

Do you think this could be related to https://github.com/fabric8io/docker-maven-plugin/issues/1146 ?

mszalbach commented 1 year ago

Yes from the commit I guess this issue should be the one changing the behavior because now the docker:build command requires a dependency solution, which was not the case before. With Maven 4-alpha3 the same example would work, because Maven would be smarter in resolving own child dependencies.

mszalbach commented 1 year ago

Did some more testing and with the change to dependency resolve I am not able to get docker:build working as standalone command in a multimodule project, because there will always a child which can not be resolved.

So it would always needs a ./mvnw package docker:build and it not possible to separate this steps in multi stages on the CI server anymore like it was possible with 0.40.2

mszalbach commented 1 year ago

Simple workaround is to call docker:build with a project list so maven did not resolve everything. So having the pom.xml in the parrent and calling ./mvn -pl . docker:build solves the issue and you can still use the simple top level Dockerfile with versions >0.40.2

grigoni commented 1 year ago

@mszalbach unfortunately using ./mvn -pl . docker:build does not work when calling from module pom.xml

Dalamaar commented 1 year ago

We also ran into this problem right now. We build the docker image in a submodule via Dockerfile, that is also located in the submodule. When using 0.40.2, all is fine, with the current 0.43.4 it does not work.

rohanKanojia commented 1 year ago

@Dalamaar : Could you please share a reproducer project?

Dalamaar commented 1 year ago

Sure, here it is: https://github.com/Dalamaar/maven-docker-plugin (It is an adjusted fork of the example of @mszalbach)

The Dockerfile is located in the app-submodule, as well as the dependency to the docker-maven-plugin. When calling "mvn package" and then "mvn docker:build" it works with 0.40.2, but not 0.43.4. "mvn package docker:build" is working.

Calling "mvn -pl app docker:build -am" is also not working in the new version. In the old one it is, as far as I can tell.

rohanKanojia commented 1 year ago

@Dalamaar : Thanks for sharing. Are you testing this on linux environment or mac?

Dalamaar commented 1 year ago

We work on Windows with Docker Desktop.