Is there a true, never needed a network, local mode for Gradle?


(coleman.rik) #1

Is it possible to use Gradle without a network connection? I don’t mean an offline mode that switches to a local cache when the network is unavailable, but a true disconnected/never connected mode?

I am asking in response to this reply from JetBrains regarding the inability to create a new gradle based android project in either IntelliJ Community Edition or Android Studio;

“Offline mode it is mode provided by Gradle api to always use dependency modules from the cache http://www.gradle.org/docs/current/userguide/dependency_management.html#sub:cache_offline . So if the library is not in Gradle cache it will not be possible to create project in this mode. You can create a feature request/usability issue at http://youtrack.jetbrains.com/issues/IDEA .”


(Peter Niederwieser) #2

If you have configured IntelliJ to use a local Gradle installation, and your build doesn’t declare any remote repositories or use the network in some other way, I’d expect it to work without a network connection.


(coleman.rik) #3

Thanks for the reply. That was what I was expecting as well. Unfortunately there appear to be a couple of issues that prevent this from happening. When using IDEA IntelliJ community edition 13.1.1 or Android Studio (currently 0.5.4) ;

  1. There is no application level setting to use a local gradle installation. The only option to do so is at the project level, after it has been created (it also doesn’t stick between opening and closing the project).

  2. I have no idea what dependencies or remote repositories it is declaring when you ask either IDE to create a new android project (gradle android in IntelliJ, the ant based new android project works just fine).

According to the response I have received from JetBrains (see initial question) they appear to be claiming that the Gradle API has no support for a mode that isn’t either

  • online

  • offline using a cache of the previously online material.

As I’ve written in other forums, the currently implemented in IDEA IntelliJ and Android Studio’s gradle offline_mode isn’t;

“I don’t have a network connection at all or ever.” [as it is in Eclipse or in IDEA IntelliJ with ant android projects]

instead it’s a;

“I have a 100Mb internet connection, but I want to keep editing on my flight from Boston to L.A… Please go to the network and locally cache all the files I will need to keep working while I’m temporarily disconnected. Sync when a network is again available.”

mode.

If gradle does indeed support a completely offline/no network mode can you point me to where I should look for information in enabling this?

rik.


(Peter Niederwieser) #4

There is no option other than ‘–offline’, but I wonder if one is needed. A true offline build can’t use any online material. If the build author makes sure of that, I don’t see why Gradle (API) should have issues with executing offline. In IntelliJ, the Gradle installation can be selected during build import. 1. and 2. sound like things that could be tackled on the IDE side (if deemed beneficial). You can see what’s being generated by opening ‘build.gradle’, and can customize it to your needs.


(coleman.rik) #5

If you don’t have a network connection, or at least a fast/reliable one, then Gradle isn’t really an option. Without a true offline mode that is. A local developer using local libraries to build a local application, from msbuild to ant and beyond has always been supported.

I know my network connection isn’t exactly spectacular, Gradle processes in Android Studio take many minutes and lock up the IDE at seemingly random times. I imagine that if I had a fast machine and a fast solid internet connection I would hardly notice them at all. Sadly I don’t think I’m in the minority. Unfortunately Google is transitioning to gradle as the build system for Android development. Things being what they are, without a true offline mode, gradle becomes a tool reserved for the well connected.

Admittedly I don’t know much about gradle at all, excepting that it appears to be the thing making Android Studio painful to use. In Android Studio there are two build.gradle files.

In the

MyApplication directory: "

// Top-level build file where you can add configuration options common to all sub-projects/modules.
  buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}
  allprojects {
    repositories {
        mavenCentral()
    }
}

"

In the MyApplication/app directory: "

apply plugin: 'android'
  android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"
      defaultConfig {
        minSdkVersion 8
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}
  dependencies {
    compile 'com.android.support:appcompat-v7:19.+'
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

"

Perhaps you can see something that says to keep going out to the internet to run gradle.

It sounds like currently there is no true offline mode for gradle. If that’s false, how can I get the IDE to use it (or what information can I point the IDE devs toward)? If it’s true, can one be added?

Thanks,


(Peter Niederwieser) #6

It’s not clear to me what you mean by “true offline mode”, and I’m not aware of a reason why Gradle can’t be used completely offline. Of course it’s then your responsibility to get the necessary dependencies onto the local machine, and you can’t simply bring in a dependency just by declaring it in your build script (’‘com.android.tools.build:gradle:0.9.+’’, ‘‘com.android.support:appcompat-v7:19.+’’, etc.). It also doesn’t make sense to declare repositories such as ‘mavenCentral()’ in that case, but you can declare a repository with a ‘file:///’ URL, provided that there is such a repository on your local disk. Additionally, you can still use file dependencies such as the last dependency declared in your build script.

If you are asking for better full offline support in Android Studio (e.g. by having Android Studio generate build scripts that only make use of local resources), that’s something best discussed with the Android Studio developers. If you have any concrete suggestions on how Gradle (not Android Studio) could make it easier to work fully offline, let us know.


(coleman.rik) #7

“True Offline Mode” means if I have gradle installed locally and no network connection I can still use it. It never needs to go online [ --offline really means offline and not --use_cached_version ].

Yes, better full offline support in Android Studio and by extension IDEA IntelliJ is the end goal of this particular line of inquiry. The reason I’ve asked the question here, of the Gradle developers, is that having brought up the subject with JetBrains I was told that Gradle doesn’t support offline mode, only disconnected cached mode. If I want to use gradle completely offline I would have to bring that up with the Gradle developers.

You’ve said that currently the only switch is --offline and that’s a cached mode, not an offline mode. Then you’ve wondered why one would even be needed. I’ve tried to explain, because not everyone has a fast stable internet connection, and you’ve suggested that I take it up with the Android Studio/IntelliJ developers. So now I’ve come full circle. IDE devs say it’s a gradle issue, Gradle devs say it’s an IDE issue. It makes one long for the simple days of ant.

Before I go back to asking the IDE devs, is it true that there are no inherent issues in gradle 1.11 that would prohibit it from running in a completely disconnected mode, assuming that the build scripts are generated correctly and (as in the ant builds) all the dependencies are local?

Thanks again for your patience in this matter,

(p.s. those build scripts are the auto generated ones when you ask the IDE to create a new android project.)


(Peter Niederwieser) #8

“True Offline Mode” means if I have gradle installed locally and no network connection I can still use it.

Gradle doesn’t go online unless configured to. Hence it’s a matter of authoring a build that’s appropriate for offline use.

Before I go back to asking the IDE devs, is it true that there are no inherent issues in gradle 1.11 that would prohibit it from running in a completely disconnected mode, assuming that the build scripts are generated correctly and (as in the ant builds) all the dependencies are local?

I’m not aware of any. Concrete pointers would be appreciated.


(coleman.rik) #9

Thank you for all of your help.

Since it isn’t a gradle issue, it’s back to bring the matter up with the IDE devs.