Unable to get the Gradle cached file location

In my project, I am using configurations.compile.collect.each to get the all compile dependencies file paths in the Gradle cache. But now we updated to Gradle plugin 4.4 and changed compile to api. But now I am unable to get the exact alternate to fetch the cached file location.I tried with variant.getCompileClasspath().each but it is returning
/.gradle/caches/transforms-1/files-1.1/ file path instead of /.gradle/caches/modules-2/files-2.1. Please help me how to get the caches/modules path for each dependency declared in dependencies with api and implementation.

If add both api and runtime for the same dependency then i can achieve my goal. But that may not be the proper solution. Is there any other way to achieve this? Please suggest me.