Error with dependencySubstitution in includeBuild for plugin under gradle 7

Hi,

We have a gradle project in version 6.8.3 that we would like to be migrated to version 7.x.
When we have tried to build it with version 7 we get the following error:

Could not find method dependencySubstitution() for arguments [settings_7okdbr2rmh271byw0v41j9gqp$_run_closure1$_closure2$_closure5@2c0cbb2a] on object of type org.gradle.internal.composite.DefaultConfigurableIncludedPluginBuild.

This comes from a section in the settings.gradle file like the following:
pluginManagement {
includeBuild(‘directory/pluginA’) {
dependencySubstitution {
substitute module(‘org.example:org.example.gradle.pluginA’) using project(‘:’)
}
}

The reason seems to be that dependencySubstitution has been removed in version 7 for included plugin builds.
Nevertheless, I have not found in the release notes that this has been deprecated. Have I missed anything?

If this has been deprecated, could someone point me to a way to solve this issue in our current project?

Thanks in advance,

Alberto

pluginManagement { includeBuild { ... } } never had dependencySubstitution.
You confuse that with the top-level includeBuild.
Even for top-level it is imho better not to use dependency substitutions but fix the builds where possible, so that it works without manual substitution rules.
But for plugins this is irrelevant anyway, as the plugin ID is the important part and there no substitution is necessary.

Thanks a lot for your answer. Strange enough, gradle 6.8.3 does not give any error when using the configuration I showed.
I have moved those lines out of the pluginManagement section and now I do not get that error under gradle 7.5.
Still I will need to put some effort to complete the migration.

Ah, I was almost right.

If you compare
https://docs.gradle.org/6.8.3/javadoc/org/gradle/plugin/management/PluginManagementSpec.html
and
https://docs.gradle.org/7.5.1/javadoc/org/gradle/plugin/management/PluginManagementSpec.html
you see the diffference.

6.8.3 did not have pluginManagement { includeBuild { ... } } at all.
Having it inside pluginManagment { ... } just had no additional effect.
It worked the same as if you had it written on top-level.
Now with 7.x there is pluginManagement { includeBuild { ... } } but without that substitution rule as it is for plugins and there substitution is not necessary.

So actually I’d recommend removing the substitution rule and keep it inside pluginManagement, as it is for a Gradle plugin.

As I a am quite new with Gradle and I have just inherited this project, moving the includeBuild { ... } out of pluginManagment { ... } has been the easy way to remove the error.

Any help on how to remove the substitution rule in my case will be highly appreciated.

Just delete it.
As long as you are applying plugins by ID, which you should do anyway, it will work.
So just

pluginManagement {
    includeBuild('directory/pluginA')
}