# Include and includes misbehave for same pattern

**URL:** <https://discuss.gradle.org/t/include-and-includes-misbehave-for-same-pattern/45282>\
**Category:** Help/Discuss\
**Created:** [March 31, 2023, 4:20am UTC](https://discuss.gradle.org/t/include-and-includes-misbehave-for-same-pattern/45282 "2023-03-31T04:20:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raja\_Nagendra\_Kumar1](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/raja_nagendra_kumar1/32/10491_2.png) [@Raja\_Nagendra\_Kumar1](https://discuss.gradle.org/u/Raja_Nagendra_Kumar1)\
**Post date:** [March 31, 2023, 4:20am UTC](https://discuss.gradle.org/t/include-and-includes-misbehave-for-same-pattern/45282/1 "2023-03-31T04:20:48Z")

</div>

source set compiled classes are different i.e when test include is  
` include ' **/test/** /*.java'`

I see only not test files are compiled and put in build folder

however with includes

 ![image](https://global.discourse-cdn.com/gradle/original/2X/1/1f558946903702606823dcd99fdcfc87d65de449.png)

and when includes is

` includes[' **/test/** /*.java']`

 ![image](https://global.discourse-cdn.com/gradle/original/2X/5/5c94084d76be79a7b0fb67b3f74ccce6e020429f.png)

I see BalancedBraces is compiled too and placed in test folder

 ![image](https://global.discourse-cdn.com/gradle/original/2X/0/083dc411a6b7038c9c53270561506b4a7a88fffa.png)

I expect the same behavior with include and includes as pattern did not change…

any reason for such behavior please, hope it is not gradle bug 🙂

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [March 31, 2023, 10:31am UTC](https://discuss.gradle.org/t/include-and-includes-misbehave-for-same-pattern/45282/2 "2023-03-31T10:31:55Z")

</div>

No, it’s not a bug in Gradle, you just don’t do what you think you do.  
You are basically tripping over Groovy syntax.  
`includes` calls [`PatternFilterable.html#getIncludes`](https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/util/PatternFilterable.html#getIncludes--) and gives you the result which is a `Set<String>`.  
`<anyCollection>[...]` calls [`Collection#getAt`](https://docs.groovy-lang.org/latest/html/groovy-jdk/java/util/Collection.html#getAt(java.lang.String)) from the GDK.  
This method returns a list of the values of the property with the given name on each of the collections elements.

In your case `includes` is empty and so the `getAt` also just returns an empty list and you effectively did nothing.  
If you would have any include already present, for example by doing

```groovy
include 'foo'
includes['baz']

```

it would try to get the property `baz` on the String `foo` and fail with a `MissingPropertyException`.

What you probably intended to do is `includes = [' **/test/** /*.java']`.

Issues like this are the reason I strongly recommend to use the Kotlin DSL instead. You immediately get type-safe build scripts, much better error messages if you mess up the syntax, and amazingly better IDE support, if you use a proper IDE like IntelliJ.

---

<div class="post-metadata">

**Author:** ![Raja\_Nagendra\_Kumar1](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/raja_nagendra_kumar1/32/10491_2.png) [@Raja\_Nagendra\_Kumar1](https://discuss.gradle.org/u/Raja_Nagendra_Kumar1)\
**Post date:** [April 5, 2023, 1:44pm UTC](https://discuss.gradle.org/t/include-and-includes-misbehave-for-same-pattern/45282/3 "2023-04-05T13:44:45Z")

</div>

Sorry, did not understand… other than that, gradle syntax is complex better use kotlin DSL for gradle.

Thank You for saying that I am missing rather and this observation of mine is not a grade bug… that is good enough clarity to learn more.

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [April 5, 2023, 2:37pm UTC](https://discuss.gradle.org/t/include-and-includes-misbehave-for-same-pattern/45282/4 "2023-04-05T14:37:40Z")

</div>

This is the important part to fix it ad-hoc

> What you probably intended to do is `includes = [' **/test/** /*.java']` .

Lines before were explaining why it behaves like it does.  
Lines after were the recommendation to use Kotlin DSL instead of Groovy DSL.  
🙂

---

<div class="post-metadata">

**Author:** ![Raja\_Nagendra\_Kumar1](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/raja_nagendra_kumar1/32/10491_2.png) [@Raja\_Nagendra\_Kumar1](https://discuss.gradle.org/u/Raja_Nagendra_Kumar1)\
**Post date:** [April 5, 2023, 4:19pm UTC](https://discuss.gradle.org/t/include-and-includes-misbehave-for-same-pattern/45282/5 "2023-04-05T16:19:44Z")

</div>

I have been trying to conver to Kotlin DSL, based on your recommendation… my first impression is kotlin DSL is lot of chars than gradle…

e.g many () are optional in gradle… any case it is more readable and clear…

From now on I shall use kotlin DSL as wholeheartedly thank you for such recommendation.

---

<div class="post-metadata">

**Author:** ![Raja\_Nagendra\_Kumar1](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/raja_nagendra_kumar1/32/10491_2.png) [@Raja\_Nagendra\_Kumar1](https://discuss.gradle.org/u/Raja_Nagendra_Kumar1)\
**Post date:** [April 5, 2023, 4:23pm UTC](https://discuss.gradle.org/t/include-and-includes-misbehave-for-same-pattern/45282/6 "2023-04-05T16:23:45Z")

</div>

> [@Vampire](#):
>
> `includes = [' **/test/** /*.java']` .

yes behavior is now the same as `include` when I use ‘=’ after `includes`  
Got it, that ‘=’ has made a huge difference in interpretation… 👌
