Sometimes you come across a Java project that is managed with Maven (pom.xml) or Gradle (build.gradle) and you need to be able to compile the full project into a jar.
As it turns out, that's pretty easy. Just follow along.
First, you need the JDK which allows you to compile Java source files into Java class files, which are ultimately packed into a jar. If you don't already have it, just get the latest version (JDK 15) here: https://jdk.java.net/15/.
These instructions will be for Windows 10, but other Operating Systems will be similar:
You should see something like:
openjdk version "15.0.1" 2020-10-20
OpenJDK Runtime Environment (build 15.0.1+9-18)
OpenJDK 64-Bit Server VM (build 15.0.1+9-18, mixed mode, sharing)
You have survived installing the JDK. Let's move on to Maven and Gradle.
These steps are going to be surprisingly similar to installing the JDK, so I'll hold out on the full instructions. You can use the previous set of steps, with different values that I will enumerate. Check it out:
Let's start with Maven:
You should see something like:
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: C:\Users\YOUR_USERNAME\.tools\apache-maven-3.6.3
Java version: 15.0.1, vendor: Oracle Corporation, runtime: C:\Users\YOUR_USERNAME>\.tools\jdk-15.0.1
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
That's it for Maven! Let's do Gradle:
You should see something like:
Welcome to Gradle 6.8!
Here are the highlights of this release:
- Faster Kotlin DSL script compilation
- Vendor selection for Java toolchains
- Convenient execution of tasks in composite builds
- Consistent dependency resolution
For more details see https://docs.gradle.org/6.8/release-notes.html
------------------------------------------------------------
Gradle 6.8
------------------------------------------------------------
Build time: 2021-01-08 16:38:46 UTC
Revision: b7e82460c5373e194fb478a998c4fcfe7da53a7e
Kotlin: 1.4.20\nGroovy: 2.5.12
Ant: Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM: 15.0.1 (Oracle Corporation 15.0.1+9-18)
OS: Windows 10 10.0 amd64\
And we're done with Gradle. We're on the home stretch. Last on the list is getting the source code from GitHub with Git.
If you don't already have Git installed, you will need to follow this section. Otherwise skip it.
You should see something like:
git version 2.30.0.windows.1
That's it for Git. Nice one.
This is the finish line. You're almost there. Find the project that you want to compile on GitHub.
For example's sake, we'll use https://github.com/PyvesB/advanced-achievements. (Please note: if the program you are planning to compile is a paid resource but has its source released, this generally means you are welcome to compile it yourself. Do also note, however, that this implies you do not and will not require support, as none shall be given to you. This is a good way to see if you end up liking a program (or plugin, in the Minecraft community). That said, if you do indeed end up liking the program you should pay for it if you have the means.)
Earlier, you figured out whether you should use Maven (a pom.xml file exists) or Gradle (a build.gradle file exists).
Your next and last step is:
For Maven:
For Gradle:
Nice. You should have your jar now! Enjoy.