Build Init 插件目前仍然是孵化状态。请务必注意,在以后的 Gradle 版本中,相关的 DSL 和其他配置可能会有所改变。
The Build Init plugin is currently incubating. Please be aware that the DSL and other configuration may change in later Gradle versions.
Gradle Build Init 插件可以用于引导创建一个新的 Gradle 构建的过程。它支持创建不同类型的全新项目,以及将现有的构建 (如 Apache Maven 构建) 转换成 Gradle 构建。
The Gradle Build Init plugin can be used to bootstrap the process of creating a new Gradle build. It supports creating brand new projects of different types as well as converting existing builds (e.g. An Apache Maven build) to be Gradle builds.
Gradle 插件通常需要被应用于 project 中才可以使用(见第 21.1节,"应用插件")。 Build Init 插件是一个自动应用的插件,这意味着您不需要显式地应用它。如果要使用该插件,只需要在你想要的地方,执行名为init
的任务,就可以创建 Gradle 构建。那里不需要创建一个“存根” build.gradle
文件以应用该插件。
Gradle plugins typically need to be applied to a project before they can be used (see Section 21.1, “Applying plugins”). The Build Init plugin is an automatically applied plugin, which means you do not need to apply it explicitly. To use the plugin, simply execute the task named init
where you would like to create the Gradle build. There is no need to create a “stub” build.gradle
file in order to apply the plugin.
它还利用了 Wrapper 插件的 wrapper
任务(见第 48章,Wrapper 插件),这意味着 Gradle Wrapper 也将被安装到该项目。
It also leverages the wrapper
task from the Wrapper plugin (see Chapter 48, Wrapper Plugin), which means that the Gradle Wrapper will also be installed into the project.
该插件向project 中添加了以下任务:
The plugin adds the following tasks to the project:
init
支持不同的构建安装程序类型。类型通过提供一个 --type
参数值指定。例如,要创建一个 Java library 项目,只需执行: gradle init --type java-library
。
The init
supports different build setup types. The type is specified by supplying a --type
argument value. For example, to create a Java library project simply execute: gradle init --type java-library
.
如果没有提供 --type
参数,Gradle 将尝试从当前环境来推断类型。例如,如果它发现pom.xml
,它将推断一个“pom
”的类型值,以转换为 Gradle 构建。
If a --type
parameter is not supplied, Gradle will attempt to infer the type from the environment. For example, it will infer a type value of "pom
" if it finds a pom.xml
to convert to a Gradle build.
如果无法推断类型,将使用“basic
”类型。
If the type could not be inferred, the type "basic
" will be used.
所有构建安装类型都包括 Gradle Wrapper 的安装。
All build setup types include the setup of the Gradle Wrapper.
“pom
”类型可以被用于把 Apache Maven 构建转换为 Gradle 构建。这是通过将 POM 转换为一个或多个 Gradle 文件。它仅用于当有一个有效的“pom.xml
”文件在 init
任务被调用的目录的时候。如果存在这样的文件,将会自动推断此类型。
The "pom
" type can be used to convert an Apache Maven build to a Gradle build. This works by converting the POM to one or more Gradle files. It is only able to be used if there is a valid "pom.xml
" file in the directory that the init
task is invoked in. This type will be automatically inferred if such a file exists.
Maven 转换实现最初由 Gradle 社区成员开发的maven2gradle tool启发。
The Maven conversion implementation was inspired by the maven2gradle tool that was originally developed by Gradle community members.
该转换过程具有以下特点:
The conversion process has the following features:
“Java-library
”构建初始化类型不是可推断的。它必须显式指定。
The "java-library
" build init type is not inferable. It must be explicitly specified.
它具有以下特点:
It has the following features:
java
”插件 java
" pluginmavenCentral()
”依赖仓库 mavenCentral()
dependency repository “scala-library
”构建初始化类型不是可推断的。它必须显式指定。
The "scala-library
" build init type is not inferable. It must be explicitly specified.
它具有以下特点:
It has the following features:
scala
”插件 scala
" pluginmavenCentral()
”依赖仓库 mavenCentral()
dependency repository “groovy-library
”构建初始化类型不是可推断的。它必须显式指定。
The "groovy-library
" build init type is not inferable. It must be explicitly specified.
它具有以下特点:
It has the following features:
groovy
”插件 groovy
" pluginmavenCentral()
”依赖仓库 mavenCentral()
dependency repository “basic
”构建初始化类型用于创建一个新的 Gradle 项目。它将创建一个示例build.gradle
文件,并包含注释和链接以帮助你开始。
The "basic
" build init type is useful for creating a fresh new Gradle project. It creates a sample build.gradle
file, with comments and links to help get started.
如果没有显示地指定一个类型,或者无法推断出类型时,会使用该类型。
This type is used when no type was explicitly specified, and no type could be inferred.