Gradle does not refresh dependencies

I am using Gradle plugin. In apply function I have added DependencyResolutionListener , and in beforeResolve method I am adding for example a dependency to a project:
compileDeps.add(project.getDependencies().add("compile", "com.squareup.picasso:picasso:2.5.0"));

After that I have iterated over the dependencies for compile Configuration, and I can see that dependency exists, but I can not see it in External Libraries in IDEA. Also if I manually refresh gradle file, but changing something in build.gradle, then dependency is there.

Is there a way to programmatically force gradle to refresh dependencies, or maybe a better way to add dependencies as explained above.

Thanks.

That’s because beforeResolve is only called on the configuration that is resolved. The compile configuration is not resolved when importing into IDEA. IDEA will use compileClasspath, runtimeClasspath, testCompileClasspath and testRuntimeClasspath by default.

What’s the reason for doing this in beforeResolve? I.e. why not add the dependency right away?

I need to check whether some dependencies are declared in build.gradle file, and if they exist then I am adding another library (extension). Because of that I was doing it in beforeResolve callback.

Is it possible to do it in a better way? @st_oehme

Thanks in advance.

Well, you could hook into all Configurations instead of just compile, see if they contain the dependencies you are looking for and add the extra ones with beforeResolved.

compileDeps.add(project.getDependencies().add(“compile”, “com.squareup.picasso:picasso:2.5.0”));

The above is probably not what you wanted - You are adding the dependency twice. Instead, use dependencies.create.

Thanks for advices. Gradle is doing part of its job really well.
IDEA does not refresh dependencies unfortunately.
But that is another problem.

Thank you.