Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support publications with grade metadata feature enabled #229

Open
vvlevchenko opened this issue Apr 27, 2018 · 17 comments
Open

Support publications with grade metadata feature enabled #229

vvlevchenko opened this issue Apr 27, 2018 · 17 comments

Comments

@vvlevchenko
Copy link

vvlevchenko commented Apr 27, 2018

Gradle introduced gradle metadata feature in version 4.6 for which mostly used in native publications. It generate .module file for artifact which contains information about possible variants of artifact and configuration attributes for resolving. This file skipped by current version of plugin.

PR #230 realise metadata file publishing.

@h0tk3y
Copy link

h0tk3y commented Nov 13, 2018

+1 for this feature, as Kotlin Multiplatform projects now support publishing Gradle module metadata for simplifying dependency management. Is this going to be supported in the Bintray plugin?

@ilmat192
Copy link

Hi @eyalbe4! This issue prevents publishing Kotlin multiplatform libraries to Bintray but the PR mentioned above can fix it. Do you have any plans to merge it?

@fluidsonic
Copy link

Workaround which works for us until the Bintray plugin catches up.

build.gradle.kts

tasks.withType<BintrayUploadTask> {
    doFirst {
        publishing.publications
            .filterIsInstance<MavenPublication>()
            .forEach { publication ->
                val moduleFile = buildDir.resolve("publications/${publication.name}/module.json")
                if (moduleFile.exists()) {
                    publication.artifact(object : FileBasedMavenArtifact(moduleFile) {
                        override fun getDefaultExtension() = "module"
                    })
                }
            }
    }
}

Note that we use Gradle Kotlin Script, so for Grovvy-based build.gradle files the code needs to be adjusted.

@dhakehurst
Copy link

This is a great workaround, though how do you 'get' the 'publishing' variable

In my multi project, multiplatform build, in the root project 'publishing' is an unresolved reference!

@dhakehurst
Copy link

found the answer,
val publishing = extensions.getByType(PublishingExtension::class.java)

ddossot added a commit to apple/servicetalk that referenced this issue Sep 5, 2019
__Motivation__

An issue in the current version of the Bintray plugin prevents it from uploading the Gradle module metadata file.

__Modification__

Add the metadata files to the bintray task config.

Note that a more involved workaround is proposed in [1], this PR sends a workaround that is purely file based.

__Results__

Gradle module metadata are published.

[1] bintray/gradle-bintray-plugin#229
ddossot added a commit to apple/servicetalk that referenced this issue Sep 5, 2019
__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
@ljacomet
Copy link

Finding this issue after having added a similar support to the build-info plugin for Artifactory integration.
@eyalbe4 If I open a PR to enable this plugin, in a similar manner to what was done in jfrog/build-info#265 (and follow up PRs), what would be the objective in terms of supported Gradle versions?
The current version of this build uses Gradle 4.3. It would be awesome to be able to bump this to at least 4.10.3 and leverage some of the APIs introduced on internal types in the 4.x line, not available in 4.3.

@eyalbe4
Copy link
Contributor

eyalbe4 commented Dec 20, 2019

Sure @ljacomet,
We'd be happy to merge a PR that supports this.
Thanks!

ljacomet added a commit to ljacomet/gradle-bintray-plugin that referenced this issue Dec 23, 2019
This enables the upload of Gradle Module Metadata when generated.
The APIs used require Gradle 4.8 at the minimum.

Fixes bintray#229
gzoritchak added a commit to data2viz/data2viz that referenced this issue Jan 1, 2020
lamba92 added a commit to lamba92/firebase-ios-kotlin-native that referenced this issue Jan 4, 2020
araqnid added a commit to araqnid/arg-parser that referenced this issue Mar 24, 2020
@martinbonnin
Copy link

martinbonnin commented Mar 26, 2020

For the record, you can upload Gradle metadata with the maven-publish plugin bundled with Gradle. That will publish all the .module files:

      maven {
        name = "bintray"
        url = uri("https://api.bintray.com/maven/$subject/$repo/$package/;publish=1;override=1")
        credentials {
          username = username
          password = password
        }
      }

ljacomet added a commit to ljacomet/gradle-bintray-plugin that referenced this issue May 4, 2020
This enables the upload of Gradle Module Metadata when generated.
The APIs used require Gradle 4.8 at the minimum.

Fixes bintray#229
@tsjensen
Copy link

Thanks @fluidsonic for this quite sophisticated workaround! 👍

I adapted it for the Groovy DSL (probably imperfectly, but it works for me 😉):

import com.jfrog.bintray.gradle.tasks.BintrayUploadTask
import org.gradle.api.publish.maven.internal.artifact.FileBasedMavenArtifact

tasks.withType(BintrayUploadTask) {
    doFirst {
        publishing.publications.withType(MavenPublication).forEach({ publication ->
            File moduleFile = new File(project.buildDir, "publications/${publication.name}/module.json")
            if (moduleFile.exists()) {
                publication.artifact(new FileBasedMavenArtifact(moduleFile) {
                    protected String getDefaultExtension() {
                        return 'module';
                    }
                })
            }
        })
    }
}

@Danilo-Araujo-Silva
Copy link

The workaround provided is not working for me.

Locally, using Maven Local, it is being resolved automatically.
But when uploading to bintray, also with the workaround, the dependency is not resolve automatically.

For example, locally this works:

implementation("com.company:project:1.0.0")

But when using bintray, even when we have the .module uploaded there it is not resolving for me and only the version below is working:

implementation("com.company:project-jvm:1.0.0")

But it seems to be not perfect because when using KScript the second version does not work as well.

@LouisCAD
Copy link

@Danilo-Araujo-Silva Replacing this plugin by Gradle's first-party maven-publish plugin, as Martin said in this comment above will solve all your issues.

@tsjensen
Copy link

@LouisCAD Really? How will you handle the secondary features, such as synching to Maven Central without going through their complicated workflow?

@LouisCAD
Copy link

@tsjensen You are mistaking the maven-publish gradle plugin with Maven Central.
The example I linked uploads to bintray. Please, take the time to read it 🙂

@martinbonnin
Copy link

@tsjensen if you're talking about https://github.com/bintray/gradle-bintray-plugin#Maven_Central_Sync, I think (but have never tried so that'll need confirmation) that you can setup Maven Central sync from the UI at bintray.com. Once setup in the UI, bintray should sync every time you push, whether you push with the maven-publish or bintray plugin.

@tsjensen
Copy link

tsjensen commented Jun 17, 2020

@martinbonnin Yes, that's what I mean. I tried hard to get this to run via their UI. It worked, but only when pushing the buttons manually. For automation, this plugin seemed like the only way.

@LouisCAD No, I did not "mix up maven-publish and Maven Central". I am genuinely interested in finding out how to do the Maven Central Sync when publishing to bintray using maven-publish. If you can point us to somewhere this is resolved, then I'll switch!

@martinbonnin
Copy link

@tsjensen the maven-publish plugin will not help with bintray specific features like this but you could certainly use the bintray API to automate this separately. It looks like a HTTP POST is everything that is required to sync a given version of a package: https://bintray.com/docs/api/#_sync_version_artifacts_to_maven_central

@LouisCAD
Copy link

Ah, I get it now. What Martin just wrote should work for syncing bintray to maven central.

In fact, that's how the gradle-bintray-plugin has been doing it:

private void mavenCentralSync(String repoName, String pkgName, String versionName, BintrayUploadTask task) {

joffrey-bion pushed a commit to joffrey-bion/krossbow that referenced this issue Aug 31, 2020
Bintray plugin doesn't upload module files:
bintray/gradle-bintray-plugin#229 (comment)

Resolves:
#63
oshai added a commit to oshai/kotlin-logging that referenced this issue Sep 13, 2020
exaV pushed a commit to exaV/screeps-kotlin-types that referenced this issue Oct 16, 2020
Add a workaround for publishing to bintray with gradle metadata
see bintray/gradle-bintray-plugin#229
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests