Search code examples
javadockermicronaut

Micronaut Dockerfile breaks package build


I've created a simple Micronaut application using

mn create-app app_name --build maven

with a JDK 11 in case that matters.

This creates a maven project which compiles fine, but includes a Dockerfile like this:

FROM adoptopenjdk/openjdk11-openj9:jdk-11.0.1.13-alpine-slim
COPY target/app_name*.jar app_name.jar
EXPOSE 8080
CMD java -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -Dcom.sun.management.jmxremote -noverify ${JAVA_OPTS} -jar app_name.jar

However, there is no docker build included in the Maven AFAICT.

So I included this

<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>dockerfile-maven-plugin</artifactId>
    <version>${dockerfile-maven-version}</version>
    <executions>
        <execution>
            <id>default</id>
            <goals>
                <goal>build</goal>
                <goal>push</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <repository>dockerUser/app_name</repository>
        <tag>${project.version}</tag>
        <buildArgs>
            <JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
        </buildArgs>
    </configuration>
</plugin>

which does manage to build a docker image, but not without manual intervention. The reason is that upon mvn package, three jars get created in target/:

  • app_name-0.1.jar
  • app_name-0.1-shaded.jar
  • original-app_name-0.1.jar

which makes the docker target fail with

When using COPY with more than one source file, the destination must be a directory and end with a /

That message does make sense because all the jars match the COPY source pattern in the Dockerfile.

Right now, I just delete the other two jars (original and shaded) and run the docker target on its own, but that's only fine as long as I work in local manual mode.

Am I missing something or is this an oversight on the Micronaut project creation?


Solution

  • Am I missing something or is this an oversight on the Micronaut project creation?

    The latter.

    If you file an issue at https://github.com/micronaut-projects/micronaut-profiles/issues we can get it straightened out.

    Relevant files:

    Thanks for the input.