I'm working on a Spring Boot Application using Gradle as a dependency management system or whatever.
After adding a couple of dependencies to the build script and rebuilding the project, I would expect the build to have added those dependencies to the project. And yet, it does not. Cannot import those libraries. What step am I missing?? I am a node.js developer and am used to just running an npm install
to import dependencies.
Here are the dependencies:
dependencies {
compile('org.mongodb:mongodb-driver:3.2.2')
compile('org.springframework.boot:spring-boot-starter-data-mongodb')
}
Not that it matters, since they were not added to the project, but here are the eventual import statements:
import org.mongodb.MongoClient;
import org.springframework.data.mongodb.core.MongoTemplate;
To view Gradle dependencies as a diagram, click on the Show Dependencies icon on the Gradle tool window toolbar or use the shortcut Alt+Shift+Ctrl+U on Linux and Windows / Alt+Shift+Cmd+U on macOS.
Click Add and reload your project. IntelliJ IDEA adds a dependency to the build.gradle file. IntelliJ IDEA also adds the dependency to the Dependencies node in the Gradle tool window and to the External Libraries in the Project tool window.
Yet, keep in mind that the IntelliJ IDEA compiler does not support some parts of the Gradle project build processing and might cause problems in building your project correctly. Use this list to select how you want to run tests in your project.
My IntelliJ didn't recognize some dependencies from the build.gradle. My guess is that its a cache thing. So I did the following: Delete the gradle caches directory. Restart IntelliJ and refresh gradle dependencies. This worked for me and seems like a simple solution. Nice! I went to File -> Invalidate Caches/Restart which did the trick.
To resolve this issue, navigate to the Gradle Tool window via View -> Tool Windows -> Gradle Click the highlighted button to refresh all registered Gradle projects after changes have been made to the Gradle file. ‘Refresh all Gradle projects‘ will create/restore project structure for all gradle modules in the IntelliJ project —
Ok, so there is a right-hand menu bar, viz:
And the gradle tab has a refresh option:
That'll do it. Ugh, ide's...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With