Class loading issue for code located in buildSrc


I will use a custom subclass of DefaultTemplateBasedStartScriptGenerator in my project build. The class source code is located somewhere under the buildSrc directory. My script generator class provides a method similar to DefaultTemplateBasedStartScriptGenerator.utf8ClassPathResource(), in particular that method also makes use of class

public class StartScriptGenerator extends DefaultTemplateBasedStartScriptGenerator {
    public StartScriptGenerator(File templateFile) {
    private static TextResource utf8FileResource(final File file) {
        return new CharSourceBackedTextResource(new CharSource() {
            public Reader openStream() throws IOException {
                InputStream stream = new FileInputStream(file);
                return new BufferedReader(new InputStreamReader(stream, CharsetUtil.UTF_8));

In order to get rid of a NoClassDefFoundError for class CharSource I needed to explicitly add guava to the dependencies of the buildSrc subproject:

dependencies {
    compile gradleApi()
    compile localGroovy()
    compile ''

However now I run into the following exception which I am unable to resolve:

Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "org.gradle.api.internal.resources.CharSourceBackedTextResource.<init>(Lcom/google/common/io/CharSource;)V" the class loader (instance of java/net/URLClassLoader) of the current class, xyz/StartScriptGenerator, and the class loader (instance of org/gradle/internal/classloader/MutableURLClassLoader) for the method's defining class, org/gradle/api/internal/resources/CharSourceBackedTextResource, have different Class objects for the type com/google/common/io/CharSource used in the signature

Question: is there a way to get the guava libraries included in the compile class path that does not produce the linkage error?

I think the reason for this exception is, that you use a different guava
version than gradle does. try this one instead:


This is the version which is currently used in gradle master.


thanks for your response. Using that dependency doesn’t solve the problem. I even killed the build daemon just to be sure, but the same linkage error persists. I am using gradle 2.5.