Gradle equivalent to Maven's “copy-dependencies”?

后端 未结 4 816
甜味超标
甜味超标 2020-12-01 16:20

In Maven-land, anytime I want to simply pull down the transitive dependencies for a particular POM file, I just open a shell, navigate to where the POM is located, and run:<

相关标签:
4条回答
  • 2020-12-01 16:43

    There's no equivalent of copy-dependencies in gradle but here's a task that does it:

    apply plugin: 'java'
    
    repositories {
       mavenCentral()
    }
    
    dependencies {
       compile 'com.google.inject:guice:4.0-beta5'
    }
    
    task copyDependencies(type: Copy) {
       from configurations.compile
       into 'dependencies'
    }
    

    Is it worthwhile to do a contribution? AS You can see it's really easy to do, so I don't think so.

    EDIT

    From gradle 4+ it will be:

    task copyDependencies(type: Copy) {
      from configurations.default
      into 'dependencies'
    }
    
    0 讨论(0)
  • 2020-12-01 16:50

    the dependency configuration of compile is deprecated in gradle 4.x. You need to replace that with default. So the above code-snippet becomes:

    dependencies {
      implementation 'com.google.inject:guice:4.0-beta5'
    }
    task copyDependencies(type: Copy) {
      from configurations.default
      into 'dependencies'
    }
    
    0 讨论(0)
  • 2020-12-01 16:57

    This is the equivalent Kotlin DSL version (added the buildDir prefix to make it copy the dependencies in the build folder):

    task("copyDependencies", Copy::class) {
        from(configurations.default).into("$buildDir/dependencies")
    }
    
    0 讨论(0)
  • 2020-12-01 16:59

    Here's another way to include dependencies. This could also be war instead of jar for web archives.

    dependencies {
        implementation 'my.group1:my-module1:0.0.1'
        implementation 'my.group2:my-module2:0.0.1'
    }
    
    jar {
        from {
            configurations.compileClasspath.filter { it.exists() }.collect { it.isDirectory() ? it : zipTree(it) }
        }
    }
    
    0 讨论(0)
提交回复
热议问题