How to download dependencies in gradle

前端 未结 8 1295
暗喜
暗喜 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:44

    You should try this one :

    task getDeps(type: Copy) {
        from configurations.runtime
        into 'runtime/'
    }
    

    I was was looking for it some time ago when working on a project in which we had to download all dependencies into current working directory at some point in our provisioning script. I guess you're trying to achieve something similar.

    0 讨论(0)
  • 2020-11-30 23:47

    This version builds on Robert Elliot's, but I'm not 100% sure of its efficacy.

    // There are a few dependencies added by one of the Scala plugins that this cannot reach.
    task downloadDependencies {
      description "Pre-downloads *most* dependencies"
      doLast {
        configurations.getAsMap().each { name, config ->
          println "Retrieving dependencies for $name"
          try {
            config.files
          } catch (e) {
            project.logger.info e.message // some cannot be resolved, silentlyish skip them
          }
        }
      }
    }
    

    I tried putting it into configuration instead of action (by removing doLast) and it broke zinc. I worked around it, but the end result was the same with or without. So, I left it as an explicit state. It seems to work enough to reduce the dependencies that have to be downloaded later, but not eliminate them in my case. I think one of the Scala plugins adds dependencies later.

    0 讨论(0)
提交回复
热议问题