Java builds on Travis CI .org

I’d seen the name Travis a number of times in relation to Continous Integration, but never having any non-work repositories I’d never paid any attention to anything other than Jenkins.

But since starting on more private projects I did come to miss not having a  ‘it works on my machine’ check. I didn’t really have an appetite to setup Jenkins locally, although it might not be much hassle with Docker and compose, it just wasn’t something I wanted to spend time on.

This is where Travis-ci.org comes into the picture. Firstly it is completely hosted; secondly, it’s completely free. (Enterprise packages available on travis-ci.com)

The org site is specifically set up to ease integration with your own Github repositories. Once you’ve signed in with the SSO/SAML magic you’re given a list of your private repos and simple tick boxes for which you want to enable.

From there is a tiny domain-specific language file you need to insert into the root of your repo. I’ve included the simplest Java one I could get away with as an example below.

file: .travis.yml

language: java
jdk:
- oraclejdk8
sudo: false
script: mvn clean verify

The build will then trigger whenever you push to the repo. Each build produces a summary plus the raw build process output.

Adding Graphite support to Spring Boot Actuator

I made a very simple Graphite implementation of the MetricWriter interface, you can see the code in my GitHub repo spring-boot-actuator-graphite.

If you want to use it in a production environment please be aware that it does open and close a new Socket connection for each metric measurement.

Assuming you have a Spring Boot Actuator project, below is an example @Configuration class to enable writing your metrics to Graphite.

 
@Configuration
public class MonitoringConfiguration {

    @Value("${spring.metrics.export.graphite.prefix}")
    private String prefix;

    @Value("${spring.metrics.export.graphite.host}")
    private String host;

    @Value("${spring.metrics.export.graphite.port}")
    private int port;

    @Bean
    public MetricsEndpointMetricReader metricsEndpointMetricReader(MetricsEndpoint metricsEndpoint) {
        return new MetricsEndpointMetricReader(metricsEndpoint);
    }

    @Bean
    @ExportMetricWriter
    MetricWriter metricWriter() {
        return new GraphiteMetricWriter(this.prefix, this.host, this.port);
    }
}