1

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

Mansur Nashaev
  • 293
  • 1
  • 5
  • 15
  • Possible duplicate of [Best way to add Gradle support to IntelliJ Project](http://stackoverflow.com/questions/26745541/best-way-to-add-gradle-support-to-intellij-project) – acm Sep 08 '16 at 14:45

3 Answers3

2

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.

Benjamin Muschko
  • 32,442
  • 9
  • 61
  • 82
2

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.
alexbt
  • 16,415
  • 6
  • 78
  • 87
1

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
pitaside
  • 650
  • 10
  • 14
  • It works but how to make gradle worked without restarting? – Mansur Nashaev Sep 09 '16 at 22:23
  • U can do that my re-sync the project. How to do that, look for the Gradle toolbar by the right side of your IDE, then click the sync icon to allow iDEA to re-sync the project. Hope that helps – pitaside Sep 09 '16 at 23:00