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

时间:2021-07-30 13:31:14

I am using android studio and in project structure -> dependencies tab following options i can see:

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

  1. Compile
  2. Provided
  3. APK
  4. Test Compile
  5. Debug Compile
  6. Release Compile

my question: what is the difference between compile, testCompile and provided in gradle dependency

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

2 个解决方案

#1


27  

compile is the group of dependencies you need to build your application while testCompile is a group of dependencies that you need only for testing.

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

Look for instance at this build.gradle (taken from here)

查看此build.gradle的实例(取自此处)

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.+'
}

This specifies that hibernate-core is needed to build your code but junit (a testing framework) is needed just for testing. Since it's not needed at runtime, it's not going to be included in the released package.

这指定构建代码需要hibernate-core,但仅需要junit(测试框架)进行测试。由于在运行时不需要它,因此它不会包含在已发布的包中。

#2


2  

You should read the User Guide that comes with the distribution, or read it online at http://gradle.org/documentation/ .

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

In short, "compile" is for dependencies for your "main" code, "testCompile" for your test classes, and "provided" is used for dependencies that are used at compile time, but not stored in your WAR file (because they're expected to be available in your web container).

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

The following posting might have relevant information: Compile, Provided, APK - Android dependency scope .

以下帖子可能包含相关信息:编译,提供,APK - Android依赖范围。

#1


27  

compile is the group of dependencies you need to build your application while testCompile is a group of dependencies that you need only for testing.

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

Look for instance at this build.gradle (taken from here)

查看此build.gradle的实例(取自此处)

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.+'
}

This specifies that hibernate-core is needed to build your code but junit (a testing framework) is needed just for testing. Since it's not needed at runtime, it's not going to be included in the released package.

这指定构建代码需要hibernate-core,但仅需要junit(测试框架)进行测试。由于在运行时不需要它,因此它不会包含在已发布的包中。

#2


2  

You should read the User Guide that comes with the distribution, or read it online at http://gradle.org/documentation/ .

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

In short, "compile" is for dependencies for your "main" code, "testCompile" for your test classes, and "provided" is used for dependencies that are used at compile time, but not stored in your WAR file (because they're expected to be available in your web container).

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

The following posting might have relevant information: Compile, Provided, APK - Android dependency scope .

以下帖子可能包含相关信息:编译,提供,APK - Android依赖范围。