Skip to content

Instantly share code, notes, and snippets.

@tkshnwesper
Last active January 5, 2018 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkshnwesper/7a04735f29584151ebc00fd0a48868ed to your computer and use it in GitHub Desktop.
Save tkshnwesper/7a04735f29584151ebc00fd0a48868ed to your computer and use it in GitHub Desktop.
How to setup Gradle on an Existing Intellij Project (Pathashala)

This tutorial assumes that you have

  1. /src/main as your sources folder
  2. /src/test as your test folder
  3. /src/resources as your resources folder

(Even you if don't, it's alright, read on. You'll just have to modify the gradle file a bit)

Install Gradle

You need to install the latest version locally.

Note: If you use the one that comes bundled with Intellij or gradlew you might face problems while compiling with JDK 9 since they don't provide the latest version of gradle.

brew install gradle

Adding build.gradle

Now just download this file (or the contents of this file) here.

Call it build.gradle and place it into the root folder of your project.

IMPORTANT:

  1. Now close the project (I'm not kidding, lol).
  2. And then open it up again.
  3. You should be able to see a small notification on the bottom right. Click Import Gradle (or something on those lines).
  4. That should open up a import module window.

Intellij's gradle config

This is what the import module should look like: gradle conf Mimic the fields that are in the picture. And press OK.

Done!

If all goes well, you should have gradle working in your project.

Don't forget to add .gradle to your .gitignore!

Change the main/test/resources folders

It's nothing difficult really. Just modify this snippet in your build.gradle:

sourceSets {
    main {
        java {
            srcDirs = ['src/main']
        }
        resources {
            srcDirs = ['src/resources']
        }
    }

    test {
        java {
            srcDirs = ['src/test']
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment