gradle Initializing a New Java Library


Example

Prerequisite: Installing Gradle

Once you have Gradle installed, you can setup a new or existing project by running

cd $PROJECT_DIR
gradle init --type=java-library

Note that there are other project types like Scala you can get started with, but we'll use Java for this example.

You will end up with:

.
├── build.gradle
├── gradle
│   └── wrapper
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── src
    ├── main
    │   └── java
    │       └── Library.java
    └── test
        └── java
            └── LibraryTest.java

You can now run gradle tasks and see that you can build a jar, run tests, produce javadocs and much more even though your build.gradle file is:

apply plugin: 'java'

repositories {
    jcenter()
}

dependencies {
    compile 'org.slf4j:slf4j-api:1.7.21'
    testCompile 'junit:junit:4.12'
}