Gradle – Create Java project structure automatically

To quick start a new Gradle Java project, type gradle init --type java-library


$ gradle init --type java-library
:wrapper
:init

BUILD SUCCESSFUL

Total time: 4.866 secs

The following files and folders will be created automatically.

P.S Tested with Gradle 2.0

1. Java Project Structure

gradle-java-init

Both src/main/java and src/test/java folders are created. The Library*.java is a sample file, just delete it.

2. Gradle Files

1. A simple gradle.build file for Java project.

gradle.build

apply plugin: 'java'

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.slf4j:slf4j-api:1.7.5'
    testCompile 'junit:junit:4.11'
}

2. A simple settings.build file, for multi project build. Ignore this file if you are not going to create a multi module project.

settings.build

rootProject.name = 'your-project-folder'

3. Some Gradle wrapper files.

References

  1. Gradle build init plugin

mkyong

Founder of Mkyong.com, passionate Java and open-source technologies. If you enjoy my tutorials, consider making a donation to these charities.

2 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Carol
7 years ago

Thanks!

Jory Ferrell
9 years ago

Where do I run this command? Can it be run inside a console of IntelliJ?