Cache files downloaded in build script

(Abel Salgado Romero) #1


I am customizing a build script to download & parse a POM XML, and dynamically include some of the dependencies during ‘afterEvaluate’.
You can see it here:

It works fine but I think downloading it every time is a bit of an overkill. I could store it manually inside ‘./gradle’ folder and check if it exists. But I am wondering if there’s an official way to tell the build script this needs to be cached…like inputs in a task.

cheers & thanks,

(Schalk Cronjé) #2

I’m not sure what you are trying to achieve. It seems tat you explicitly want to add the groovy-all & log4j dependencies to compile. Why not just add them to compile anyway without jumping through the hoops of parsing the POM?

(Abel Salgado Romero) #3

I want add the same versions used by the SoapUI version automatically but without all the rest. For instance if I use soapUI 4.5.2 (, it will include groovy-all 1.8.0. That way I make sure I don’t use any feature not available and the change will only require changing a single property value.

Also, there’s a second reason, that is just for fun and personal learning ^^

(Stefan Oehme) #4

Why not just exclude what you don’t want instead of implementing your own “include” mechanism?

(Schalk Cronjé) #5

That is a good approach except that one has to know what to exclude. There is no select-only-these-transitive-dependencies option.

If @abelsromero want to go this route he would have to do

compile "com.smartbear.soapui:soapui:$soapuiVersion"

then run gradle dep and look at the transitive dependencies for SoapUI. He would then have to chaneg the script to

compile ("com.smartbear.soapui:soapui:$soapuiVersion") {
    exclude group: 'org.reflections'
    // and so on for everyone of the 20+ deps he does not want to include 

That is not slick at all.

(Abel Salgado Romero) #6

That was my first approach, but as @Schalk_Cronje said I had to go through dependencies…and it was a huge list.
In fact what I am doing here is kind of a “includeOnly” option, because I just want the dependencies for code completion, not for actual compilation and deployment.

(Rahul Somasunderam) #7

Does this help?

apply plugin: 'groovy'

repositories {
    maven { url "" }

configurations {

ext {
    soapuiVersion = '5.2.1'
    requiredArtifacts = ['groovy-all', 'log4j']

dependencies {
    soapui("com.smartbear.soapui:soapui:$soapuiVersion") {
        exclude module: 'cajo'
        exclude module: 'jtidy'
                    findAll { in requiredArtifacts }.
                    collect { }

(Stefan Oehme) #8

Note that this is resolving dependencies at configuration time, slowing down every build, even when you just do gradle clean

(Abel Salgado Romero) #9

Thanks a lot to all, but I feel we are digressing a bit.
We are focussing on the dependency management and the question was more focused on caching files downloaded during the build.

@rahulsom I like that, even when it’s not practical to my case here it will be helpfull for another stuff I have :thumbsup:

(Schalk Cronjé) #10

In short, the only simple way I know of to use caching in Gradle is to put it in a configuration. The other way is to use the VFS plugin and create a download task.