Substitute dependency with a local file

I cannot add substitution logic to substitute some modules with local files from my plugin.
I’m adding flatDir repo. So far its ok
My local files have names like "group-name.jar"
So I need to give these dependencies another names because flatDir repos do not try to match this pattern
I tried enumerate files in that flat dir and add substitution rule for each of them like substitute module("org.example:foobar") with module("org.example:org-example-foobar"). No success
I also tried resolutionStrategy.eachDependency { it.useTarget(...) }. No success
I tried to add artifacts to dependencies after project evaluated. No success
And only thing that I found to work is adding some closure-transformer which addes artifact to a dependency just after creation like project.dependencies { addArtifactToDependency(compile("org.example:foobar:1.0")) }
This closure adds an artifact like this dependency.artifact { it.name = "${dependency.group.replace('.', '-')}-${dependency.name}" it.type = "jar" it.extension = "jar" }

Is there any way to make this implicit?

gradle 3.3