s going on here? This build script says a few things about the project. Firstly, it states that Hibernate core 3.6.7.Final is required to compile the project's production source. By implication, Hibernate core and its dependencies are also required at runtime. The build script also states that any junit >= 4.0 is required to compile the project's tests. It also tells Gradle to look in the Maven central repository for any dependencies that are required. The following sections go into the details.
7.3. Dependency configurations
In Gradle dependencies are grouped into configurations. A configuration is simply a named set of dependencies. We will refer to them as dependency configurations.
//gradle中依赖以组的形式配置,一个配置就是一个简单的依赖的名字的集合。我们称它依赖配置
You can use them to declare the external dependencies of your project. As we will see later, they are also used to declare the publications of your project.
//我们可以使用它们声明外部依赖,后面我们也会看到,它们也可以用来声明项目的发布
The Java plugin defines a number of standard configurations. These configurations represent the classpaths that the Java plugin uses. Some are listed below, and you
can find more details in Table 45.5, “Java plugin - dependency configurations”.
//java插件定义了一些标准配置,部分如下
compile
-
The dependencies required to compile the production source of the project.
//用于编译项目源代码的依赖
-
runtime
-
The dependencies required by the production classes at runtime. By default, also includes the compile time dependencies.
//
-
testCompile
-
The dependencies required to compile the test source of the project. By default, also includes the compiled production classes and the compile time dependencies.
-
testRuntime
-
The dependencies required to run the tests. By default, also includes the compile, runtime and test compile dependencies.
Various plugins add further standard configurations. You can also define your own custom configurations to use in your build. Please see Section 23.3, “Dependency configurations” for the details of defining and customizing dependency configurations.
7.4. External dependencies
There are various types of dependencies that you can declare. One such type is an external dependency. This is a dependency on some files built outside the current build, and stored in a repository of some kind, such as Maven central, or a corporate Maven or Ivy repository, or a directory in the local file system.
To define an external dependency, you add it to a dependency configuration:
//为了定义外部依赖,你需要把它添加到依赖配置中
Example 7.2. Definition of an external dependency
build.gradle
dependencies {
compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final' }
An external dependency is identified using group
, name
and version
attributes. Depending on which kind of repository you are using, group
and version
may be optional.
//外部依赖使用group name和version属性来生命,group和version是可选的
The shortcut form for declaring external dependencies looks like “group
:name
:version
”.
//生命外部依赖的简洁写法为group
:name
:version
Example 7.3. Shortcut definition of an external dependency
build.gradle
dependencies {
compile 'org.hibernate:hibernate-core:3.6.7.Final'
}
To find out more about defining and working with dependencies, have a look at Section 23.4, “How to declare your dependencies”.