ci(java): basic gradle publish setup

This commit is contained in:
zaaarf 2024-09-18 02:40:55 +02:00
parent 581419bfed
commit d2b5e413c5
No known key found for this signature in database
GPG key ID: C91CFF9E2262BBA1
3 changed files with 47 additions and 29 deletions

View file

@ -40,5 +40,11 @@ jobs:
with: with:
name: codemp-java-${{ matrix.platform.target }} name: codemp-java-${{ matrix.platform.target }}
path: dist/java/build/libs path: dist/java/build/libs
- run: gradle publish
env:
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
MAVEN_CENTRAL_GPG_SECRET_KEY: ${{ secrets.MAVEN_CENTRAL_GPG_SECRET_KEY }}
MAVEN_CENTRAL_GPG_PASSWORD: ${{ secrets.MAVEN_CENTRAL_GPG_PASSWORD }}
# TODO add a publish step to maven central # TODO add a publish step to maven central

View file

@ -1,12 +1,12 @@
plugins { plugins {
id 'java-library' id 'java-library'
id 'maven-publish' id 'maven-publish'
id 'signing'
id 'com.github.johnrengelman.shadow' version '8.1.1' id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'com.palantir.git-version' version '3.1.0'
} }
group = 'mp.code' group = 'mp.code'
version = versionDetails().lastTag.substring(1) version = '0.0.1-SNAPSHOT'
java { java {
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8 sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
@ -61,43 +61,49 @@ build.finalizedBy shadowJar
publishing { publishing {
publications { publications {
mavenJava(MavenPublication) { mavenJava(MavenPublication) {
artifactId = 'my-library' artifactId = rootProject.name
version = project.version
from components.java from components.java
versionMapping {
usage('java-api') {
fromResolutionOf('runtimeClasspath')
}
usage('java-runtime') {
fromResolutionResult()
}
}
pom { pom {
name = 'My Library' name = 'codemp'
description = 'A concise description of my library' description = 'A collaborative editor plugin ecosystem'
url = 'http://www.example.com/library' url = 'https://code.mp'
properties = [
myProp: "value",
"prop.with.dots": "anotherValue"
]
licenses { licenses {
license { license {
name = 'The Apache License, Version 2.0' name = 'The GNU General Public License v3.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' url = 'https://www.gnu.org/licenses/gpl-3.0.txt'
} }
} }
developers { developers {
developer { developer {
id = 'johnd' id = 'zaaarf'
name = 'John Doe' email = 'zaaarf@codemp.dev'
email = 'john.doe@example.com'
} }
} }
scm { scm {
connection = 'scm:git:git://example.com/my-library.git' connection = 'scm:git:git://github.com/hexedtech/codemp.git'
developerConnection = 'scm:git:ssh://example.com/my-library.git' developerConnection = 'scm:git:ssh://github.com/hexedtech/codemp.git'
url = 'http://example.com/my-library/' url = 'https://github.com/hexedtech/codemp/'
} }
} }
} }
} }
repositories {
maven {
name = "centralManualTesting"
url "https://central.sonatype.com/api/v1/publisher/deployments/download/"
credentials {
username = System.getenv('MAVEN_CENTRAL_USERNAME')
password = System.getenv('MAVEN_CENTRAL_PASSWORD')
}
}
mavenCentral()
}
}
signing {
def signingKey = System.getenv('MAVEN_CENTRAL_GPG_SECRET_KEY')
def signingPassword = System.getenv('MAVEN_CENTRAL_GPG_PASSWORD')
useInMemoryPgpKeys(signingKey, signingPassword)
sign publishing.publications.mavenJava
} }

View file

@ -41,10 +41,16 @@ public final class Extensions {
static synchronized void loadLibraryIfNotPresent() { static synchronized void loadLibraryIfNotPresent() {
if(loaded) return; if(loaded) return;
try { try {
String filename = System.getProperty("os.name").startsWith("Windows") String os = System.getProperty("os.name").toLowerCase();
? "/natives/codemp.dll"
: "/natives/libcodemp.so"; String filename;
if(os.startsWith("windows")) {
filename = "/natives/codemp.dll";
} else if(os.startsWith("mac")) {
filename = "/natives/libcodemp.dylib";;
} else filename = "/natives/libcodemp.so";
cz.adamh.utils.NativeUtils.loadLibraryFromJar(filename); cz.adamh.utils.NativeUtils.loadLibraryFromJar(filename);
loaded = true; loaded = true;
} catch(IOException e) { } catch(IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);