This GitHub Action repurposes a GitHub repository to act as a Maven repository, allowing you to store and serve Java/Android artifacts directly from GitHub. Build Java project with Gradle, extract metadata, and publish artifacts to a your GitHub repository with no additional registrations and efforts.
This GitHub Action allows you to:
- Checkout your project repository.
- Set up the specified JDK version.
- Extract the latest Git commit message and hash.
- Build the project or specific Gradle modules.
- Publish artifacts to the local Maven repository.
- Copy artifacts and POM files to a specified GitHub repository.
- Generate checksums (
.sha1and.md5) for JAR, AAR, and POM files. - Commit and push artifacts to a separate repository.
You can use this action in your workflows. Here's an example:
name: Build and Publish
on:
workflow_dispatch:
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: Use Maven publish action
uses: RiV-chain/github-publish-maven-action@main
with:
gh_pat: ${{ secrets.PAT }}
artifact_repo: 'vikulin/artifact'
gradle_file_path: './gradlew'
gradle_modules: ':app,:mylib'
java_version: '21'
distribution: 'adopt'
Groovy:
publishing {
repositories {
mavenLocal()
}
publications {
gpr(MavenPublication) {
from(components.java)
}
}
}
Kotlin (Android library):
android {
// ...
// This is important for publishing Android libraries
publishing {
singleVariant("release") {
withSourcesJar()
withJavadocJar()
}
}
}
publishing {
publications {
create<MavenPublication>("gpr") {
groupId = "org.rivchain"
artifactId = "libsodium-android"
version = "1.0.0"
// Use the release component that we defined above
afterEvaluate {
from(components["release"])
}
}
}
repositories {
mavenLocal()
}
}
Register secret.PAT with permissions for your Maven repository and replace the path in the artifact_repo parameter.
Your Maven repository URL will be:
https://github.com/<username>/<repo>/raw/<branch>
Groovy:
repositories {
maven {
url "https://github.com/vikulin/artifact/raw/main"
}
}
Kotlin:
repositories {
maven {
url = uri("https://github.com/vikulin/artifact/raw/main")
}
}
| Input | Description | Required | Default |
|---|---|---|---|
gh_pat |
Personal Access Token for GitHub Maven artifact repository | Yes | - |
artifact_repo |
GitHub repository to publish artifacts | Yes | - |
gradle_file_path |
Path to the Gradle file | Yes | ./gradlew |
java_version |
Java version to set up | Yes | - |
distribution |
Java distribution to set up | Yes | - |
gradle_modules |
Comma-separated list of Gradle modules (e.g., :app,:mylib). Empty means root module. |
No | "" |
- Checkout Repository – Clones your source repository.
- Set up JDK – Installs the specified Java distribution and version.
- Extract Git Metadata – Retrieves the latest commit message and hash.
- Install Utilities – Installs
xmlstarletandtreefor processing POM files. - Build with Gradle – Builds the root project or specified modules and publishes them to the local Maven repository.
- Checkout Artifact Repository – Clones the repository where artifacts will be stored.
- Process Artifacts – Copies Maven artifacts (
.jar,.aar,.pom) from local Maven cache to the artifact repository, generates checksums, and organizes them in Maven structure. - Commit & Push – Commits the processed artifacts to the artifact repository and pushes the changes.
- Permissions: Ensure your repository permissions allow this action to check out repositories and push changes.
- Secrets: Ensure the
secrets.PATsecret is set in your Maven GitHub repository secrets. - Java
distributionparameter accepts values from GitHub Setup-Java Supported Distributions. - If no modules are specified, the action builds the root Gradle project.
- Checksums are automatically generated for JAR, AAR, and POM files.
This project is licensed under the GPL-3.0 license. See the LICENSE file for details.