Creating project structure using Gradle

Gradle is a convention based build tool to build even large scale projects. Gradle provides a detailed documentation about the tool. This article will be crisp about setting a constant gradle version as the first step.

Requirements

  • JVM : version 8+
  • Gradle : version 3+

Plugin 'wrapper'

Plugin 'wrapper' can be used to set a version of gradle required for a project.

hello-world> gradle wrapper --gradle-version=5.0

Execution of the above command sets the gradle version to be 5.0 for the empty project hello-world`. Version of gradle installed in the machine can be different from the version required for the project, in this case '5.0'.

This is useful to standardize the build environment to be identical across different machines. This mechanism is also useful to upgrade the version gradle easily by using the same command.

bash
hello-world> ./gradlew --version

Notice the use of gradle wrapper in ./gradlew. Use './' for linux and '.\' for windows

Above command will return '5.0' as the version of gradle.
bash
hello-world> gradle --version

In the above command, the version of gradle could be different from '5.0'. In this case, gradle used is the system-wide installed version of gradle and not the project specific version.

Plugin 'init'

Gradle has a collection of plugins for various requirements. Plugin 'init' is used for initializing projects. Documentation of plugin is available in https://docs.gradle.org/current/userguide/build_init_plugin.html .

Generate seed project

Using the below command, a maven style project structure is created along with a sample java program.

bash
hello-world> ./gradlew init --type java-library

Using the below command, a maven style project structure is created along with a sample scala program.

bash
hello-world> ./gradlew init --type scala-library

23