Skip to content

Commit

Permalink
Fix Bintray upload of Gradle module metadata (#766)
Browse files Browse the repository at this point in the history
__Motivation__

The recently introduced fix for Bintray plugin's Gradle module metadata issue is not working because the Bintray plugin copy task (`_bintrayRecordingCopy`) runs before the generation of the Gradle metadata (`generateMetadataFileForMavenJavaPublication`).

This was not detected locally because the Gradle metadata was preexisting in an unclean build when `bintrayUpload` was tested.

__Modifications__

- Use the workaround suggested in [1],
- Review application of `maven-publish` plugin as it now must be done before Bintray.

__Results__

Gradle module metadata files are uploaded to Bintray (hopefully 😅).

[1] bintray/gradle-bintray-plugin#229
  • Loading branch information
ddossot authored Sep 5, 2019
1 parent 2c4092c commit 8032da9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
1 change: 0 additions & 1 deletion servicetalk-bom-internal/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

apply plugin: "servicetalk-core"
apply plugin: "java-platform"
apply plugin: "maven-publish"

dependencies {
constraints {
Expand Down
1 change: 0 additions & 1 deletion servicetalk-bom/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

apply plugin: "servicetalk-core"
apply plugin: "java-platform"
apply plugin: "maven-publish"

rootProject.subprojects.findAll { !it.name.contains("bom") && !it.name.contains("examples") }.each {
dependencies.constraints.add("api", it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ final class ProjectUtils {
configFile.exists() ? configFile : project.file("$project.projectDir/$path")
}

private static void addQualityTask(Project project) {
static void addQualityTask(Project project) {
project.configure(project) {
project.task("quality") {
description = "Run all quality analyzers for all source sets"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
*/
package io.servicetalk.gradle.plugin.internal

import com.jfrog.bintray.gradle.tasks.BintrayUploadTask
import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.XmlProvider
import org.gradle.api.plugins.quality.Checkstyle
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.internal.artifact.FileBasedMavenArtifact

import static io.servicetalk.gradle.plugin.internal.ProjectUtils.addBuildContextExtensions
import static io.servicetalk.gradle.plugin.internal.ProjectUtils.appendNodes
Expand All @@ -31,13 +35,14 @@ import static io.servicetalk.gradle.plugin.internal.Versions.CHECKSTYLE_VERSION
import static io.servicetalk.gradle.plugin.internal.Versions.TARGET_VERSION

class ServiceTalkCorePlugin implements Plugin<Project> {
void apply(Project project, boolean includeBintrayPlugin = true) {
void apply(Project project, boolean publishesArtifacts = true) {
enforceUtf8FileSystem()
addBuildContextExtensions project
applyCheckstylePlugin project
applyIdeaPlugin project

if (includeBintrayPlugin) {
if (publishesArtifacts) {
applyMavenPublishPlugin project
applyBintrayPlugin project
}
}
Expand Down Expand Up @@ -123,6 +128,12 @@ class ServiceTalkCorePlugin implements Plugin<Project> {
}
}

private static void applyMavenPublishPlugin(Project project) {
project.configure(project) {
pluginManager.apply("maven-publish")
}
}

private static void applyBintrayPlugin(Project project) {
project.configure(project) {
pluginManager.apply("com.jfrog.bintray")
Expand All @@ -147,15 +158,6 @@ class ServiceTalkCorePlugin implements Plugin<Project> {
key = bintrayKey
publications = ["mavenJava"]

// Temporary workaround for https://github.com/bintray/gradle-bintray-plugin/issues/229
def groupPath = project.group.replaceAll('\\.', '/')
filesSpec {
from "$buildDir/publications/mavenJava"
include "module.json"
into "$groupPath/$project.name/$project.version"
rename ".*", "$project.name-${project.version}.module"
}

pkg {
userOrg = "servicetalk"
repo = "servicetalk"
Expand All @@ -166,6 +168,27 @@ class ServiceTalkCorePlugin implements Plugin<Project> {
override = true
publish = true
}

// Temporary workaround for https://github.com/bintray/gradle-bintray-plugin/issues/229
PublishingExtension publishing = project.extensions.getByType(PublishingExtension)
project.tasks.withType(BintrayUploadTask) {
doFirst {
publishing.publications.withType(MavenPublication).each { publication ->
File moduleFile = project.buildDir.toPath()
.resolve("publications/${publication.name}/module.json").toFile()

if (moduleFile.exists()) {
publication.artifact(new FileBasedMavenArtifact(moduleFile) {
@Override
protected String getDefaultExtension() {
return "module"
}
})
}
}
}
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ final class ServiceTalkLibraryPlugin extends ServiceTalkCorePlugin {
private static void applyJavaLibraryPlugin(Project project) {
project.configure(project) {
pluginManager.apply("java-library")
pluginManager.apply("maven-publish")

sourceCompatibility = TARGET_VERSION
targetCompatibility = TARGET_VERSION
Expand Down

0 comments on commit 8032da9

Please sign in to comment.