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:
name: codemp-java-${{ matrix.platform.target }}
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

View file

@ -1,12 +1,12 @@
plugins {
id 'java-library'
id 'maven-publish'
id 'signing'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'com.palantir.git-version' version '3.1.0'
}
group = 'mp.code'
version = versionDetails().lastTag.substring(1)
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
@ -61,43 +61,49 @@ build.finalizedBy shadowJar
publishing {
publications {
mavenJava(MavenPublication) {
artifactId = 'my-library'
artifactId = rootProject.name
version = project.version
from components.java
versionMapping {
usage('java-api') {
fromResolutionOf('runtimeClasspath')
}
usage('java-runtime') {
fromResolutionResult()
}
}
pom {
name = 'My Library'
description = 'A concise description of my library'
url = 'http://www.example.com/library'
properties = [
myProp: "value",
"prop.with.dots": "anotherValue"
]
name = 'codemp'
description = 'A collaborative editor plugin ecosystem'
url = 'https://code.mp'
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
name = 'The GNU General Public License v3.0'
url = 'https://www.gnu.org/licenses/gpl-3.0.txt'
}
}
developers {
developer {
id = 'johnd'
name = 'John Doe'
email = 'john.doe@example.com'
id = 'zaaarf'
email = 'zaaarf@codemp.dev'
}
}
scm {
connection = 'scm:git:git://example.com/my-library.git'
developerConnection = 'scm:git:ssh://example.com/my-library.git'
url = 'http://example.com/my-library/'
connection = 'scm:git:git://github.com/hexedtech/codemp.git'
developerConnection = 'scm:git:ssh://github.com/hexedtech/codemp.git'
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() {
if(loaded) return;
try {
String filename = System.getProperty("os.name").startsWith("Windows")
? "/natives/codemp.dll"
: "/natives/libcodemp.so";
String os = System.getProperty("os.name").toLowerCase();
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);
loaded = true;
} catch(IOException e) {
throw new RuntimeException(e);