Publishing artifact from gradle project to bintray (maven repository)
Asked Answered
K

2

10

I have configured Gradle to publish project artifact using new Maven Publisher Plugin, unfortunately this plugin has problem with dependency in generated pom.xml - dependencies has scope runtime instead of compile.

My configuration is like this:

apply plugin: 'maven-publish'

publishing {
    publications {
        mavenCustom(MavenPublication) {
            from components.java
        }
    }
    repositories {
        maven {
            url "https://api.bintray.com/maven/codearte/public/fairyland"
            credentials {
                username = bintrayUser
                password = bintrayKey
            }
        }
    }
}

Publishing was simple with one command:

gradle publish

How to achieve this in old (working) way? Is possible to automate project taging when project is released?

Kansu answered 21/11, 2013 at 21:9 Comment(0)
K
6

Ok, I figured it out:

apply plugin: 'maven'

uploadArchives {
    repositories {
        mavenDeployer {
            name = 'Codearte Public Repository'
            repository(id: 'codearte-repository', url: 'https://api.bintray.com/maven/codearte/public/fairyland'){
                authentication(userName: bintrayUser, password: bintrayKey)
        }
    }
}

Uploading with command:

gradle uploadArchives
Kansu answered 21/11, 2013 at 22:17 Comment(1)
I'd also suggest you take a look at the bintray gradle plugin. It makes publishing to Bintray much easier.Garretgarreth
O
3

The fact that all POM dependencies have runtime scope is a known limitation of the new, incubating maven-publish plugin. Until this gets fixed, you can either fix it up yourself by using the publication.pom.withXml hook, or fall back to the maven plugin. Both plugins are documented in the Gradle User Guide.

Tagging is an entirely different question. You can either use one of the third-party Gradle SCM plugins or call out to a command line tool (e.g. with an Exec task).

Ovida answered 21/11, 2013 at 21:45 Comment(5)
In my opinion new gradle maven-plugin is not new anymore, but problem still exist.Kansu
Is this "new, incubating" plugin ever going to be finished?Fragment
Here is example 'withXml hook' gist.github.com/bugs84/… which i found here discuss.gradle.org/t/… it's working for meJay
Is there a bug anywhere tracking this limitation?Circassia
From discuss.gradle.org/t/… publishing { publications { pom.withXml { asNode().dependencies.''.findAll() { it.scope.text() == 'runtime' && project.configurations.compile.allDependencies.find { dep -> dep.name == it.artifactId.text() } }.each() { it.scope.value = 'compile' } } } }Sinegold

© 2022 - 2024 — McMap. All rights reserved.