代码之家  ›  专栏  ›  技术社区  ›  NickUnuchek Romulano

使用multyply“exclude”时如何修复“POM file is invalid”?

  •  0
  • NickUnuchek Romulano  · 技术社区  · 6 年前
    dependencies {
    ...
    api ("com.jakewharton:butterknife:${rootProject.ext.butterKnifeVersion}"){
            exclude group: 'com.android.support', module: 'support-compat'
            exclude group: 'com.android.support', module: 'support-annotations'
        }
    ...
    }
    

    发布过程如下:

    publishing {
        publications {
            bintrayMavenPublication(MavenPublication) {
                groupId theGroupId
                artifactId theArtifactId
                version theVersion
    
                artifact androidJavadocsJar
                artifact androidSourcesJar
                artifact bundleRelease
    
                pom.withXml {
                    final dependenciesNode = asNode().appendNode('dependencies')
    
                    ext.addDependency = { Dependency dep, String scope ->
                        final dependencyNode = dependenciesNode.appendNode('dependency')
                        dependencyNode.appendNode('groupId', dep.group)
                        dependencyNode.appendNode('artifactId', dep.group == theGroupId ? dep.name.substring(9) : dep.name)
                        dependencyNode.appendNode('version', dep.version)
                        dependencyNode.appendNode('scope', scope)
    
                        if (!dep.transitive) {
                            final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
                            exclusionNode.appendNode('groupId', '*')
                            exclusionNode.appendNode('artifactId', '*')
                        } else if (!dep.properties.excludeRules.empty) {
                            final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
                            dep.properties.excludeRules.each { ExcludeRule rule ->
                                exclusionNode.appendNode('groupId', rule.group ?: '*')
                                exclusionNode.appendNode('artifactId', rule.module ?: '*')
                            }
                        }
                    }
    
                    configurations.api.getAllDependencies().each { dep -> addDependency(dep, "compile") }
                    configurations.implementation.getAllDependencies().each { dep -> addDependency(dep, "runtime") }
                }
            }
        }
    }
    

    结果,pom文件有:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.example</groupId>
      <artifactId>library-example</artifactId>
      <version>1.0.0</version>
      <packaging>aar</packaging>
      <dependencies>
        <dependency>
          <groupId>com.jakewharton</groupId>
          <artifactId>butterknife</artifactId>
          <version>8.8.1</version>
          <scope>compile</scope>
          <exclusions>
            <exclusion>
              <groupId>com.android.support</groupId>
              <artifactId>support-annotations</artifactId>
              <groupId>com.android.support</groupId>
              <artifactId>support-compat</artifactId>
            </exclusion>
          </exclusions>
        </dependency>
      </dependencies>
    </project>
    

    就像你现在看到的 <exclusion> <artifactId> 还有两个 <groupId> . 如何修复并将其拆分为两个单独的标记 < ?

    错误是:

    • 出了什么问题:

      无法将发布“bintrayMavenPublication”发布到存储库“mavenCustom” 发布“bintrayMavenPublication”无效:POM文件无效。检查对POM文件所做的任何修改。

      • 尝试: 使用--stack trace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获得更多日志输出。运行--扫描以获得完整的见解。

      • 获得更多帮助 https://help.gradle.org

    1 回复  |  直到 6 年前
        1
  •  1
  •   NickUnuchek Romulano    6 年前

    修正者:

    ...
    } else if (!dep.properties.excludeRules.empty) {
                            // Otherwise add specified exclude rules
                            final exclusionsNode = dependencyNode.appendNode('exclusions')
                            dep.properties.excludeRules.each { ExcludeRule rule ->
                                def exclusion = exclusionsNode.appendNode('exclusion')
                                exclusion.appendNode('groupId', rule.group ?: '*')
                                exclusion.appendNode('artifactId', rule.module ?: '*')
                            }
                        }
    ...