Skip to content

The Hydra Gradle plugin smoothly integrates Hydra into Gradle. The Hydra Gradle plugin is built on top of the Scala Gradle plugin, and it is hence trivial to update your build to enable compilation of Scala sources with Hydra.

Requirements

  • Gradle 4
  • for Scala 2.11: 2.11.8 or above
  • for Scala 2.12: 2.12.1 or above
  • Zinc 0.3.13
  • Oracle Java 1.8

Note: This documentation assumes you are familiar with the Gradle Scala plugin and it only explains the few changes needed to upgrade your build so that your project is compiled with Hydra instead of vanilla Scala. If you are new to Gradle, start by reading the Gradle Scala documentation to set up your project.

Installation

Hydra is distributed through our public repository. Let's start by adding the Triplequote repository to your build.gradle:

repositories {
  maven {
    url "https://repo.triplequote.com/libs-release/"
  }
}

Then, add the Hydra Gradle plugin to the plugins block:

plugins {
  id "com.triplequote.hydra" version "0.0.2"
}

Note: See here for the latest released version of the Hydra Gradle plugin.

And replace

apply plugin: 'scala'

with

apply plugin: 'com.triplequote.hydra'

If the build file contains an explicit dependency to zinc, e.g.,

dependencies {
    zinc 'com.typesafe.zinc:zinc:<zinc-version>'
}

Remove it. The reason is that the Gradle Hydra plugin works only with zinc 0.3.13, and the correct zinc version is automatically set by the plugin.

Finally, set the Hydra and Metrics service versions:

hydra {
  version = "1.1.1"
  metricsServiceVersion = "1.1.0"
  // optional:
  // workers = 4
}

Check the CHANGELOG for valid Hydra versions.

Note that if you have a multi-module build, the above hydra settings need to be applied to all modules containing Scala sources. The allprojects or subprojects Gradle helpers may prove to be useful, e.g.,

allprojects {
  hydra {
    ...
  }
}

License activation

If you're using Hydra on your developer machine, you need to activate a Hydra license before you can compile with Hydra. Use the hydraActivateLicense task, passing as argument the the actual license number you obtained:

$ gradle hydraActivateLicense --key=XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
> Task :hydraActivateLicense
Activating license XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX using https://activation.triplequote.com/algas/. This may take a while.
License successfully activated

Compiling with Hydra

Now that Hydra is installed, let's check how it works:

$ gradle compileScala

> Task :compileScala
Starting MetricsService watching /Users/mirco/.triplequote/metrics, pushing to http://localhost:3333.

...

BUILD SUCCESSFUL in 8s
3 actionable tasks: 3 executed

Congratulations, you have successfully installed Hydra!

Compile-time monitoring!

While compiling your Scala source files, Hydra also collects compilation metrics that help you keep compile time under control. With the help of a modern web-based dashboard, you can track how compilation time evolves on your project, commit after commit. Even more importantly, you can prevent unexpected compile time deteriorations to land in the development branch before hampering everyone's productivity.

In the output above you might have noticed the message

Starting MetricsService watching /Users/mirco/.triplequote/metrics, pushing to http://localhost:3333.

This informs you that Hydra will try to push compilation metrics to a service that is expected to run on localhost (note that Hydra will work just fine also if you decide not to install the dashboard).

To set-up the dashboard please read the installation instruction.

Dashboard Deck

Know your memory requirements

Hydra has slightly higher memory requirements than regular Scala, so make sure you keep an eye on the JVM behavior. If compiling your codebase using Hydra doesn't deliver the desired speed up, adjust the memory settings for compiling as explained in the Gradle Scala plugin documentation.