Dependency substitution in a separate composite build

The include build dependcy substitution works great for the project it is included in like this

include ':app'

includeBuild('../lib_project') {
    dependencySubstitution {
        substitute module('com.github.myname:lib_project_name') using project(':lib')
    }
}

The dependency module defined in the :app project gets subsctituted correctly.

But it doesn’t work in a separate composite build, i.e. when both projects are included into a higher level composite:

includeBuild('../app_project')
includeBuild('../lib_project') {
    dependencySubstitution {
        substitute module('com.github.myname:lib_project') using project(':lib')
    }
}

The dependency module defined in app_project:app does not get subsctituted in this case.

Is there a way to make it work?