Gradle : Copy all test dependencies to a zip file

2019-04-28 18:38发布

问题:

I am quite new to gradle, so maybe I am asking something quite easy....

I am looking for a solution to put all dependencies in scope testCompile into a zip file. I checked http://forums.gradle.org/gradle/topics/how_do_i_make_a_zip_to_contain_dependency_artifacts but this seems to work only for runtime dependencies. I also checked http://www.gradle.org/docs/current/userguide/working_with_files.html Chapter 16.8, but that did not work either.

When I access via configurations.testCompile.allArtifacts.files, my zip is always empty. When I acces via configurations.testCompile.allDependencies I can see all deps but I am lacking the path of the dependencies.

It is hard to believe to me, that I am the only one ever had this problems since I did not find any solution.

Any help appreciated!

回答1:

This works for me: http://forums.gradle.org/gradle/topics/how_do_i_make_a_zip_to_contain_dependency_artifacts

Sample task:

task zip2(dependsOn: 'testCompile', type: Zip) {
    from configurations.testCompile.allArtifacts.files
    from configurations.testCompile
    archiveName project.name + "_test_"+ project.version
}

Then run:

gradle test zip2

Zip file will be generated at:

build\distributions