Artifactory打包发布到本地仓库,生成的pom文件dependencies丢失

如题,Artifactory在打包发布到本地仓库到时候,生成的pom文件可能会不包含dependencies

可以手动查找、添加build.gradle中包含的dependencies到最终生成到pom文件。

添加步骤:

  1. 使用implementation增加编译是需要导入的外部引用:

    dependencies {
      implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.60'
    }
  2. 修改上传发布的gradle代码:

    publishing {
        publications {
            aar(MavenPublication) {
                groupId = '{your_group_id}'
                artifactId = '{your_artifact_id}'
                version = '{your_artifact_version}'
                ..
    
                pom.withXml {
                    def dependenciesNode = asNode().appendNode('dependencies')
                    configurations.implementation.allDependencies.withType(ModuleDependency) { ModuleDependency dp ->
                        if (dp.version != "unspecified") { // 过滤项目内library引用
                            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)
                                }
                            }
                        }
                    }
                }
            }
        }
    }
  3. 调整完成后,重新打包发布,生成的pom文件就会包含项目引用。

    <dependencies>
      <dependency>
        <groupId>org.jetbrains.kotlingroupId>
        <artifactId>kotlin-stdlib-jdk7artifactId>
        <version>1.2.60version>
      dependency>
    dependencies>

相关链接:

  • Gradle Artifactory Plugin
  • Android library dependencies missing from POM with Gradle

你可能感兴趣的:(Android)