Provided scope for plain java projects

I am following this approach:

http://forums.gradle.org/gradle/topics/how_do_i_best_define_dependencies_as_provided

to create a provided scope for some of my plain java projects. Now I would like to move this configuration to a custom plugin I am writing. Creating the new configuration is simple but how do I specify the following:

sourceSets {
  main {
    compileClasspath += configurations.provided

on the project object in the plugin? I have tried:

project.getConfigurations().create("provided");
    project.compileClasspath += project.configurations.provided

but get:

Could not find property 'compileClasspath' on root project ...

From the docs this should be supplied when applying the java plugin:

http://www.gradle.org/docs/current/userguide/java_plugin.html

You can use exactly the same syntax as in the build script, except that it’s ‘project.sourceSets’ and ‘project.configurations’.

hm maybe I am blind I have now tried:

project.configurations.create("provided")
     project.sourceSets.compileClasspath += project.configurations.provided

but it gives:

  • What went wrong: Could not find property ‘compileClasspath’ on SourceSet container.

The ‘compileClasspath’ property is a property of the SourceSet and not the SourceSetContainer class.

Thanks:

project.sourceSets.main.compileClasspath += project.configurations.provided

works