How to register a resource folder for generated resource files in a Gradle custom plugin?

Hi all,
I have a Gradle plugin to generate a properties file and I want to register the parent directory as a resource folder (to be recognized by Gradle so the file will be packaged into the final jar file).

Here is the groovy code (from my plugin) which does not work (the folder is not added to classpath and is not recognized as classpath entry when imported to Eclipse using Buildship)

// File: GitPropertiesPlugin.groovy
class GitPropertiesPlugin implements Plugin<Project> {
    void apply(Project project) {
        project.getPlugins().withType(JavaPlugin.class, new Action<JavaPlugin>() {
            public void execute(JavaPlugin javaPlugin) {
                ...
                project.sourceSets.main.resources.srcDir "${project.buildDir}/generated-resources/main" // DOES NOT WORK!
            }
        })
    }
}

The similar logic will work in a build.gradle (but I don’t want the users to do it for every build.gradle file)

// File: build.gradle

sourceSets.main.resources.srcDir "$buildDir/generated-resources/main" // WORK!

We’ve done this with generated java code and it does work very well, but I don’t see the difference to your code (other than that it’s more verbose):

    @Override
    public void apply(final Project project) {
        // makes no sense without the java plugin
        project.getPluginManager().apply(JavaPlugin.class);
        ...
        final SourceSet main = project
                .getConvention()
                .getPlugin(JavaPluginConvention.class)
                .getSourceSets()
                .getByName(SourceSet.MAIN_SOURCE_SET_NAME);
        main.getJava().srcDir(generateTask.getOutputDirectory());
    }

Thanks @geissld . You are right. It should work with no problem. I found out that my actual code (not the example I provided) using a config from my plugin extension which is not available when plugin is being applied. So I have wrapped my logic inside a gradle.projectsEvaluated {… } block and now it worked.
NOTE: my example I provided above actually works, only my real code (using extension config) didn’t work and needs a gradle.projectsEvaluated {… } block.