Skip to content

Commit

Permalink
🚀 Add maven publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Ally Mitchell committed Jul 9, 2024
1 parent a98c2be commit 1f5da4b
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
48 changes: 48 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Publish with Gradle

on:
push:
branches: [ '1.20.1' ]

env:
CACHE_REV: "1"

jobs:
publish:
runs-on: ubuntu-22.04
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
${{ github.workspace}}/build/
${{ github.workspace}}/.gradle/
key: "${{ runner.os }}-build-${{ env.CACHE_REV }}-${{ hashFiles('**/*.gradle*') }}"
restore-keys: |
${{ runner.os }}-build-${{ env.CACHE_REV }}-
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
- name: Setup workspace
run: |
echo "GIT_COMMIT=${GITHUB_SHA}" >> $GITHUB_ENV
echo "GIT_BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV
- name: Publish Snapshot
if: ${{ github.ref_name == 'develop' }}
run: |
chmod +x ./gradlew && ./gradlew "-PpistonVersion=${{ steps.calver.outputs.release }}-SNAPSHOT" "-Pmaven.auth.username=${MAVEN_USERNAME}" "-Pmaven.auth.password=${MAVEN_PASSWORD}" publish --stacktrace
- name: Publish Release
if: ${{ github.ref_name == 'production' }}
run: |
chmod +x ./gradlew && ./gradlew "-Pmaven.auth.username=${{ secrets.MAVEN_USERNAME }}" "-Pmaven.auth.password=${{ secrets.MAVEN_PASSWORD }}" publish --stacktrace
27 changes: 27 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ plugins {
id 'net.neoforged.gradle' version '[6.0.18,6.2)'
id 'org.spongepowered.mixin' version '0.7.+'
id 'org.parchmentmc.librarian.forgegradle' version '1.+'
id 'maven-publish'
}

group = 'cn.leomc'
Expand Down Expand Up @@ -173,4 +174,30 @@ jar.finalizedBy('reobfJar')

tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
}

publishing {
publications {
register("maven", MavenPublication) {
from components.java
}
}

repositories {
maven {
url = uri("${getVariable("maven.repo.url")}")
credentials {
username = getVariable("maven.auth.username")
password = getVariable("maven.auth.password")
}
}
}
}

String getVariable(String variable) {
if(project.ext.get(variable) != null) {
return project.ext.get(variable)
} else {
return property(variable)
}
}
6 changes: 5 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ org.gradle.daemon=false

mc_version=1.20.1

forge_version=47.1.79
forge_version=47.1.79

maven.repo.url=https://repo.modrealms.net/repository/maven-releases
maven.auth.username=
maven.auth.password=

0 comments on commit 1f5da4b

Please sign in to comment.