Mansur Nashaev
Mansur Nashaev

Reputation: 313

Gradle not downloading dependencies in Java EE

I am learning to create a java ee web application. In intellij idea I created a project using the project wizard: Java Enterprise -> Web Application. Then I created a build file.gradle in the project root, and call the gradle init, gradle build in the terminal. Here is the build file.gradle

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'idea'

repositories {
    jcenter()
    mavenCentral()
}

sourceCompatibility = 1.5

dependencies {
    compile 'org.slf4j:slf4j-api:1.7.21'
    compile 'com.squareup.retrofit2:converter-gson:2.0.2'
    testCompile 'junit:junit:4.12'
}

When I add a dependency and do gradle build, they are not loaded into the project. For example, the Gson library is not available in the code. How to tell Gradle to download the libraries so I could use them? What i'm doing wrong?

enter image description here

Upvotes: 1

Views: 1166

Answers (3)

pitaside
pitaside

Reputation: 678

When your run gradle build does it shows the dependency downloading, if so then the dependency has downloaded but not avaialable in intellij Quick fix is to close the project

  • Remove the .idea folder and the .iml file
  • Next re-open your intellij
  • Click on File -> choose New -> Project From Existing Source
  • Select your project build.gradle
  • Allow Intellij to do the rest

Upvotes: 1

alexbt
alexbt

Reputation: 17055

Your project is not backed by gradle. The easiest way for me to fix this is to :

  • close and re-open the project;
  • the bottom-right of the screen should display (x) Event log (the digit in parentheses being the number of events raised);
  • click on Event log;
  • a tooltip pops up, click on Import Gradle project;
  • a window pops up, configure gradle options.

Upvotes: 2

Benjamin Muschko
Benjamin Muschko

Reputation: 33436

IntelliJ's Gradle integration does not automatically reflect changes you make in your build script. You will have manually initiate the synchronization between build script and IntelliJ project.

Upvotes: 2

Related Questions