Open Source Consultant, Software Developer and System Administrator

If you are interrested in hiring a consultant for the effective use of open source software on an enterprise grade, take a look around in the About section to see, what I have to offer.

Blog and snippets

Various snippets or code parts I found useful, so I keep them here for reference.

Use .netrc from within Grails BuildConfig.groovy

With the switch from ivy to aether providing credentials to Basic-Auth protected internal maven repos according to documentation needs the credentials in the BuildConfig.groovy. Not much saver, but at least not in the repo you can use the content of your .netrc quite easy with a small helper. Add this script in your BuildConfig.groovy:

// parse a valid .netrc and provide the content as netrc.<machine>.key = value
def netrc = [:]
def netrcFile = new File("${System.getProperty('user.home')}/.netrc")
if (netrcFile.exists()) {
        lastMachine = null
        netrcFile.eachLine{
                it.split().collect{ it.trim() }.with{
                        if (it.size()>1) {
                                switch (it[0]) {
                                case 'machine': lastMachine = it[1]; netrc.put(lastMachine, [:]); break
                                default: netrc."$lastMachine".put(it[0],it[1])
                                }
                        }
                }
        }
}

And then you can use it along with the mavenRepo:

def inhouseHost = 'inhouse.com'
mavenRepo("https://${inhouseHost}/mvn/"){
    auth([
            username: netrc."${inhouseHost}".login,
            password: netrc."${inhouseHost}".password,
    ])
}

Toggle JDK in Gentoo

function jdk {
        export GENTOO_VM=oracle-jdk-bin-1.$1
        export JDK_HOME=/usr/lib/jvm/oracle-jdk-bin-1.$1
        export JAVA_HOME=/usr/lib/jvm/oracle-jdk-bin-1.$1
        java -version
}

e.g. jdk 8

Minimalistic Gradle build.gradle file for Groovy projects

apply plugin: 'groovy'

repositories {
        jcenter()
}

dependencies {
        compile 'org.codehaus.groovy:groovy-all:2.3.+'
}

and for Spring Boot

buildscript {
        repositories {
                jcenter()
        }
        dependencies {
                classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.0.2.RELEASE'
        }
}

apply plugin: 'groovy'
apply plugin: 'spring-boot'

repositories {
        jcenter()
}

dependencies {
        compile 'org.codehaus.groovy:groovy-all:2.3.+'
        // e.g. compile("org.springframework.boot:spring-boot-starter-web")
}