簡體   English   中英

如何從命令行更新 Gradle 依賴項?

[英]How to update Gradle dependencies from command line?

我有以下build.gradle文件:

apply plugin: 'java'
apply plugin: 'eclipse'

sourceCompatibility = 1.7
version = '1.0'

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.springframework:spring-core:4.1.1.RELEASE'
    compile 'org.springframework:spring-context:4.1.1.RELEASE'
    testCompile group: 'junit', name: 'junit', version: '4.+'
}

我運行以下命令:

$ gradle --refresh-dependencies

但它什么也不做。 依賴項不會更新,也不會反映在類路徑上。 命令的輸出是:

:help

Welcome to Gradle 2.1.

To run a build, run gradle <task> ...

To see a list of available tasks, run gradle tasks

To see a list of command-line options, run gradle --help

BUILD SUCCESSFUL

Total time: 5.999 secs

不過,通過 Eclipse gradle 插件執行此操作是可行的。

gradle --refresh-dependencies <task>

我使用的是 Gradle 2.9,我用它來強制刷新:

gradle build --refresh-dependencies

您應該首先使用gradle clean ,然后gradle eclipse最后轉到 eclipse 中的項目並刷新項目,它適用於我的。

要執行 gradle 刷新,請通過命令提示符運行以下命令

gradle --refresh-dependencies 清理構建

如果您想在不運行構建(或所有任務)的情況下獲取依賴項,您可以使用dependency-verification

gradle --write-verification-metadata sha256 help

需要注意的是為解釋在這里

它是構建期間可以下載的依賴項的近似值。 特別是,如果一個任務使用我們所謂的“分離配置”(執行時的動態依賴圖),那么這些依賴將不會被下載,因為它們對 Gradle 是不透明的。

如果您有多個項目並且只想在一個項目上執行 clean-eclipse(不帶引號)

gradle 'project name':clean 'project name':eclipse --refresh-dependencies

在您的 IDE 中刷新項目后。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM