How to download dependencies in gradle

前端 未结 8 1353
暗喜
暗喜 2020-11-30 23:00

I have a custom compile task.

task compileSpeedTest(type: JavaCompile) {
    classpath = files(\'build\')
    source = fileTree(\'src/test/java/speed\')
             


        
8条回答
  •  孤街浪徒
    2020-11-30 23:30

    A slightly lighter task that doesn't unnecessarily copy files to a dir:

    task downloadDependencies(type: Exec) {
        configurations.testRuntime.files
        commandLine 'echo', 'Downloaded all dependencies'
    }
    

    Updated for kotlin & gradle 6.2.0, with buildscript dependency resolution added:

    fun Configuration.isDeprecated() = this is DeprecatableConfiguration && resolutionAlternatives != null
    
    fun ConfigurationContainer.resolveAll() = this
      .filter { it.isCanBeResolved && !it.isDeprecated() }
      .forEach { it.resolve() }
    
    tasks.register("downloadDependencies") {
      doLast {
        configurations.resolveAll()
        buildscript.configurations.resolveAll()
      }
    }
    

提交回复
热议问题