From d2b5e413c53d940f996517cbf5faeaecc180fcdf Mon Sep 17 00:00:00 2001 From: zaaarf Date: Wed, 18 Sep 2024 02:40:55 +0200 Subject: [PATCH] ci(java): basic gradle publish setup --- .github/workflows/java.yml | 6 +++ dist/java/build.gradle | 58 +++++++++++++++------------ dist/java/src/mp/code/Extensions.java | 12 ++++-- 3 files changed, 47 insertions(+), 29 deletions(-) diff --git a/.github/workflows/java.yml b/.github/workflows/java.yml index a95e1d4..af6314a 100644 --- a/.github/workflows/java.yml +++ b/.github/workflows/java.yml @@ -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 diff --git a/dist/java/build.gradle b/dist/java/build.gradle index 9496a40..2abb0fb 100644 --- a/dist/java/build.gradle +++ b/dist/java/build.gradle @@ -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 +} \ No newline at end of file diff --git a/dist/java/src/mp/code/Extensions.java b/dist/java/src/mp/code/Extensions.java index c6cddfa..34c2984 100644 --- a/dist/java/src/mp/code/Extensions.java +++ b/dist/java/src/mp/code/Extensions.java @@ -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);