Introduction
To build your modifications, forge uses Gradle. Gradle is a tool which automates the compilation, deployment and dependencies of your project. Forge ships with it's own version of Gradle, so you don't have to install it yourself.
Getting Minecraft Forge
You can download Minecraft Forge from the official website: https://files.minecraftforge.net/. Different versions of Forge might have different features, and might work for different versions of Minecraft. All modifications must use a Forge copy matching their Minecraft version. Using a Forge copy meant to be used on a different version of Minecraft *will* crash your game, and might not even compile.
In most cases it is sufficient you download the *recommended* version of Forge. The latest version might contain bugs and in general should only be used when you are testing them out, or when you need specific features attached to those specific versions.
[*]go to the Minecraft Forge download website
[*]Download the source (src) version of the copy you want. You should end up with a single zip archive.
[*]Extract the archive.
Setting up the workspace
You first need to open a console in your Forge directory. On Windows this is done by shift-clicking on the directory and clicking "Open Command Window Here".
As mentioned before, Forge uses Gradle, which makes managing your project a whole lot easier. Forge ships with a Graddle wrapper. On Linux this is gradlew and on Windows this is gradlew.bat. If you have Grandle installed you can also simply use gradle.
To to setup your workspace and decompile Minecraft execute the following command:
gradle setupDecompWorkspace
If you do not have Gradle installed, you'll have to replace gradle with ./gradlew or gradlew.bat for Unix/Linux or Windows respectively.
Directory structure and files
You should now have the following directories:
build - Your mod can be found here once it's been built. It'll end up inside /libs.
eclipse - this is where the Eclipse IDE project will be located
gradle - the Gradle wrapper that ships with Forge
src - Your source files go here. Put your code inside /main/java, and your resources inside /main/resources
.gradle - Gralde's cache directory
Building your modification
Once you have written your modification you can build it using the following command:
gradle build
Same goes here: If you do not have Gradle installed, you'll have to replace gradle with ./gradlew or gradlew.bat for Unix/Linux or Windows respectively.
Where to go next
Here are some more helpful tutorials:
Setting up your IDE for use with Forge