【问题标题】:add plugin to gradle buildscript from a local jar从本地 jar 将插件添加到 gradle buildscript
【发布时间】:2016-11-26 05:09:32
【问题描述】:

我想将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
    }
}

【问题讨论】:

    标签: java android gradle


    【解决方案1】:

    我可以通过在我的 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
        }
    }
    

    【讨论】:

    • 我已经添加了相同的行,但我的 Apply 插件仍然没有解决,请您提出一些建议
    • 您不仅需要添加该行,而且 jar 应正确放置在 app/libs 或您认为合适的任何目录中
    【解决方案2】:

    您应该使用您的 *.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
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-01
      • 1970-01-01
      • 2012-09-06
      • 1970-01-01
      • 2022-08-22
      • 2021-03-04
      • 1970-01-01
      • 2016-06-26
      相关资源
      最近更新 更多