构建初始化插件目前是一个试验性插件。注意,在以后的 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 构建初始化插件可以用于引导创建一个新的 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插件需要在 应用 在项目之后才能使用(请参阅 第 21.1节, 《应用插件》)。构建初始化插件是一个自动应用的插件,这意味着你不需要显式地应用该插件。 要使用这个插件,只需要在你想要创建Gradle构建的地方执行 init
任务。 在这里,你不需要创建一个“存根” 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.
该插件向项目中添加以下任务:
The plugin adds the following tasks to the project:
init
支持不同的构建设置 类型。类型通过提供 --type
参数值来指定。例如,要创建Java库项目,只需执行: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文件。它仅用于当调用 init
任务的目录有一个有效的“pom.xml
”文件的时候。如果存在一个这样的文件,那么将会自动推断类型。
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.