These days I don’t get to use Gradle much, but I wanted to see how difficult it would be to convert a POM for building a Docker image into a Gradle build script.
It’s hard to tell exactly what plugin is recommended, but I guess it would be “com.palantir.docker”.
The POM for building the Docker image is part of a multiproject build including two other projects, each of which builds a WAR file. I found it pretty trivial to generate the Gradle build scripts for the other two projects, but the Docker one is a little harder. The examples on the “com.palantir.docker” plugin page don’t cover what I need to do.
In the existing POM, I specify the other two projects as dependencies using their GAV coordinates, including a JDBC driver jar. I use the Maven “copy-dependencies” task to get local copies of the dependencies that need to go into the image (stripping versions from the jar names), and I specify those artifacts in the configuration for the “docker-maven-plugin”.
The following is an excerpt of the current POM:
<dependencies> <dependency> <groupId>orderProcessingDashboard</groupId> <artifactId>ordersService</artifactId> <version>0.0.1-SNAPSHOT</version> <type>war</type> </dependency> <dependency> <groupId>orderProcessingDashboard</groupId> <artifactId>ordersGUI</artifactId> <version>0.0.1-SNAPSHOT</version> <type>war</type> </dependency> <dependency> <groupId>oracle</groupId> <artifactId>ojdbc6</artifactId> <version>11.2.0.3</version> </dependency> </dependencies> <repositories> <!-- Need this for the Oracle JDBC driver. --> <repository> ... repo info </repository> </repositories> <build> <plugins> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <executions> <execution> <id>build-image</id> <phase>package</phase> <goals> <goal>build</goal> </goals> </execution> </executions> <configuration> <dockerDirectory>${basedir}/src/docker</dockerDirectory> <imageName>ssorderprocessingdashboard</imageName> <resources> <resource> <directory>${project.build.directory}/dependencies</directory> <includes> <include>ordersService.war</include> <include>ordersGUI.war</include> <include>ojdbc6.jar</include> </includes> </resource> </resources> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>prepare-package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/dependencies</outputDirectory> <excludeTransitive>true</excludeTransitive> <includeArtifactIds>ordersService,ordersGUI,ojdbc6</includeArtifactIds> <stripVersion>true</stripVersion> </configuration> </execution> </executions> </plugin> </plugins> </build>
So far, my build.gradle for this project is just the following, as I have no idea how to manage getting dependencies into the image (so I haven’t bothered to specify the dependencies yet):
`apply plugin: java
plugins {
id ‘com.palantir.docker’ version ‘’
}
docker {
name 'ssorderprocessingdashboard’
dockerfile ‘src/docker/Dockerfile’
}`