首页 文章

compile,testCompile和gradle依赖项之间有什么区别

提问于
浏览
28

我正在使用android studio和项目结构 - >依赖项选项卡以下选项我可以看到:

  • 编译

  • 已提供

  • APK

  • 测试编译

  • Debug Compile

  • 发布编译

我的问题:compile,testCompile和gradle依赖项之间的区别是什么

2 回答

  • 2

    compile 是构建应用程序所需的依赖项组,而 testCompile 是一组只需要进行测试的依赖项 .

    build.gradle 寻找例子(取自here

    apply plugin: 'java'
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'
        testCompile group: 'junit', name: 'junit', version: '4.+'
    }
    

    这指定构建代码需要 hibernate-core ,但仅需要 junit (测试框架)进行测试 . 因为's not needed at runtime, it'不会被包含在已发布的包中 .

  • 29

    您应该阅读发行版附带的“用户指南”,或者在http://gradle.org/documentation/在线阅读 .

    简而言之,“compile”是针对您的“主”代码的依赖关系,“testCompile”针对您的测试类,“provided”用于编译时使用但不存储在WAR文件中的依赖关系(因为它们'预计将在您的Web容器中提供) .

    以下帖子可能包含相关信息:Compile, Provided, APK - Android dependency scope .

相关问题