简体   繁体   中英

add plugin to gradle buildscript from a local jar

I'd like to apply the google-services Gradle plugin to a Java project from a local jar, such that my build does not need to connect to jcenter to download the plugin.

I have downloaded the google-services-3.0.0.jar , but I don't know how to tell gradle to load the plugin from the file.

This is my build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath 'com.google.gms:google-services:3.0.0' <---i have the jar

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    }
}

I was able to add the plugin from the jar by adding the jar in my lib folder and call it from the project gradle dependencies like so :

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath fileTree(include: ['*.jar'], dir: 'app/libs')
        classpath files('app/libs/google-services-3.0.0.jar')

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

You should create a directory with your *.jar libs and add flatDir {} in repositories {} block to initialize the directory that keeps jar-libs as a repository:

buildscript {
    repositories {
        jcenter()
        flatDir { dirs 'jarlibs' } // *.jar libs are keep in 'app/jarlibs' dir
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath 'com.google.gms:google-services:3.0.0' // now it works
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM