简体   繁体   English

如何从命令行更新 Gradle 依赖项?

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

I have following build.gradle file:我有以下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.+'
}

I run following command:我运行以下命令:

$ gradle --refresh-dependencies

But it does nothing.但它什么也不做。 The dependencies do not get updated and do not reflect on classpath.依赖项不会更新,也不会反映在类路径上。 The output from command is:命令的输出是:

: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

Doing this via Eclipse gradle plugin is working though.不过,通过 Eclipse gradle 插件执行此操作是可行的。

gradle --refresh-dependencies <task>

我使用的是 Gradle 2.9,我用它来强制刷新:

gradle build --refresh-dependencies

您应该首先使用gradle clean ,然后gradle eclipse最后转到 eclipse 中的项目并刷新项目,它适用于我的。

for gradle refresh to perform , run the below command via command prompt要执行 gradle 刷新,请通过命令提示符运行以下命令

gradle --refresh-dependencies clean build gradle --refresh-dependencies 清理构建

If you want to fetch dependencies without running build (or all the tasks), you could use dependency-verification :如果您想在不运行构建(或所有任务)的情况下获取依赖项,您可以使用dependency-verification

gradle --write-verification-metadata sha256 help

Note that as explained here :需要注意的是为解释在这里

it's an approximation of what dependencies could be downloaded during a build.它是构建期间可以下载的依赖项的近似值。 In particular, if a task uses what we call a “detached configuration” (a dynamic dependency graph at execution time), then those dependencies will not be downloaded, because they are opaque to Gradle.特别是,如果一个任务使用我们所谓的“分离配置”(执行时的动态依赖图),那么这些依赖将不会被下载,因为它们对 Gradle 是不透明的。

If you have multiple projects then and want to execute only on one project the clean-eclipse (without quotation marks)如果您有多个项目并且只想在一个项目上执行 clean-eclipse(不带引号)

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

after you just refresh the project in your IDE.在您的 IDE 中刷新项目后。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM