In the world of Java development, delivering high-quality, reliable, and easily deployable applications is paramount. To achieve this, integrating robust testing, comprehensive code analysis, and streamlined containerization into your workflow is crucial. This is where the powerful combination of Jacoco, SonarQube, and Jkube comes into play.
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>sonar</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.jkube</groupId>
<artifactId>kubernetes-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<images>
<image>
<name>${app.image}</name>
<build>
<from>${app.base.image}</from>
<tags>
<tag>${git.branch}</tag>
<tag>${project.version}</tag>
</tags>
<assembly>
<mode>dir</mode>
<targetDir>${app.location}</targetDir>
<inline>
<id>copy-jar</id>
<baseDirectory>${app.location}</baseDirectory>
<files>
<file>
<source>
${project.build.directory}/${app.artifact}
</source>
<outputDirectory>.</outputDirectory>
</file>
</files>
</inline>
</assembly>
<workdir>${app.location}</workdir>
<cmd>${app.cmd}</cmd>
<ports>
<port>${app.port}</port>
</ports>
</build>
</image>
</images>
</configuration>
<executions>
<execution>
<id>build-on-package</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
<execution>
<id>push-on-deploy</id>
<phase>deploy</phase>
<goals>
<goal>push</goal>
</goals>
</execution>
</executions>
</plugin>
A Sample github repository containing the code is available at https://github.com/agileguru/graalvm_cloud_native/blob/main/graalvmcloudnativeserver/pom.xml . You can for the fork the repo and then change the value in the properties to achieve the outcome.
By integrating these three tools, you create a powerful feedback loop that fosters a culture of continuous improvement, leading to higher quality Java applications and a more efficient development process. By using these plugins you can reduce the build / package / code quality time by a significantly. This will also ensure that developer do not check-in before they build and run it locally.