Skip to content

Commit

Permalink
Maven Publishing 1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeryn99 committed Dec 17, 2023
1 parent e2b8b70 commit cdc9718
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 7 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Publish to Maven Repository

on:
push:
branches:
- new_assets

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set up JDK
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '17'

- name: Make Gradlew Executable
run: chmod +x ./gradlew

- name: Build and Publish
run: |
./gradlew publish
env:
MAVEN_REPO_USERNAME: ${{ secrets.MAVEN_REPO_USERNAME }}
MAVEN_REPO_PASSWORD: ${{ secrets.MAVEN_REPO_PASSWORD }}
20 changes: 19 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,31 @@ subprojects {
}
}

def gitHash = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}

def gitBranch() {
def branch = ""
def proc = "git rev-parse --abbrev-ref HEAD".execute()
proc.in.eachLine { line -> branch = line }
proc.err.eachLine { line -> println line }
proc.waitFor()
branch
}

allprojects {
apply plugin: "java"
apply plugin: "architectury-plugin"
apply plugin: "maven-publish"

archivesBaseName = rootProject.jar_name
version = "${rootProject.minecraft_version}-${rootProject.mod_version}"
version = "${rootProject.minecraft_version}-${rootProject.mod_version}-${gitHash()}-${gitBranch()}"
group = rootProject.maven_group

repositories {
Expand Down
4 changes: 2 additions & 2 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ architectury {
publishing {
publications {
mavenCommon(MavenPublication) {
artifactId = rootProject.archives_base_name
artifactId = archives_base_name + "_" + project.name
from components.java
}
}

// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.

}
}
10 changes: 8 additions & 2 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,19 @@ components.java {
publishing {
publications {
mavenFabric(MavenPublication) {
artifactId = rootProject.archives_base_name + "-" + project.name
artifactId = archives_base_name + "_" + project.name
from components.java
}
}

// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
maven {
url = project.findProperty("maven_repo_url") ?: "https://maven.craig.software/repository/whocraft/"
credentials {
username = project.findProperty("MAVEN_REPO_USERNAME") ?: System.getenv("MAVEN_REPO_USERNAME") ?: ""
password = project.findProperty("MAVEN_REPO_PASSWORD") ?: System.getenv("MAVEN_REPO_PASSWORD") ?: ""
}
}
}
}
10 changes: 8 additions & 2 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,19 @@ components.java {
publishing {
publications {
mavenForge(MavenPublication) {
artifactId = archives_base_name + "-" + project.name
artifactId = archives_base_name + "_" + project.name
from components.java
}
}

// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
maven {
url = project.findProperty("maven_repo_url") ?: "https://maven.craig.software/repository/whocraft/"
credentials {
username = project.findProperty("MAVEN_REPO_USERNAME") ?: System.getenv("MAVEN_REPO_USERNAME") ?: ""
password = project.findProperty("MAVEN_REPO_PASSWORD") ?: System.getenv("MAVEN_REPO_PASSWORD") ?: ""
}
}
}
}

0 comments on commit cdc9718

Please sign in to comment.