Bug creating buildscript configuration

The following code seems to fail to create a buildscript configuration:

buildscript {
    configurations {
        gradleCommon
    }

    repositories {
        mavenCentral()
    }

    dependencies {
        gradleCommon 'com.example:artefact:1.0.0'
        classpath 'com.bmuschko:gradle-tomcat-plugin:2.0'
        classpath 'mysql:mysql-connector-java:5.1.27'
    }
}

I created this bug report because I was told this is a bug and should be reported, original post on stackoveflow: http://stackoverflow.com/questions/31227387/how-to-create-gradle-buildscript-configuration?noredirect=1#comment50514199_31227387

The API is working as documented. The buildscript block is associted with the ScriptHandler interface. If you look at the javadoc, you’ll see that ‘repositories’ and ‘dependencies’ are the only supported closures. There is a getConfigurations(), but no configurations(Closure configureClosure), which is why configurations.create(…) would work, but configurations { } definitely would not.

As far as it being a bug in the sense of not working the way users would expect, this is quite far from a normal use case. You’re wanting to put a hack on top of Matt’s hack in the other SO answer. Nothing is stopping you from doing this. You just need to call the API as designed.

One of the core devs can comment on this, but it seems like something they would specifically not want to add because it would make the API less clear on what the intended uses would be.

Ok. But then shouldn’t the error be on the 2nd line with the “configurations {” ? Shouldn’t is say something about setConfiguration(Closure) not being a method on ScriptHandler ?

I agree that this is very hacky and I since then found a non hacky way of implementing what I want. But I am still trying to figure out why I got this error when I tried the above code.

Also, do you want to answer on my SO question or do you want me to do it and quote you?

What’s actually happening here is when you call configurations(Closure configureClosure) inside the buildscript { } block it is actually calling the method on the Project object since Groovy will continue searching up the closure scope until it finds a match. The result being that you are defining a project configuration thus the error saying that a configuration named ‘gradleCommon’ could not be found.

Ok, thank you I understand now.