Now that compiling works inside of the IDE, it should also be part of the standard command-line build. Fortunately, there are build hooks into the Hybris build pipeline. Those are configured inside the build_callbacks.xml file.

A naive first draft would look like:

The above is configured for a simple core module, not a web one. It can be added afterwards though.

Unfortunately, this doesn’t work. Launching the build with ant build will produce the following output:

/hybris/bin/platform/resources/ant/compiling.xml:530: java.lang.NoSuchMethodError: com.google.common.collect.Iterables.filter(Ljava/lang/Iterable;Lcom/google/common/base/Predicate;)Ljava/lang/Iterable;

Looking more closely at the kotlin-compiler.jar , one must notice it embeds Guava, which also happens to be on the hybris classpath. Hence, there’s a version conflict. Fortunately, there’s a smarter version of the compiler - kotlin-compiler-embeddedable.jar available on repo1 that shades Guava i.e. embeds it using a different package name, thus resolving the conflict. Just update the callback file with the new JAR name, and be done.

Now, the build produces a different output:

/hybris/bin/custom/kotlinfun/buildcallbacks.xml:34: java.lang.IllegalStateException: File is not found in the directory of Kotlin Ant task: kotlin-compiler.jar

For reasons unknown, the Ant task checks the existence of dependent libraries using their file names! Check the source code for proof. There’s an evil workaround: rename the JAR as it’s expected. And update the build file back to the initial version…​