Include and includes misbehave for same pattern

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

and when includes is


I see BalancedBraces is compiled too and placed in test folder

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

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 and gives you the result which is a Set<String>.
<anyCollection>[...] calls Collection#getAt 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

include 'foo'

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.

1 Like

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.

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.

1 Like

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.

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

1 Like