从本地jar将插件添加到gradle构建脚本

2022-09-03 05:45:50

我想从本地jar将Gradle插件应用于Java项目,这样我的构建就不需要连接到jcenter来下载插件。google-services

我已经下载了,但我不知道如何告诉gradle从文件中加载插件。google-services-3.0.0.jar

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

答案 1

我能够通过将jar添加到我的lib文件夹中来从jar中添加插件,并从项目gradle依赖项中调用它,如下所示:

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

答案 2

您应该使用您的libs创建一个目录,并添加块以初始化将jar-libs保留为存储库的目录:*.jarflatDir {}repositories {}

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

推荐