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?

MariuszS
  • 30,646
  • 12
  • 114
  • 155

2 Answers2

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
MariuszS
  • 30,646
  • 12
  • 114
  • 155
  • 4
    I'd also suggest you take a look at the [bintray gradle plugin](https://bintray.com/jfrog/jfrog-jars/gradle-bintray-plugin). It makes publishing to Bintray much easier. – JBaruch Nov 24 '13 at 07:43
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).

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
  • 2
    In my opinion new gradle `maven-plugin` is not new anymore, but problem still exist. – MariuszS Jul 01 '15 at 13:34
  • 4
    Is this "new, incubating" plugin ever going to be finished? – Kevin Krumwiede Oct 28 '15 at 21:10
  • Here is example 'withXml hook' https://gist.github.com/bugs84/b7887fb5d7f9f2d484b8#file-changefromruntimetocompile-gradle which i found here https://discuss.gradle.org/t/maven-publish-plugin-generated-pom-making-dependency-scope-runtime/7494/6 it's working for me – bugs_ Feb 26 '16 at 16:08
  • Is there a bug anywhere tracking this limitation? – Ilya Nov 02 '16 at 20:25
  • From https://discuss.gradle.org/t/maven-publish-plugin-generated-pom-making-dependency-scope-runtime/7494/5 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' } } } } – Arnaud Jeansen Feb 22 '18 at 15:26