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

Packaging docker / docker-build should put something into the maven repository #1537

Open stoerr opened 2 years ago

stoerr commented 2 years ago

Description

When doing a "mvn install" for a packaging "docker-build" or "docker", nothing at all is put into the maven repository. Of course, the primary goal is building the docker image, but if you have a multi module build with maven you'd need some way to declare the dependencies to maven so that there is a sensible build order. So, something like the docker-info artifact of the dockerfile-maven-plugin would come handy. That said: a JAR with some basic information is actually generated - it just isn't put into the maven repository yet.

Info

stoerr commented 2 years ago

Workaround for now, if someone has the same problem: if you add this to the pom.xml, it uploads at least something to the maven repositories - the pom artifact and a docker artifact.

            <plugin>
                <artifactId>maven-install-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-install</id>
                        <phase>install</phase>
                        <goals>
                            <goal>install</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-deploy-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-deploy</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>deploy</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

If you want the JAR in there, this would help:

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-artifacts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${project.build.directory}/${project.build.finalName}.jar</file>
                                    <type>jar</type>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
stoerr commented 1 year ago

Are there any good practices for making sure the right build order if you've got several docker images built in a multi module reactor project? That workaround works, but it'd be no good for actual releases, as you don't want to litter maven central with such fake artifacts. :-)