Android library dependencies missing from POM with Gradle

后端 未结 2 2018
没有蜡笔的小新
没有蜡笔的小新 2020-12-11 02:51

I am using Gradle to build an Android library project and deploy it to maven repository as an aar.

The library has some dependencies, which should be included in the

相关标签:
2条回答
  • 2020-12-11 02:57

    This is the solution that worked for me in the end:

    publishing {
        publications {
            sdk(MavenPublication) {
                artifactId libName
                artifact "${project.buildDir}/outputs/aar/${libName}-${project.version}.aar"
    
                //The publication doesn't know about our dependencies, so we have to manually add them to the pom
                pom.withXml {
                    // for dependencies and exclusions
                    def dependenciesNode = asNode().appendNode('dependencies')
                    configurations.implementation.allDependencies.withType(ModuleDepend‌​ency) { ModuleDependency dp ->
                        def dependencyNode = dependenciesNode.appendNode('dependency')
                        dependencyNode.appendNode('groupId', dp.group)
                        dependencyNode.appendNode('artifactId', dp.name)
                        dependencyNode.appendNode('version', dp.version)
    
                        // for exclusions
                        if (dp.excludeRules.size() > 0) {
                            def exclusions = dependencyNode.appendNode('exclusions')
                            dp.excludeRules.each { ExcludeRule ex ->
                                def exclusion = exclusions.appendNode('exclusion')
                                exclusion.appendNode('groupId', ex.group)
                                exclusion.appendNode('artifactId', ex.module)
                            }
                        }
                    }
                }
            }
        }
    
        repositories {
            maven {
                name 'myrepo'
                url 'https://maven.foo.com'
    
                credentials {
                    username mavenUsername
                    password mavenPassword
                }      
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-11 02:59

    try mavenDeployer: http://gradle.org/docs/current/userguide/maven_plugin.html

    uploadArchives {
        repositories {
            mavenDeployer {
                repository(url: "file://localhost/tmp/myRepo/")
                pom.version = '1.0Maven'
                pom.artifactId = 'myMavenName'
            }
        }
    }
    

    here you could set the pom details. You'll get a new goal called uploadArchives. When executed, it deploys to a given repo.

    0 讨论(0)
提交回复
热议问题