"You can't change a configuration which is not in unresolved state" when building for sonar

I get an exception “You can’t change a configuration which is not in unresolved state” on the following line

configurations {
  all*.exclude module: "org.osgi.foundation"
}

This is working in normal builds, but fails when I apply the sonar plugin.

Anyone got an idea on how to resolve this ?

The problem is that some plugins add their own configurations, and using ‘all’ includes them as well. To be on the safe side, you’ll have to explicitly list the configurations that you wish to alter. For example:

configurations {
  [compile, runtime]*.exclude module: "org.osgi.foundation"
}

PS: The upcoming revised Sonar plugin won’t have this problem.

Thanks ! That did the trick.