Publishing your mod to a Maven repository
Publishing your mod to a Maven repository is a great way to share your mod with other developers. Maven is a popular platform for sharing Java libraries and projects, and it is used by many Java developers to share their projects with the community. Gradle has built-in support for publishing your mod to a Maven repository, and this guide will show you how you can publish your mod to a Maven repository using Tableau.
Prerequisites
Before you can publish your mod to a Maven repository, you need to have a Maven repository to publish to. You can use a public Maven repository like Maven Central or JitPack, or you can set up your own Maven repository using a tool like Nexus Repository Manager. Please collect the following information:
- The URL of the Maven repository
- Your username and password for the Maven repository
Keep your username and password safe and do not share them with anyone!
Configuring Tableau
To publish your mod to a Maven repository, you need to configure Tableau's Maven module.
To do this, edit the build.gradle
file of your project and add the following configuration to the tableau
block:
- Groovy
- Kotlin
tableau {
maven {
publishTo("https://maven.example.com/repository/maven-releases/")
}
}
tableau {
maven {
publishTo("https://maven.example.com/repository/maven-releases/")
}
}
This is enough configuration of the project to get started with publishing your mod to a Maven repository.
Configuring the publishing
It is highly recommended that you properly configure your publishing metadata and repository. You will need address two aspects: Configuring the correct publishing location, and the POM file itself.
Publishing location
In the Configuring Tableau section, you have already configured the publishing location.
However, as of writing there are three other options you could use, instead of publishTo
:
- Publishing locally
- Publishing to GitHub Packages.
- Publishing to the LDTTeam repository.
Publishing locally
To publish locally, you can use the publishLocally
method:
- Groovy
- Kotlin
tableau {
maven {
publishLocally()
}
}
tableau {
maven {
publishLocally()
}
}
This will ensure that the mod is published to the repo
directory in the project root.
Publishing to GitHub Packages
To publish to GitHub Packages, you can use the publishToGithub
method:
- Groovy
- Kotlin
tableau {
maven {
publishToGithub()
}
}
tableau {
maven {
publishToGithub()
}
}
When you this method you need to supply the GitHub username and token as environment variables:
GITHUB_USERNAME
-> Your GitHub username.GITHUB_TOKEN
-> A GitHub token with thewrite:packages
scope.
Publishing to the LDTTeam repository
To publish to the LDTTeam repository, you can use the publishToLDTTeam
method:
- Groovy
- Kotlin
tableau {
maven {
publishToLDTTeam()
}
}
tableau {
maven {
publishToLDTTeam()
}
}
When you this method you need to supply the LDTTeam username and token as environment variables:
LDTTeamJfrogUsername
-> Your LDTTeam username.LDTTeamJfrogPassword
-> Your LDTTeam password, or token.
POM file
Configuring a POM file correctly ensures that your mod is published correctly, and that other modders have a place to find information about your mod.
The pom
in the maven
block extends a Gradle MavenPom
object, which is a representation of a Maven POM file.
You can find more information about the MavenPom
object in the Gradle documentation.
However, the pom in Tableau also comes with a set of special methods, which are not available in the Gradle documentation, but are Tableau specific. These methods help you configure the POM file for your mod.
Configuring a license
The maven POM indicates what license your project has to consumers.
You can configure the license using the licenses
method:
- Groovy
- Kotlin
tableau {
maven {
pom {
licenses {
license {
name = "Project custom license"
url = "https://somelice.url/path/to/license"
}
}
}
}
}
tableau {
maven {
pom {
licenses {
license {
name.set("Project custom license")
url.set("https://somelice.url/path/to/license")
}
}
}
}
}
Alternatively, you can use the license shortcut methods Tableau provides, to configure common licenses for your project.
Configuring your project for a GNU GPL license
To configure your project for a GNU GPL license, you can use the usingGnu3License
method:
- Groovy
- Kotlin
tableau {
maven {
pom {
usingGnu3License()
}
}
}
tableau {
maven {
pom {
usingGnu3License()
}
}
}
Configuring your project for a MIT license
To configure your project for a MIT license, you can use the usingMitLicense
method:
- Groovy
- Kotlin
tableau {
maven {
pom {
usingMitLicense()
}
}
}
tableau {
maven {
pom {
usingMitLicense()
}
}
}
Configuring your distribution management
The distribution management section of the POM file indicates where the project is distributed and can be downloaded from.
You can configure the distribution management using the distributionManagement
method:
- Groovy
- Kotlin
tableau {
maven {
pom {
distributionManagement {
//Replace with maven url
downloadUrl = "https://maven.example.com/repository/maven-releases/"
}
}
}
}
tableau {
maven {
pom {
distributionManagement {
//Replace with maven url
downloadUrl.set("https://maven.example.com/repository/maven-releases/")
}
}
}
}
If you followed the guides under Publishing location, then the distribution management is already configured for you.
Configuring using Git
The POM file can also be configured using information from your git repository.
You can configure the POM file to use information from your git repository using the usingGit
method:
- Groovy
- Kotlin
tableau {
maven {
pom {
usingGit()
}
}
}
tableau {
maven {
pom {
usingGit()
}
}
}
This will configure the following information:
- Source Control Management
- Developers
- Contributors (Which are the top 5 contributors to the project)
- Issue Management (Automatically set to GitHub Issues)
- Inception Year
- Ci Management (Automatically set to GitHub Actions)
- Organization (Automatically set to the GitHub organization)