Chapter 47. Build Setup Plugin

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 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 plugins typically need to be applied to a project before they can be used (see Section 21.1, “Applying plugins”). The Build Setup 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 setupBuild 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.

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.

47.1. Tasks

The plugin adds the following tasks to the project:

Table 47.1. Build Setup plugin - tasks

Task name Depends on Type Description
setupBuild wrapper SetupBuild Generates a Gradle project.
wrapper - Wrapper Generates Gradle wrapper files.

47.2. What to set up

The setupBuild 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 setupBuild --type java-library.

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.

If the type could not be inferred, the type "basic" will be used.

All build setup types include the setup of the Gradle Wrapper.

47.3. Build setup types

As this plugin is currently incubating, only 3 build setup types are currently supported. More types will be added in future Gradle releases.

47.3.1. "java-library"

The "java-library" build setup type is not inferable. It must be explicitly specified.

It has the following features:

  • Uses the "java" plugin
  • Uses the " mavenCentral() dependency repository
  • Uses JUnit for testing
  • Has directories in the conventional locations for source code
  • Contains a sample class and unit test, if there are no existing source or test files

47.3.2. "pom" (Maven conversion)

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 setupBuild task is invoked in. This type will be automatically inferred if such a file exists.

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:

  • Uses effective POM and effective settings (support for POM inheritance, dependency management, properties)
  • Supports both single module and multimodule projects
  • Supports custom module names (that differ from directory names)
  • Generates general metadata - id, description and version
  • Applies maven, java and war plugins (as needed)
  • Supports packaging war projects as jars if needed
  • Generates dependencies (both external and inter-module)
  • Generates download repositories (inc. local Maven repository)
  • Adjusts java compiler settings
  • Supports packaging of sources and tests
  • Supports TestNG runner
  • Generates global exclusions from Maven enforcer plugin settings

47.3.3. "basic"

The "basic" build setup 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.