From ad74673e7f7cf91d6b4e9261b657970030196bcf Mon Sep 17 00:00:00 2001 From: Him188 Date: Tue, 18 Aug 2020 09:24:44 +0800 Subject: [PATCH] New MPP publishing (#489) --- .github/workflows/bintray.yml | 11 +- gradle.properties | 4 +- gradle/bintray.gradle | 12 ++ gradle/publish.gradle | 228 +++++++++++++++----------- gradle/publishOld.gradle | 129 +++++++++++++++ mirai-core-qqandroid/build.gradle.kts | 16 ++ mirai-core/build.gradle.kts | 18 +- 7 files changed, 311 insertions(+), 107 deletions(-) create mode 100644 gradle/bintray.gradle create mode 100644 gradle/publishOld.gradle diff --git a/.github/workflows/bintray.yml b/.github/workflows/bintray.yml index b3fcd50a9..83072f5d7 100644 --- a/.github/workflows/bintray.yml +++ b/.github/workflows/bintray.yml @@ -28,13 +28,10 @@ jobs: run: ./gradlew build # if test's failed, don't publish - name: Check keys run: ./gradlew :mirai-core:ensureBintrayAvailable :mirai-core-qqandroid:ensureBintrayAvailable -Dbintray_user=${{ secrets.BINTRAY_USER }} -Pbintray_user=${{ secrets.BINTRAY_USER }} -Dbintray_key=${{ secrets.BINTRAY_KEY }} -Pbintray_key=${{ secrets.BINTRAY_KEY }} - - name: Gradle :mirai-core:bintrayUpload - run: ./gradlew :mirai-core:bintrayUpload -Dbintray_user=${{ secrets.BINTRAY_USER }} -Pbintray_user=${{ secrets.BINTRAY_USER }} -Dbintray_key=${{ secrets.BINTRAY_KEY }} -Pbintray_key=${{ secrets.BINTRAY_KEY }} - - name: Gradle :mirai-core-qqandroid:bintrayUpload - run: ./gradlew :mirai-core-qqandroid:bintrayUpload -Dbintray_user=${{ secrets.BINTRAY_USER }} -Pbintray_user=${{ secrets.BINTRAY_USER }} -Dbintray_key=${{ secrets.BINTRAY_KEY }} -Pbintray_key=${{ secrets.BINTRAY_KEY }} - - name: Gradle :mirai-serialization:bintrayUpload - run: ./gradlew :mirai-serialization:bintrayUpload -Dbintray_user=${{ secrets.BINTRAY_USER }} -Pbintray_user=${{ secrets.BINTRAY_USER }} -Dbintray_key=${{ secrets.BINTRAY_KEY }} -Pbintray_key=${{ secrets.BINTRAY_KEY }} - + - name: Gradle :mirai-core:publish + run: ./gradlew :mirai-core:publish -Dbintray_user=${{ secrets.BINTRAY_USER }} -Pbintray_user=${{ secrets.BINTRAY_USER }} -Dbintray_key=${{ secrets.BINTRAY_KEY }} -Pbintray_key=${{ secrets.BINTRAY_KEY }} + - name: Gradle :mirai-core-qqandroid:publish + run: ./gradlew :mirai-core-qqandroid:publish -Dbintray_user=${{ secrets.BINTRAY_USER }} -Pbintray_user=${{ secrets.BINTRAY_USER }} -Dbintray_key=${{ secrets.BINTRAY_KEY }} -Pbintray_key=${{ secrets.BINTRAY_KEY }} # - name: Upload artifact # uses: actions/upload-artifact@v1.0.0 diff --git a/gradle.properties b/gradle.properties index 7d006b978..e76c9a8d4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,6 @@ kotlin.parallel.tasks.in.project=true org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=512m -Dfile.encoding=UTF-8 org.gradle.parallel=true -#kotlin.mpp.enableGranularSourceSetsMetadata=true \ No newline at end of file +#kotlin.mpp.enableGranularSourceSetsMetadata=true + +systemProp.org.gradle.internal.publish.checksums.insecure=true \ No newline at end of file diff --git a/gradle/bintray.gradle b/gradle/bintray.gradle new file mode 100644 index 000000000..8a73daf7a --- /dev/null +++ b/gradle/bintray.gradle @@ -0,0 +1,12 @@ +publishing { + repositories { + maven { + url = "https://api.bintray.com/maven/mamoe/mirai/mirai-core/;publish=0" + + credentials { + username = upload.Bintray.getUser(project) + password = upload.Bintray.getKey(project) + } + } + } +} \ No newline at end of file diff --git a/gradle/publish.gradle b/gradle/publish.gradle index 001960256..5ce9b910d 100644 --- a/gradle/publish.gradle +++ b/gradle/publish.gradle @@ -1,87 +1,42 @@ -import upload.Bintray - // 部分源码来自 kotlinx.coroutines // Source code from kotlinx.coroutines -task ensureBintrayAvailable() { +tasks.register("ensureBintrayAvailable") { doLast { - if (!Bintray.isBintrayAvailable(project)) { + if (!upload.Bintray.isBintrayAvailable(project)) { throw new IllegalStateException("bintray isn't available. ") } } } -if (!Bintray.isBintrayAvailable(project)) { - println("bintray isn't available. NO PUBLICATIONS WILL BE SET") - return -} +def vcs = "https://github.com/mamoe/mirai" -def miraiGitHubUrl = "https://github.com/mamoe/mirai" - -bintray { - user = Bintray.getUser(project) - key = Bintray.getKey(project) - - pkg { - repo = 'mirai' - name = "mirai-core" - licenses = ['AGPL'] - vcsUrl = miraiGitHubUrl - websiteUrl = miraiGitHubUrl - githubRepo = miraiGitHubUrl - issueTrackerUrl = "$miraiGitHubUrl/issues" - /* version { - name = project.version - }*/ - } -} - -afterEvaluate { - project.publishing.publications.forEach { publication -> - publication.pom.withXml { - def root = asNode() - //root.appendNode('groupId', project.group) - //root.appendNode('artifactId', project.name) - //root.appendNode('version', project.version) - root.appendNode('name', project.name) - root.appendNode('description', project.description) - root.appendNode('url', miraiGitHubUrl) - root.children().last() + { - licenses { - license { - name "AGPL-V3" - url "https://www.gnu.org/licenses/agpl-3.0.txt" - distribution "repo" - } - } - developers { - developer { - id "mamoe" - name "Mamoe Technologies" - email "support@mamoe.net" - } - } - scm { - url miraiGitHubUrl - } - } +def pomConfig = { + licenses { + license { + name "AGPLv3 with Mamoe Exceptions" + url "https://github.com/mamoe/mirai/blob/master/LICENSE" + distribution "repo" } } + developers { + developer { + id "mamoe" + name "Mamoe Technologies" + email "support@mamoe.net" + } + } + scm { + url vcs + } } -bintrayUpload.doFirst { - publications = project.publishing.publications -} - -bintrayUpload.dependsOn { - def list = new LinkedList() - list.add(tasks.getByName("build")) - - list.addAll(tasks.findAll { task -> task.name.contains('Jar') }) - list.addAll(tasks.findAll { task -> task.name.startsWith('generateMetadataFileFor') }) - list.addAll(tasks.findAll { task -> task.name.startsWith('generatePomFileFor') }) - - list +project.ext.configureMavenCentralMetadata = { pom -> + def root = asNode() + root.appendNode('name', project.name) + root.appendNode('description', project.description) + root.appendNode('url', vcs) + root.children().last() + pomConfig } try { @@ -90,40 +45,117 @@ try { task javadocJar(type: Jar) { archiveClassifier = 'javadoc' } - } catch (Exception ignored) { } -publishing { - publications.all { - // add empty javadocs (no need for MPP root publication which publishes only pom file) - if (it.name != 'kotlinMultiplatform') { - it.artifact(javadocJar) + +try { + task stubJavadoc(type: Jar) { + archiveClassifier = 'javadoc' + } +}catch (Exception ignored) { + +} + +/** + * Publish the platform JAR and POM so that consumers who depend on this module and can't read Gradle module + * metadata can still get the platform artifact and transitive dependencies from the POM + * (see details in https://youtrack.jetbrains.com/issue/KT-39184#focus=streamItem-27-4115233.0-0) + */ +project.ext.publishPlatformArtifactsInRootModule = { platformPublication -> + afterEvaluate { + def platformPomBuilder = null + + platformPublication.pom.withXml { platformPomBuilder = asString() } + + publishing.publications.kotlinMultiplatform { + platformPublication.artifacts.forEach { + artifact(it) + } + + pom.withXml { + def pomStringBuilder = asString() + pomStringBuilder.setLength(0) + // The platform POM needs its artifact ID replaced with the artifact ID of the root module: + def platformPomString = platformPomBuilder.toString() + platformPomString.eachLine { line -> + if (!line.contains("