Automatically generating java project structure in Gradle

Gradle generated java project structure using Gradle Build init plugin

To find the list of gradle supported project structure you can fire the below command in command prompt

gradle init

The “java-application” build init type is not inferable. It must be explicitly specified.

It has the following features:

  • Uses the “application” plugin to produce a command-line application implemented using Java
  • Uses the “jcenter” 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

Alternative test framework can be specified by supplying a --test-framework argument value. To use a different test framework, execute one of the following commands:

  • gradle init --type java-application --test-framework spock: Uses Spock for testing instead of JUnit
  • gradle init --type java-application --test-framework testng: Uses TestNG for testing instead of JUnit

You can specify the init type directly by using the below command

gradle init --type java-application

Leave a Comment