如何在Gradle中更新依赖项

7

有没有人能告诉我如何在Gradle中执行类似于 maven install -U(更新依赖项)的操作?

我遇到了问题,我已经在build.gradle文件中添加了新的依赖项。

dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile("org.springframework.boot:spring-boot-starter-security")
    runtime('com.h2database:h2')
    testCompile('org.springframework.boot:spring-boot-starter-test') 
}

新的依赖关系是:

compile("org.springframework.boot:spring-boot-starter-security")

在构建或项目同步期间,我的IntelliJ (版本14)甚至不尝试下载这个新的依赖项(我使用gradle版本2.5)。
在Maven项目中,IntelliJ 有像下载Maven依赖项的东西。但对于Gradle,我没有看到类似的东西。我的项目看起来像这样。
有人可以告诉我为什么我在项目列表中看不到任何*.jar 文件,就像Maven那样吗? enter image description here

你可以在Gradle构建脚本中添加idea插件,使用apply plugin: 'idea'语句。然后在添加新依赖项后运行gradle idea命令,它会自动下载依赖项。 - Opal
2个回答

4

使用 IntelliJ

在 Gradle 工具窗口中,单击刷新按钮。以下是屏幕截图:

Gradle tool window

使用终端

您必须在 build.gradle 文件中添加以下代码行:

apply plugin: 'idea'

如果您添加了一些依赖项并且想要同步IntelliJ,则只需使用命令:

gradle idea

非常好,非常感谢,这对我帮助很大。您知道如何从控制台/终端执行此任务吗? - Piotr Żak

0
如果您在查找Gradle工具窗口时遇到问题,可以在以下位置找到它:
视图 | 工具窗口 | Gradle

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接