compileJava can't resolve dependency already present in cache

I am relatively new to the Gradle world and started migrating a project from maven to gradle.

The problem is that I have one dependency that is present in the cache and I can see the same dependency in the classpath with the following statement.

println sourceSets.main.compileClasspath.asPath

This shows me all the compile classpath that include the dependency I need. But during the compileJava task, I am getting compilation errors that the dependency is missing.

This is how I have defined that particular dependency in dependencies{} task

compile (’::‘version’’) {
exclude(module: ‘cxf-api’)
}
runtime (’::‘version’’ {
exclude(module: ‘cxf-api’)
}