11

How do you add dependencies into build.gradle then work with those dependencies straight away in the IDE? (I've tried it with STS & Netbeans)

Here is the long story: I was following springs consuming rest tutorial (modifying it slightly to suit my own rest service and objects). I started a new gradle project, then added the dependencies to build.gradle. Then when I added RestTemplate into the main application file, I could not resolve it. I tried building the project and while I noted it downloaded the dependencies I still could not resolve RestTemplate (nor @JsonIgnoreProperties(ignoreUnknown=true)). In Spring Tool Suite I tried restarting the application and nothing changed. In Netbeans I tried restarting the application and it worked! But I'd rather have more control over this than trial'n'error. What's the proper procedure?

Edit Peter has answered STS in the comments. Netbeans anyone?

1
  • 2
    In STS you just need to right-click on the project and select Gradle -> Refresh Dependencies. Oct 29, 2013 at 7:42

3 Answers 3

38

I'm the developer of the NetBeans integration of Gradle. In NetBeans, if you edit your build script, you have to reload the project for NetBeans to detect the changes. You can reload the project by selecting "Reload project" in the context menu of the project. In practice, you should only reload, if you have adjusted the compile time dependencies.

Since plugin version 1.2.7, if you are using Gradle 1.9 or above (Gradle 1.8 does not work properly with NetBeans: debugging features will be broken), more exotic non-standard configurations are detected automatically as well (adding a new source set with different set of dependencies, provided dependencies, ect.).

I have set up a Wiki page which you might want to read if you would like to know more.

7
  • 5
    Is it terribly difficult to incorporate the classpath properties in a Java context such that we don't get the red squiggly lines underneath dependency imports and such?
    – JagWire
    Aug 19, 2015 at 17:24
  • @JagWire I'm having this problem too, and it makes it pretty much impossible to develop since I have no autocompletion or anything. Any solutions?
    – nhouser9
    May 8, 2017 at 19:41
  • @nhouser9 From your comment, it is not possible to tell what the issue is. If you think there is an issue, you should report it on: github.com/kelemen/netbeans-gradle-project/issues May 9, 2017 at 20:29
  • @AttilaKelemen I opened a separate question with more details if you are curious. I don't really think there is a bug in the plugin, I think I am doing something wrong. However, I have no idea what that may be. stackoverflow.com/questions/43837698/…
    – nhouser9
    May 10, 2017 at 3:46
  • In NetBeans 11.2, the "Reload" item is somehow missing Gradle project in the context menu. For Maven project, however, the "Reload" item is still there. I have to restart the IDE to see the latest compile lib changes. Am I missing something?
    – q3769
    Dec 3, 2019 at 18:06
1

It depends on your IDE. In IntelliJIDEA, you use the Gradle support to access the JetGradle plugin. You can use that to import dependencies and make sure the IDE is aware of any changes to your build script.

Personally, I find the Grade support in IntelliJ merely adequate. It isn't nearly as good as the Maven support. But I also prefer Gradle so much more to Maven that I live with it.

Note also that Gradle provides an IntelliJIDEA plugin. This enables you to build a project in IntelliJ from the build file. This is good but not as good as I would like.

Hopefully others can chime in on the pros and cons of other IDE's when it comes to Gradle.

2
  • Check out the Gradle support in IDEA 13 EAP. It's much better than in 12. Oct 29, 2013 at 7:43
  • 2
    For those who don't know, @Peter is the author of the testing framework Spock (code.google.com/p/spock) and a lead on Gradle. Definitely someone to pay attention to.
    – Vidya
    Oct 29, 2013 at 15:02
0

For Netbeans, I just have the same issue and I deleted the .gradle/chaches folder from my root user folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.