Gradle Kotlin DSL Properties Plugin Example

Quick example of how to use the gradle properties plugin with the Kotlin DSL. This example uses the copy task along with the filter ReplaceTokens to do the heavy lifting. When using the ReplaceTokens filter the token needs to be surrounded with start and end token marker, in this case the @ character.


plugins {

repositories {

task<Copy>("prepareProperties") {
    val filterTokens: Map<String, String> by project
    from("$rootDir/target") {
        filter<>("tokens" to filterTokens)



The output file is located at $buildDir/target/conf/test-file.txt with contents

Copy Spring Boot Property Sources into System Properties

Spring Boot is unique in that property values are accessed through Spring’s Environment abstraction. However, certain libraries require properties to be accessible through the System.getProperty(...) convention. Adding a custom factory around the @PropertySource annotation to force properties into the system context is a good solution, however, it might not be the most robust. Anything that might get bootstrapped during the Spring initialization process before the property sources are loaded from the annotation might be misconfigured based on properties that haven’t loaded yet.

To prevent this from happening, a application listener can be configured to listen for the ApplicationEnvironmentPreparedEvent then load properties into the system context before much else has occurred. This listener should be used in conjunction with the system property spring.config.location to set the location of properties to load instead of the @PropertySource annotation. For more information on external configuration, see the Spring Documentation.

The Java and Kotlin examples below demo this implementation.

Java Version

public class Application {
  public static void main(String[] args) {
      SpringApplication springApplication = new SpringApplication(Application.class);
      springApplication.addListener(new SystemPropertiesSetterEventListener());;

  private static class SystemPropertiesSetterEventListener
      implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {
    public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
      event.getEnvironment().getPropertySources().forEach(ps -> {
        if (ps instanceof MapPropertySource) {
          MapPropertySource mps = (MapPropertySource) ps;
          mps.getSource().forEach((key, value) -> System.getProperties().putIfAbsent(key, value.toString()));

Kotlin Version

class Application

fun main(args: Array<String>) {
  runApplication<Application>(args = *args, init = {

class SystemPropertiesSetterEventListener :
    ApplicationListener<ApplicationEnvironmentPreparedEvent> {
  override fun onApplicationEvent(event: ApplicationEnvironmentPreparedEvent) {
    event.environment.propertySources.forEach { ps ->
      if (ps is MapPropertySource) {
        ps.source.forEach {
          System.getProperties().putIfAbsent(it.key, it.value.toString())

Using Sonarqube with Kotlin

The state of kotlin and sonarqube

There currently is no offical plugin for sonarqube to support kotlin. In the meantime, the detekt can be used to analyze kotlin projects. Please double check that this is still the case before continuing.

Getting a local Sonarqube running for testing

Setting up Sonarqube via docker with their official image and adding the detekt plugin. The lazy way without a dockerfile:

docker pull sonarqube:<version>
docker run -d --name sonarqube -p 9000:9000 -p 9092:9092 sonarqube:<verson>
docker exec -it sonarqube bash
chown sonarqube:sonarqube sonar-kotlin-0.4.1.jar
mv sonar-kotlin-0.4.1.jar /opt/sonarqube/extensions/plugins/
docker restart sonarqube

Setting up configuration via gradle

Added changes needed to root build.gradle file Specific notes: 1. This is a multiproject example, if you have just one project just remove the configure(subjects) wrapping 2. Get a copy of the detekt.yml by running ./gradlew detektGenerateConfig or by copying default-detekt-config.yml. 3. Jacoco is for code coverage

buildscript {
  ext.detektVersion = '1.0.0.RC7'
  dependencies {
    classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.2'
    classpath "$detektVersion"

apply plugin: 'org.sonarqube'
apply plugin: 'io.gitlab.arturbosch.detekt'

detekt {
  version = $detektVersion
  defaultProfile {
    input = "$projectDir"
    config = "$project.rootDir/detekt.yml" // if you'd like to override the default rules

configure(subprojects) { project ->
  apply plugin: 'jacoco'
  jacoco {
    toolVersion = ''
    reportsDir = file("$buildDir/jacocoReports")

  sonarqube {
    properties {
      property "detekt.sonar.kotlin.config.path", "$project.rootDir/detekt.yml"
      property "detekt.sonar.kotlin.filters", ".*/test/.*,.*/resources/.*,.*/build/.*,.*/target/.*"

Side notes

Detekt filtering, make sure this is correct or you’ll get 0 kotlin files were analyzed. Examples of what might be filtered for the following .*/test/.*,.*/resources/.*,.*/build/.*,.*/target/.*:


How to fix Synology Hyper Backup Explorer Insufficient Privileges Error

A quick guide to fix the following error message given in Hyper Backup Explorer when trying to access a usb backup.


Insufficient privileges to access some subfolders under the destination shared folder. Please contact the destination administrator for assistance.

The application actually outputs the error to a log under the running directory called HyperBackupExplorer.log and contains the following

2017-06-03 01:28:57 PM (5775) [debug] target_manager.cpp:186 synobkpinfo.db [/media/user/drive/diskstation_backup/synobkpinfo.db] access failed Permission denied
2017-06-03 01:28:57 PM (5775) [debug] target_manager.cpp:186 synobkpinfo.db [/media/user/drive/diskstation_backup/synobkpinfo.db] access failed Permission denied
2017-06-03 01:28:57 PM backuptargetimpl.cpp:73 get target failed

A simple fix for this is to change the file permissions for the database file with the following command (note please change the media directory path with the correct mount path for the drive):

cd /media/user/drive/diskstation_backup/
sudo chmod o+r synobkpinfo.db

Ubuntu 17.04 Install Nvidia Drivers

Looking for Ubuntu 16.04/16.10?

Quick guide on how to install nvidia drivers on a fresh install of Ubuntu 17.04 with full disk encryption. The following steps were tested with a GTX 1070 and Intel HD Graphics 530 integrated graphics.

  • Boot and install via normal usb ubuntu installer
  • After installation reboot and login
  • Run update system software via terminal
sudo apt-get update && sudo apt-get upgrade
  • Reboot system
  • Switch to tty1 by ctl-alt-f1 and login
  • Stop x
sudo /etc/init.d/lightdm stop
  • Remove the default nouveau drivers:
sudo apt-get --purge remove xserver-xorg-video-nouveau
  • Add nvidia ppa and install correct driver version replacing nvidia-381 with whatever version you’d like
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
sudo apt-get install nvidia-381
sudo nvidia-xconfig
  • Edit file /etc/default/grub with your favorite editor
  • Edit line 11
From: GRUB_CMDLINE_LINUX_DEFAULT="quiet nosplash noplymouth"
  • Uncomment line 25 and change to your monitor’s resolution (for aesthetics)
  • Then update grub and reboot

Note: the first first booting after these changes might only show a black screen, just type in the encryption password and enter and it should login. This seems to only happen the first time.