Main Tutorials

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

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
2 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Carol
5 years ago

Thanks!

Jory Ferrell
7 years ago

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