When changing things you need to led intellij reload the gradle config (it may or may not do it automatically depending on your config) and do the indexing, it can take some time depending on the size of the library.
It may also depend on what you change. There is a good chance that intellij won’t monitore local file changes in your lib directory since this is not how gradle is generally used.
If you have problems with imports you can trigger the gradle config reload manually. That should solve the issue you describe.
There should be a button for it in the gradle tool window. I don’t have intellij open right now so I can’t tell you how it looks like but I think it’s a generic reload icon. I think you can open the tool window under View>Tools>Gradle. You cou also add a keyboard shortcut for this (both opening the gradle window and the reload).
Your build.gradle file looks correct. I just wanted to add some context to @bjonnh’s answer why intellij might not recognise the change. IDEA only monitores the gradle files themself.
The GUI methods only work with IDEA internal build system. Gradle is spearate from that. That said some changes in there eg. JVM version do affect the gradle build as well. It’s a bit complicated, but in general you need to define all build settings in .gradle files.