Applying script from http - not fail when no network?


(Wujek Srujek) #1

I am configuring some common build scripts to have them available on our web server, so that I can use apply from: ‘http://server/gradle/build-base.gradle’ in our builds. This requires that the network is working. Is there anything I can do so that if the file is not there (because the network is down) the build doesn’t fail? The --offline switch doesn’t work for build scripts (I am using 1.6), but the scripts are cached somewhere, I guess? maven would use the parent pom (that’s what I’m trying to simulate) from the local repository in --offline mode. Is there anything similar in gradle? Or is there anything new that has similar functionality to parent poms from maven? wujek


(Peter Niederwieser) #2

It’s a known limitation of script plugins, and will hopefully by removed some day. Until then, the best (and only) solution is to write a binary plugin instead, which will be cached like any other dependency.


(Wujek Srujek) #3

Fair enough. What would happen then? Would it be taken from the local gradle caches? Looking in the ~/.gradle/caches directory, there are some cached classes generated from scripts (the closures and all) and properties there, but nowhere is the original script to be found. Would it be a lot for work to save the script text as well, and try to fall back to using it (maybe with a dedicated cli switch?) when no network is available? Binary plugins have the problem that they are … binary. In my case, I build a few scripts that I can apply like ‘mixins’, where they use some properties that are to be set from the main project script. With scripts, it is easy for users to look at the text and see what is expected to be set. With binary plugins, not so much (except when there is good documentation, but not everybody has such good docs as gradle!). wujek


(Peter Niederwieser) #4

Fair enough. What would happen then? Would it be taken from the local gradle caches?

Yes.

Would it be a lot for work to save the script text as well, and try to fall back to using it (maybe with a dedicated cli switch?) when no network is available?

You could implement script caching yourself. For example, ‘apply from: cache(“http://…”)’ where you implement the ‘cache’ method. You might have to implement this from scratch though. Maybe you could declare an Ivy repo with custom artifact pattern to resolve the script (which would then be cached automatically); you’d have to give it a try. We would also be interested in having someone contribute “real” script caching to Gradle.


(Luke Daley) #5

There is the existing issue GRADLE-1768 for this. I recommend voting for it.