bintray / gradle-bintray-plugin

Apache License 2.0
1.28k stars 197 forks source link

Wrong docs for new Gradle system with Android #274

Closed VedavyasBhat closed 5 years ago

VedavyasBhat commented 5 years ago

To package an Android library, the POM file doesn't include dependencies, so a manual override to the POM must be made. Step 4 of the docs here covers that, but there is an error in the following block:

    pom.withXml {
        // Iterate over the compile dependencies (we don't want the test ones), adding a <dependency> node for each
        configurations.implementation.allDependencies.each {
           // Ensure dependencies such as fileTree are not included.
           if (it.name != 'unspecified') {
              def dependencyNode = dependenciesNode.appendNode('dependency')
              dependencyNode.appendNode('groupId', it.group)
              dependencyNode.appendNode('artifactId', it.name)
              dependencyNode.appendNode('version', it.version)
           }
        }
      }

In the implementation (and api, for that matter) configuration, there is no dependenciesNode variable; it needs to be defined. Here is the above block with the fix (code tested and POM verified):

    pom.withXml {
        def dependenciesNode = asNode().getAt('dependencies')[0] ?: asNode().appendNode('dependencies')
        // Iterate over the compile dependencies (we don't want the test ones), adding a <dependency> node for each
        configurations.implementation.allDependencies.each {
           // Ensure dependencies such as fileTree are not included.
           if (it.name != 'unspecified') {
              def dependencyNode = dependenciesNode.appendNode('dependency')
              dependencyNode.appendNode('groupId', it.group)
              dependencyNode.appendNode('artifactId', it.name)
              dependencyNode.appendNode('version', it.version)
           }
        }
      }
langsmith commented 5 years ago

+1 about the error existing and the code to fix it. I ran into the issue mentioned above and in https://github.com/bintray/gradle-bintray-plugin/issues/272. @VedavyasBhat 's code above got rid of it 🚀

eyalbe4 commented 5 years ago

Thank you @VedavyasBhat and @langsmith for pointing this out! Would one of you be willing to create a pull request to fix this?

VedavyasBhat commented 5 years ago

Sure, I'll have one up shortly.

langsmith commented 5 years ago

Cool, thanks @VedavyasBhat

olLenz commented 5 years ago

The gradle sync fails when using the code snipped with the error: Gradle DSL method not found: 'asNode()'

After moving the line def dependenciesNode = asNode().getAt('dependencies')[0] ?: asNode().appendNode('dependencies') into the pom.withXML {}-scope the gradle sync was successfull. This should be updated in the docs :)