Cache files downloaded in build script

Hi,

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,

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?

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 (http://smartbearsoftware.com/repository/maven2/com/smartbear/soapui/soapui/4.5.2/soapui-4.5.2.pom), 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 ^^

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

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.

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.

Does this help?

apply plugin: 'groovy'

repositories {
    jcenter()
    maven { url "http://smartbearsoftware.com/repository/maven2" }
}

configurations {
    soapui
}

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

dependencies {
    soapui("com.smartbear.soapui:soapui:$soapuiVersion") {
        exclude module: 'cajo'
        exclude module: 'jtidy'
    }
    compile(
            configurations.soapui.resolvedConfiguration.resolvedArtifacts.
                    findAll { it.moduleVersion.id.module.name in requiredArtifacts }.
                    collect { it.moduleVersion.id.toString() }
    )
}
1 Like

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

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:

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.