Continuous Integration, and Continuous Deployment for Java

This guide will help you to build configuration for a Java project on Scrutinizer. Notice that, Scrutinizer automatically infers your build configuration and test commands depending on your build system. If you have a specific set-up that does not follow the standard practices, you can customize your own configuration by placing a .scrutinizer.yml file in your project root folder.

Setup JDK and Tools

By default, OpenJDK 8 is used in build environment. However Scrutinizer also support Oracle JDK 8 if you have strict requirement for your build. You can config it in your configuration:

build:
    environment:
        java: 'java-8-oracle'

It is also possible to tweak Java memory heap size:

build:
    environment:
        variables:
            _JAVA_OPTIONS: '-Xms512m -Xmx1024m'

Setup with SDKMAN

SDKMAN! is a tool for managing parallel versions of multiple Software Development Kits on most Unix-based systems. You can also setup JDK and tools with SDKMAN. Examples:

To setup a default version of JDK:

build:
    environment:
        sdkman:
            - java

To setup a specific version of JDK:

build:
    environment:
        sdkman:
            - [email protected]

To setup tools like Gradle, Maven and Ant:

build:
    environment:
        sdkman:
            - [email protected]
            - maven
            - [email protected]

For more details about available Software Development Kits and versions supported by SDKMAN, please check SDKMAN! documentation.

Project Setup

As long as you use a common build system such as Maven, Gradle or Ant. Scrutinizer will automatically infer install commands based on your project build system. For example, if you have a pom.xml at the root of the project, it's automatically detected and Scrutinizer will infer command:

mvn clean compile

or if your project uses the mvnw wrapper script:

./mvnw install -DskipTests=true -Dmaven.javadoc.skip=true -B -V

or if you would like to run your own scripts, you can add the configuration in your configuration:

build:
  nodes:
    my-tests:
      project_setup:
        override:
          - set-up.sh

Testing

Scrutinizer will automatically try to infer your test commands. We support running tests via Maven, Gradle and Ant. If you would like to run a customized test script, you can add them in your configuration:

build:
  nodes:
    my-tests:
      tests:
        override:
          - ./run-tests.sh

Code Coverage

Scrutinizer also supports several coverage reports formats such as jacoco, clover and cobertura. Take JaCoCo as an example, the configuration of code coverage in your configuration would look like:

build:
  nodes:
    tests-with-coverage:
      tests:
        override:
          - command: mvn clean package
            coverage:
              file: '[path-to-coverage-reports]'
              format: 'jacoco'

If you have multiple commands that generate code coverage data, we will automatically take care of merging it.

Deployment

Scrutinizer provides first-class support for deployment. Once all your tests have passed, it will automatically trigger deployment of your code. You can define deploy commands in your configuration file:

build:
  nodes:
    deploy:
      requires:
        - branch: master         # you can use either the full branch name,
        - branch: /feature_.*/   # or a regular rexpression

      commands:
        - mvn deploy

Multi-Core Builds

If your build benefits from multiple CPU cores, you can currently request up to 8 CPUs for your build. Simply, add the following to your configuration:

build:
  nodes:
    my-tests:
      resources:
        cpus: 4
Note: The maximum CPU number is limited by the number of available containers in your plan.

Cache

In order to speed up the future build, Scrutinizer automatically cached Maven local repository .m2 for maven project , .gradle for gradle project and .ivy2 for Apache Ivy project. You can also customize configuration for caching, learn more in our Caching Reference.

For more informations about build configuration, please check out Build Config Reference.