What are best practices for library dependencies in a version-controlled project?

I'm a relatively new IntelliJ IDEA user, and struggling a bit with setting up a version controlled project that also uses library dependencies. We've got a project that we've set up that integrates with gradle for building a releasable app, but we also use IntelliJ's normal build strategy for project work. The challenge is how to manage library dependencies. I can put 'em in Project Settings, and then if we version-control the appropriate XML files, all users see those config settings. But those settings get overwritten if someone clicks the "refresh" button in the Gradle tools screen. Alternatively, I've tried putting our library dependencies in our build.gradle file. That requires that we always synchronize them back to Project Settings via the Gradle refresh button, which doesn't always seem to work reliably. (Perhaps it does work and I need to put all my effort there and learn how to do it right. The feedback is certainly limited.) Most confusing to me is that when I refresh a gradle project, a matching library which has been previously added to the Project Settings window is grayed out. I have two general (categories of) questions which I've been unable to find good answers for:

1. How does gradle refresh work, precisely, with regards to IDEA project settings? What the heck is going on when a library is getting grayed out in the Project Settings window? What's going on in the dot files and in the directory structure? Understanding that would help me a lot in determining how to best organize version control.

2. What are best practices for including library dependencies in a version-controlled project? Is Gradle just a bad idea in this case? Or is it exactly where I should be focused? Would Maven work better? Said differently, if you were starting a brand new version-controlled project with library dependencies and a desire to use IDEA's excellent development tools but also to build applications, how would you structure it?

Thanks for your help, much appreciated.

2 comments
Comment actions Permalink

I think the general idea is that you put all your dependencies into maven or gradle files (and check them into VCS of course) and let IDEA pick it up from there.

I use almost only maven and it basically works ok there (though not great).
IDEA auto-refreshes whenever the maven poms are changed. The pom.xml's are checked in, IDEA's module (*.iml) files aren't.

In a larger project with complicated maven structure there are some hiccups and IDEA needs the occasional manual refresh.

AFAIK for gradle it _should_ work the same, but it may be that there are some more glitches.
If you notice something specific that does not work in IDEA with gradle, it is probably best to file an issue in JetBrains tracker ( https://youtrack.jetbrains.com ).
I found JetBrains to be very responsive in general especially if you manage to create a reproducible self-contained example that shows a bug.

0
Comment actions Permalink

Thanks for the thoughts. I've just switched to Maven, and it does (so far) seem to be working a lot smoother.

0

Please sign in to leave a comment.