簡體   English   中英

將插件添加到本地 jar 中的 gradle buildscript

[英]add plugin to gradle buildscript from a local jar

我想將google-services Gradle 插件從本地 jar 應用到 Java 項目,這樣我的構建就不需要連接到 jcenter 來下載插件。

我已經下載了google-services-3.0.0.jar ,但我不知道如何告訴 gradle 從文件加載插件。

這是我的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
    }
}

我能夠通過在我的 lib 文件夾中添加 jar 並從項目 gradle 依賴項中調用它來從 jar 添加插件,如下所示:

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
    }
}

您應該使用*.jar庫創建一個目錄,並在repositories {}塊中添加flatDir {}以初始化將 jar-libs 作為存儲庫的目錄:

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
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM