At this year's Code Camp, I wanted to extend our Maven project-build-plugin with a new Maven goal that would allow us to build an application ZIP alongside the Ivy project archive (.iar).
On my way to implementing this goal, I ended up tackling two other interesting challenges. First, I made our project-build-plugin thread-safe, so that it can build projects in parallel. Second, I struggled with developing the new Maven goal in VS Code because Java formatting wasn't properly configured.
Project-build-plugin adventures
Package Application using Maven
The new pack-app Maven goal is disabled by default when building Ivy projects. When the pack-app goal is enabled for an Ivy project, it generates an application ZIP containing the project's IAR and all of its Ivy dependencies as IARs.
If the project that triggers the goal contains a config/app directory, its contents are also included in the resulting ZIP.
To enable the new goal for a specific Ivy project, add the following configuration to its pom.xml:
<plugin>
<groupId>com.axonivy.ivy.ci</groupId>
<artifactId>project-build-plugin</artifactId>
<configuration>
<skipPackApp>false</skipPackApp>
</configuration>
</plugin>
Parallel Maven builds
So far, it was not possible to run the Maven build of an Ivy project in parallel because some of our goals were not thread-safe. With a few minor adjustments to the affected goals, we can now run builds in parallel.
This means you can use Maven's -T option to configure the number of threads:
mvn -T 4 clean package # Builds with four threads
mvn -T 1C clean package # One thread per CPU core
mvn -T 1.5C clean package # 1.5 thread per CPU core
Java formatting in VS Code
Currently, when I write Java code, I usually do so in Eclipse IDE because our core product is still closely tied to the Eclipse ecosystem. Nevertheless, whenever I get the chance, I try to use VS Code for Java development. With the implementation of pack-app Maven goal, I finally had a good opportunity to do so.
In Eclipse, we have quite a few formatting rules enabled that are automatically applied on save. For example, I don't have to worry about indentation or the number of spaces used. When developing in VS Code, however, the lack of these formatting rules quickly becomes annoying, as I suddenly have to pay attention to formatting details.
Fortunately, I found that Eclipse's Java formatting settings can be exported as an XML file and used in VS Code as well. The exported Eclipse formatting settings, together with the VS Code configuration required to apply them, can be found in the following repository.
If you are using our VS Code extension, you don't need to do anything manually, we preconfigure the formatting settings for you.
Java Formatter for VS Code