From 3bf91fe0531129d59a03ce29421bf113baa46a4a Mon Sep 17 00:00:00 2001 From: CaiHQ Date: Thu, 21 Apr 2022 22:43:39 +0800 Subject: [PATCH] feat: support publish to mvn center --- .gitignore | 1 + README.md | 12 +++ build.gradle | 94 +++++++++++++++++-- src/main/java/org.zz/gmhelper/SM2KeyPair.java | 13 +-- 4 files changed, 104 insertions(+), 16 deletions(-) create mode 100644 README.md diff --git a/.gitignore b/.gitignore index 0a7c0b4..60b18e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +gradle.properties build # Compiled class file *.class diff --git a/README.md b/README.md new file mode 100644 index 0000000..f58511b --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +#说明 +本项目fork自`https://github.com/ZZMarquis/gmhelper` +和`https://github.com/FISCO-BCOS/paillier-lib` +编译报错时需配置gradle.properties文件 + +```bash +NEXUS_USERNAME=_your_name_ +NEXUS_PASSWORD=_your_passowrd_ +signing.keyId=_your_own_key_id_ +signing.password=_keyid_passowrd_ +signing.secretKeyRingFile=/path/to/the/key.pgp +``` \ No newline at end of file diff --git a/build.gradle b/build.gradle index e5cfb32..3c7bdda 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,11 @@ plugins { + id 'java' id 'java-library' + id 'maven-publish' + id 'signing' } - +group 'org.bdware.bdcontract' +version '0.1.0' sourceCompatibility = 1.8 repositories { @@ -13,13 +17,8 @@ task copyLibs(type: Copy) { into "./build/output/libs/" } -//task copyJar(type: Exec, dependsOn: [":gmhelper:jar", ":gmhelper:copyLibs"]) { -// println("copyJar start") -// commandLine "cp", "./build/libs/$project.name-$version" + ".jar", "./build/output/gmhelper.jar" -//} - task copyJar(type: Copy, dependsOn: [":gmhelper:jar", ":gmhelper:copyLibs"]) { - from "./build/libs/$project.name-${project.version}.jar" + from "./build/libs/$project.name-${version}.jar" into "./build/output" rename { String fileName -> "gmhelper.jar" } doFirst { @@ -31,6 +30,85 @@ dependencies { api 'com.google.code.gson:gson:2.8.8' api 'org.bouncycastle:bcpkix-jdk15on:1.69' api 'org.bouncycastle:bcprov-jdk15on:1.69' - testImplementation 'junit:junit:4.13.2' } + +task classJar(type: Jar, dependsOn: classes) { + classifier = "jar" +} +task sourceJar(type: Jar, dependsOn: classes) { + archiveClassifier = "sources" + classifier = "sources" + from sourceSets.main.allSource +} + +tasks.withType(Javadoc) { + options.addStringOption('Xdoclint:none', '-quiet') +} + +task javadocJar(type: Jar, dependsOn: javadoc) { + archiveClassifier = 'javadoc' + classifier = "javadoc" + exclude { + details -> details.file.getAbsolutePath().contains("/gm/") + } + from javadoc.destinationDir +} + +publishing { + publications { + mavenJava(MavenPublication) { + groupId project.group + artifactId "gmhelper" + version "${version}" + from components.java + artifact sourceJar + artifact javadocJar + artifact classJar + pom { + name = "bdware-gmhelper" + description = "gmhelper" + url = "https://gitee.com/BDWare/gmhelper" + licenses { + license { + name = "Mulan PSL v2" + url = "http://license.coscl.org.cn/MulanPSL2" + } + } + developers { + developer { + id = "dataware" + email = "caihq@pku.edu.cn" + } + } + scm { + connection = "scm:git:https://gitee.com/BDWare/gmhelper.git" + developerConnection = "scm:git:https://gitee.com/BDWare/gmhelper.git" + url = "https://gitee.com/BDWare/gmhelper" + } + } + + } + } + repositories { + maven { + name 'bdwareSnapshotRepository' + url 'https://oss.sonatype.org/content/repositories/snapshots' + credentials { + username = "${NEXUS_USERNAME}" + password = "${NEXUS_PASSWORD}" + } + } + maven { + name 'bdwareRepository' + url 'https://oss.sonatype.org/service/local/staging/deploy/maven2' + credentials { + username = "${NEXUS_USERNAME}" + password = "${NEXUS_PASSWORD}" + } + } + } +} +signing { + sign publishing.publications.mavenJava +} \ No newline at end of file diff --git a/src/main/java/org.zz/gmhelper/SM2KeyPair.java b/src/main/java/org.zz/gmhelper/SM2KeyPair.java index 2754969..cdb053f 100644 --- a/src/main/java/org.zz/gmhelper/SM2KeyPair.java +++ b/src/main/java/org.zz/gmhelper/SM2KeyPair.java @@ -1,7 +1,7 @@ package org.zz.gmhelper; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import org.bouncycastle.crypto.params.ECDomainParameters; import org.bouncycastle.crypto.params.ECPrivateKeyParameters; import org.bouncycastle.crypto.params.ECPublicKeyParameters; @@ -13,7 +13,6 @@ import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; import java.math.BigInteger; import java.security.KeyPair; -import java.util.Map; /** * SM2密钥对Bean @@ -30,11 +29,9 @@ public class SM2KeyPair { } public static SM2KeyPair fromJson(String jsonStr) { - Map jo = - new Gson().fromJson(jsonStr, new TypeToken>() { - }.getType()); - String publicKeyStr = jo.get("publicKey"); - String privateKeyStr = jo.get("privateKey"); + JsonObject jo = JsonParser.parseString(jsonStr).getAsJsonObject(); + String publicKeyStr = jo.get("publicKey").getAsString(); + String privateKeyStr = jo.get("privateKey").getAsString(); ECPublicKeyParameters point = BCECUtil.createECPublicKeyFromStrParameters( publicKeyStr, SM2Util.CURVE, SM2Util.DOMAIN_PARAMS);