How to build and run a Discord bot using Gradle shadowJar command

I’m working with a Discord bot project written in Java that uses Gradle as the build tool. The bot creator told me to run ./gradlew shadowJar to get it working, but I’m not sure what this command does or how to use it properly.

I’ve been trying different approaches to compile and run the bot but keep running into issues. Here’s what I’ve attempted:

javac MyBot.java

This gave me an error about missing logback packages.

jar cvfm MyBot.jar MANIFEST.MF core utils commands audio

This created a jar file but it doesn’t seem to work.

java -jar MyBot.jar

This throws an error saying there’s no main manifest attribute.

What exactly does the shadowJar gradle task do and how should I properly build and execute this Discord bot project? I’m new to Gradle and could use some guidance on the correct workflow.

shadowJar is super handy! it packages your bot with all its dependencies, so you end up with one fat jar file in build/libs. just do java -jar your-bot-all.jar to run it after. gl with your bot!

I had the same confusion when I started with Gradle. Your manual jar creation failed because Discord bots need external libraries like JDA and logging frameworks. When you compile with just javac or create a basic jar, these dependencies aren’t included - that’s why you get runtime errors. The shadowJar task does all the heavy lifting by grabbing your project dependencies from build.gradle and merging them into one executable jar. After running ./gradlew shadowJar, check the build/libs/ folder for your bot jar. Make sure your build.gradle specifies the main class in the shadowJar configuration, or you’ll still get that manifest error when trying to run it.

The shadowJar plugin creates a “fat JAR” that bundles your app code and all dependencies into one executable file. When you run ./gradlew shadowJar, Gradle compiles your code and packages all necessary libraries, such as JDA and logback, into the output JAR. Look for a file with “-all” in the name inside the build/libs/ directory; that’s your fully packaged bot ready to run. Manual compilation has issues because of missing libraries, which shadowJar resolves automatically.