# Unable to acces ProjectSourceSet via rule based model

**URL:** <https://discuss.gradle.org/t/unable-to-acces-projectsourceset-via-rule-based-model/13118>\
**Category:** Help/Discuss\
**Created:** [December 8, 2015, 7:07am UTC](https://discuss.gradle.org/t/unable-to-acces-projectsourceset-via-rule-based-model/13118 "2015-12-08T07:07:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jan](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@Jan](https://discuss.gradle.org/u/Jan)\
**Post date:** [December 8, 2015, 7:07am UTC](https://discuss.gradle.org/t/unable-to-acces-projectsourceset-via-rule-based-model/13118/1 "2015-12-08T07:07:11Z")

</div>

Hello and good morning from germany.

I want to read the ProjectSourceSet via the rule based model. Running gradle model tells me, that my ProjectSourceSet contains two entries, and that the rule in which i try to read the ProjectSourceSet was applied to the ProjectSourceSet model object. However, within the rule, the ProjectSourceSet contains zero entries.

I tried to anotate my rule with @Mutate, @Validate and @Finalize, to no success. My understanding is, that the ProjectSourceSet model object should be complete in rules with @Validate or @Finalize, but obviously i have not figured out the big picture yet. What else could i do to access the ProjectSourceSet?

From gradle model:

```
+ sources
| Type: org.gradle.language.base.ProjectSourceSet
| Value: [C++ source 'mathematics:cpp', C++ source 'myLib:cpp']
| Creator: LanguageBasePlugin.Rules#sources
| Rules:
   ? MyPlugin.RuleSourceInnerClass#read

```

Source code of Rule:

```
public static class RuleSourceInnerClass extends RuleSource {

    @Validate
    void read(ProjectSourceSet projectSourceSet) {
        println 'Rule fired'
        println projectSourceSet.size() // <-- results to 0
    }
}
```

---

<div class="post-metadata">

**Author:** ![adammurdoch](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/adammurdoch/32/17_2.png) [@adammurdoch](https://discuss.gradle.org/u/adammurdoch)\
**Post date:** [December 9, 2015, 10:31pm UTC](https://discuss.gradle.org/t/unable-to-acces-projectsourceset-via-rule-based-model/13118/2 "2015-12-09T22:31:51Z")

</div>

This is a bug. The rule you have there should work, so that when the `read()` method is called, the `projectSourceSet` collection you get should not be empty, and should contain all of the source sets defined in the project (for all components and binaries).

---

<div class="post-metadata">

**Author:** ![Jan](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@Jan](https://discuss.gradle.org/u/Jan)\
**Post date:** [December 10, 2015, 8:36am UTC](https://discuss.gradle.org/t/unable-to-acces-projectsourceset-via-rule-based-model/13118/3 "2015-12-10T08:36:59Z")

</div>

Thanks for the feedback. I will try it again with the next version.
