Gradle to identify which tests to run

I have a big java codebase in Gradle with hundreds of sub-projects. Some sub projects are independent (not in the builg graph), and even though I change java source code in there, gradle runs all the tests available for all projects. Can gradle identify where to run or not tests automatically?

If you have a test task that is executing when you think it shouldn’t be, you can run gradle with -i to output additional information about why gradle thinks that task is not up-to-date. For example, when I modify a source file and the compile task needs to execute:

Task :compileJava
Caching disabled for task ‘:compileJava’ because:
Build cache is disabled
Task ‘:compileJava’ is not up-to-date because:
Input property ‘stableSources’ file C:\Users\Chris Dore\Projects\gradle-plugin-examples\widget-plugin\src\main\java\com\github\oesolutions\gradle\widget\WidgetPlugin.java has changed.