The build setup plugin is currently incubating. Please be aware that the DSL and other configuration may change in later Gradle versions.
The Gradle build setup plugin prepares the current project for Gradle.
Typically it will create the relevant build.gradle, settings.gradle files.
If a pom.xml
file is found in the project directory the Maven build is
converted to a Gradle build. At the moment only the conversion from Maven 3 is supported.
The plugin is currently incubating which means it is already useful but not everything might work perfectly. The API, plugin and task names may change before the final release. Please let us know your feedback or report any issues.
This plugin provides a lifecycle task named setupBuild
.
If a Gradle build with the task name setupBuild
is triggered in a directory
without an existing build file in the project directory, the build setup plugin is auto applied.
This means that you can setup a Gradle project build without needing a stub build.gradle file declaring
the build-setup plugin.
If a pom.xml file is found in the project directory, a task of type ConvertMaven2Gradle
is added to the setupBuild
lifecycle. Furthermore a Wrapper
task is part of the
setupBuild
lifecycle that generates all files needed to run the build using the Gradle Wrapper.
Details about the Gradle Wrapper can be found in the according chapter Chapter 61, The Gradle Wrapper
The build-setup plugin adds the following tasks to the project:
Table 47.1. Build Setup plugin - tasks
Task name | Depends on | Type | Description |
buildSetup
|
maven2Gradle , generateBuildFile , generateSettingsFile , setupWrapper
|
lifecycle task (no actions) | Generates a Gradle project. |
maven2Gradle
|
- | ConvertMaven2Gradle |
Converts a Maven project to a Gradle project by obtaining the effective POM. This task is only added if
a pom.xml file can be found in the project directory.
|
generateBuildFile
|
- |
GenerateBuildFile
|
Generates an build.gradle file. This task is only added if no
pom.xml file can be found in the project directory.
|
generateSettingsFile
|
- |
GenerateSettingsFile
|
Generates a settings.gradle file. This task is only added if no
pom.xml file can be found in the project directory.
|
setupWrapper
|
- |
Wrapper
|
Generates Gradle wrapper files. |
The ConvertMaven2Gradle task works by obtaining the effective POM of the current project by executing Maven internally. Then it reads the dependencies and other information to generate build.gradle scripts. This task is inspired by the maven2gradle tool founded and maintained by recognized leaders of Gradle community; created by Baruch Sadogursky with contributions from Antony Stubbs, Matthew McCullough and others.
(*) - Note: Your project will be considered multi-module only if your reactor is also a parent of at least one of your modules. Why so? Reactor project is built last, when Parent project is built first. The reactor has to be built first, because effective-pom Mojo generates needed output only if it finds modules in first project it encounters. Making reactor also a parent achieves this.
To convert a Maven project follow the steps:
build.gradle
file is available in your your Maven project folder.gradle setupBuild
in your project directory.
You should see that the maven2Gradle
task is executed as a dependency on setupBuild.