如何在不实际构建东西的情况下创建gradle下载依赖项 [英] How to make gradle download dependencies without actually building things

查看:98
本文介绍了如何在不实际构建东西的情况下创建gradle下载依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在新环境中,gradle build需要花费相当长的时间,因为必须下载所有依赖项.

On a new environment gradle build takes quite a while because all dependencies have to be downloaded.

有没有一种方法可以仅下载依赖项以加快后续构建速度?

Is there a way to only download dependencies in order to speed up the following build?

通过这种方式,我们可以例如预先填充CI构建环境.

That way we could for example already prefill a CI build environment.

推荐答案

已针对Gradle 6+更新.

Updated for Gradle 6+.

一些注意事项:

  • 这种新方法将jars下载到一个文件夹中,然后删除该文件夹.因此,将罐子放在Gradle缓存中的结果是一个副作用.
  • 它当前使用为main源集配置的jar,但可以推广.
  • 尽管既不高效也不美观,但如果您确实需要jar(以及传递依赖项),它可能会很有用:只需注释掉runtime文件夹的删除即可.
  • This new approach downloads jars into a folder, and then deletes the folder. So the result of having the jars in the Gradle cache is a side-effect.
  • It currently uses jars configured for the main source-set but could be generalized.
  • Even though it is neither efficient nor elegant, it can be useful if you actually want the jars (and transitive dependencies): simply comment-out the deletion of the runtime folder.

当您想要 jars(以及传递依赖项)时,此解决方案会很方便,因为您只需注释掉删除文件夹即可.

This solution can be handy when you want the jars (and transitive dependencies), as you simply have to comment-out deleting the folder.

考虑以下build.gradle(作为任意的具体示例):

Consider this build.gradle (as an arbitrary, concrete example):

apply plugin: 'java'

dependencies {
    implementation 'org.apache.commons:commons-io:1.3.2'
    implementation 'org.kie.modules:org-apache-commons-lang3:6.2.0.Beta2'
}

repositories { 
   jcenter()
}

task getDeps(type: Copy) {
    from sourceSets.main.runtimeClasspath
    into 'runtime/'

    doFirst {
        ant.delete(dir: 'runtime')
        ant.mkdir(dir: 'runtime')
    }

    doLast {
        ant.delete(dir: 'runtime')
    }
}

示例运行:

$ find /Users/measter/.gradle/caches -name "commons-io*1.3.2.jar"

$ gradle getDeps

$ find /Users/measter/.gradle/caches -name "commons-io*1.3.2.jar"
/Users/measter/.gradle/caches/modules-2/files-2.1/commons-io/commons-io/1.3.2/[snip]/commons-io-1.3.2.jar

这篇关于如何在不实际构建东西的情况下创建gradle下载依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆