Provided scope for plain java projects

I am following this approach:

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.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:

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.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.


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