How to Publish a Gradle Project on Maven Central
You can publish a Java or Kotlin library built with Gradle on Maven Central like this.
First setup your Gradle build to produce a valid bundle for Maven Central.
-
Include the Maven Publish Plugin in your build.
-
Setup building of Javadoc and Source archives using Dokka.
-
Set the required POM metadata in Gradle like this.
See here for a complete working example.
Now you can run gradle publish to create the Maven bundle in the mavenPublish directory (which you probably want to include in .gitignore).
Secure your Gradle builds with AppArmor
If you have a Linux system with AppArmor, you can use it to secure your Gradle builds.
Here is how I installed it on Ubuntu Linux:
-
Make sure you have a Java Development Kit installed.
-
Set the
JAVA_HOMEenvironment variable to point to your JDK by creating a file/etc/profile.d/java.shwith this content:#!/bin/sh export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64 -
Make a manual installation of Gradle in
/opt/gradle. -
Make it available in PATH:
$ cd /usr/bin $ sudo ln -s ../../opt/gradle/gradle-8.14.3/bin/gradle .