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 the Author

author image
mkyong
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

avatar
2 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
CarolJory Ferrell Recent comment authors
newest oldest most voted
Jory Ferrell
Guest
Jory Ferrell

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

Carol
Guest
Carol

Thanks!