A few moments ago I released version 1 of a handy plugin for Gradle.
This plugin adds compileOnly as a new configuration to a java or groovy build. If either the java nor the groovy is applied, the plugin applies automatically the java plugin.
It takes care of adding this configuration to the standard source sets main and test.
And it is aware of Eclipse and IntellJ IDEA as IDEs and adds this configuration to the provided dependencies of them, if the plugins are applied.
How to apply
classpath group: 'com.coders-kitchen', name: 'compileonlyplugin', version: '1.0.0'
apply plugin: 'compileOnly'
Like any other configuration