Skip to content

Commit be3d53c

Browse files
committed
Testing Maven support
1 parent 69a3591 commit be3d53c

File tree

5 files changed

+134
-23
lines changed

5 files changed

+134
-23
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ name: Java CI
33
on:
44
push:
55
pull_request:
6-
release:
7-
types:
8-
- created
96

107
permissions:
118
contents: write
@@ -27,20 +24,4 @@ jobs:
2724
run: |
2825
chmod +x gradlew
2926
./gradlew clean
30-
./gradlew lib
31-
./gradlew dex
32-
- name: Upload built mod artifact as a GitHub Action artifact
33-
uses: actions/upload-artifact@v4
34-
if: github.event_name == 'push' || github.event_name == 'pull_request'
35-
with:
36-
name: CustomJsonLib (zipped)
37-
path: |
38-
build/libs/CustomJsonLibCrossPlatform.jar
39-
build/libs/CustomJsonLib.jar
40-
if-no-files-found: error
41-
compression-level: 0
42-
- name: Upload built mod artifact into release
43-
uses: softprops/action-gh-release@v2
44-
if: github.event_name == 'release' && github.event.action == 'created'
45-
with:
46-
files: ${{ endsWith(github.event.release.name, 'Library') && 'build/libs/CustomJsonLib.jar' || 'build/libs/CustomJsonLibCrossPlatform.jar' }}
27+
./gradlew dex

.github/workflows/publish.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Java CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
tags:
8+
- 'v*'
9+
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
buildJar:
16+
name: Build and Publish Jar for Release
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Set up JDK 17
22+
uses: actions/setup-java@v4
23+
with:
24+
java-version: 17
25+
distribution: temurin
26+
27+
- name: Setup Gradle
28+
uses: gradle/actions/setup-gradle@v4
29+
30+
- name: Set Artifact Version
31+
run: |
32+
if [ "${GITHUB_REF_TYPE}" = "tag" ]; then
33+
# This is a release, so use the release's tag as the version.
34+
echo "ARTIFACT_VERSION=${GITHUB_REF_NAME}" >> $GITHUB_ENV
35+
elif [ "${GITHUB_REF_TYPE}" = "branch" ] && [ "${GITHUB_REF_NAME}" = "master" ]; then
36+
# This is a bleeding-edge, so use the short commit's hash as the version.
37+
echo "ARTIFACT_VERSION=$(git rev-parse --short=10 HEAD)" >> $GITHUB_ENV
38+
else
39+
# Sanity checks.
40+
echo "Error: Unsupported branch '${GITHUB_REF_NAME}' or ref type '${GITHUB_REF_TYPE}'" >&2
41+
exit 1
42+
fi
43+
44+
- name: Build mod artifact
45+
run: |
46+
chmod +x gradlew
47+
./gradlew clean
48+
./gradlew dex
49+
50+
- name: Upload built mod artifact as a GitHub Action artifact
51+
uses: actions/upload-artifact@v4
52+
if: github.event_name == 'push' || github.event_name == 'pull_request'
53+
with:
54+
name: CustomJsonLib (zipped)
55+
path: build/libs/CustomJsonLibCrossPlatform.jar
56+
if-no-files-found: error
57+
compression-level: 0
58+
59+
- name: Upload built mod artifact into release
60+
uses: softprops/action-gh-release@v2
61+
if: github.event_name == 'release' && github.event.action == 'created'
62+
with:
63+
files: 'build/libs/CustomJsonLibCrossPlatform.jar'
64+
name: CustomJsonLib.jar
65+
66+
- name: Publish Artifacts to Maven Repository
67+
run: |
68+
./gradlew -P version="${ARTIFACT_VERSION}" -D maven.repo.local="$(pwd)/.out" publishToMavenLocal
69+
70+
git clone https://${{ secrets.MAVEN_TOKEN_GITHUB }}@github.com/ThePythonGuy3/CustomJSONLibMaven.git --depth=1 ../CustomJSONLibMaven
71+
cp -r .out/* ../CustomJSONLibMaven
72+
cd ../CustomJSONLibMaven
73+
74+
git config user.name "GitHub Actions"
75+
git config user.email "actions@github.com"
76+
git add .
77+
git commit -m "Publishing for ${ARTIFACT_VERSION}"
78+
git push https://${{ secrets.MAVEN_TOKEN_GITHUB }}@github.com/ThePythonGuy3/CustomJSONLibMaven.git

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
bin/
33
build/
44
.gradle/
5+
.out/
56
.settings/
67
.project
78
.classpath

build.gradle.kts

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ buildscript{
1919

2020
plugins{
2121
java
22+
`maven-publish`
2223
}
2324

2425
val arcVersion: String by project
2526
val mindustryVersion: String by project
2627
val mindustryBEVersion: String by project
28+
val entVersion: String by project
2729

2830
val modName: String by project
2931
val modArtifact: String by project
@@ -42,6 +44,10 @@ fun mindustry(module: String): String{
4244
return "com.github.Anuken.Mindustry$module:$mindustryVersion"
4345
}
4446

47+
fun entity(module: String): String{
48+
return "com.github.GlennFolker.EntityAnno$module:$entVersion"
49+
}
50+
4551
allprojects{
4652
apply(plugin = "java")
4753
sourceSets["main"].java.setSrcDirs(listOf(layout.projectDirectory.dir("src")))
@@ -57,11 +63,17 @@ allprojects{
5763
}
5864
}
5965

66+
dependencies{
67+
// Downgrade Java 9+ syntax into being available in Java 8.
68+
annotationProcessor(entity(":downgrader"))
69+
}
70+
6071
repositories{
6172
// Necessary Maven repositories to pull dependencies from.
6273
mavenCentral()
6374
maven("https://oss.sonatype.org/content/repositories/snapshots/")
6475
maven("https://oss.sonatype.org/content/repositories/releases/")
76+
maven("https://raw.githubusercontent.com/GlennFolker/EntityAnnoMaven/main")
6577

6678
// Use Zelaux's non-buggy repository for release Mindustry and Arc builds.
6779
if(!useJitpack) maven("https://raw.githubusercontent.com/Zelaux/MindustryRepo/master/repository")
@@ -81,6 +93,26 @@ allprojects{
8193
}
8294
}
8395

96+
fun commonPom(pom: MavenPom){
97+
pom.apply{
98+
url = "https://github.com/ThePythonGuy3/CustomJSONLibMaven"
99+
inceptionYear = "2025"
100+
101+
licenses{
102+
license{
103+
name = "GPL-3.0-or-later"
104+
url = "https://www.gnu.org/licenses/gpl-3.0.en.html"
105+
distribution = "repo"
106+
}
107+
}
108+
109+
issueManagement{
110+
system = "GitHub Issue Tracker"
111+
url = "https://github.com/ThePythonGuy3/CustomJSONLibMaven/issues"
112+
}
113+
}
114+
}
115+
84116
project(":"){
85117
dependencies{
86118
compileOnly(mindustry(":core"))
@@ -96,7 +128,6 @@ project(":"){
96128
files(sourceSets["main"].output.resourcesDir),
97129
configurations.runtimeClasspath.map{conf -> conf.map{if(it.isDirectory) it else zipTree(it)}},
98130

99-
files(layout.projectDirectory.dir("assets")),
100131
layout.projectDirectory.file("icon.png"),
101132
meta
102133
)
@@ -125,7 +156,7 @@ project(":"){
125156
}
126157
}
127158

128-
val lib = tasks.register<Jar>("lib"){
159+
tasks.register<Jar>("lib"){
129160
archiveFileName = "$modArtifact.jar"
130161

131162
from(
@@ -195,4 +226,20 @@ project(":"){
195226
logger.lifecycle("Copied :jar output to $folder.")
196227
}
197228
}
198-
}
229+
230+
publishing.publications.register<MavenPublication>("maven")
231+
{
232+
artifact(tasks["lib"])
233+
234+
groupId = "com.github.ThePythonGuy3.CustomJSONLib"
235+
artifactId = "pyguy.jsonlib"
236+
237+
pom{
238+
name = "CustomJSONLib Maven Library"
239+
240+
description = "CustomJSONLib Library required to compile Mindustry mods using CustomJSONLib."
241+
242+
commonPom(this)
243+
}
244+
}
245+
}

gradle.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ modName = pyguy.jsonlib
44
# The mod's JAR file name. Desktop build is suffixed with `Desktop`.
55
modArtifact = CustomJsonLib
66

7+
# EntityAnno version, for integrating syntax-downgrader.
8+
# The exact version you need should be looked up on the project's `README.md`
9+
# (see https://github.com/GlennFolker/EntityAnno?tab=readme-ov-file#version-compatibility).
10+
entVersion = v146.0.10
711
# Set to `true` if the mod is compiled against Mindustry bleeding-edge build.
812
# See documents on `mindustryVersion` and `mindustryBEVersion`.
913
mindustryBE = false

0 commit comments

Comments
 (0)