Gradle-Publish-没有创建pom.xml文件

时间:2018-09-24 18:26:43

标签: maven gradle publish

我正在尝试使用this指南将库发布到AWS S3 Maven存储库。最终将其正确无误地上传到S3存储桶后,按照指南,我将其作为新项目的依赖项。

当我尝试构建新项目时,发生错误,指出找不到我的库的第一个依赖项。当然,没有生成包含该依赖项(和其他依赖项)的pom.xml文件。

我不太了解如何编写Gradle任务,我认为问题出在脚本的pom.withXml {}部分。否则在此之前可能会发生问题,因为甚至没有空的pom.xml文件。

这是整个脚本:

apply plugin: 'com.android.library'
apply plugin: 'maven-publish'

// update these next lines to fit your submodule
group = 'com.myproject'
version = '1.0'

// Add sources as an artifact
task sourceJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier "source"
}

// Loop over all variants
android.libraryVariants.all { variant ->
    variant.outputs.all { output ->
        // This creates a publication for each variant
        publishing.publications.create(variant.name, MavenPublication) {
            // The sources artifact from earlier
            artifact sourceJar

            // Variant dependent artifact, e.g. release, debug
            artifact source: output.outputFile, classifier: output.name

            // Go through all the dependencies for each variant and add them to the POM
            // file as dependencies
            pom.withXml {
                def dependencies = asNode().appendNode('dependencies')

                // Filter out anything that's not an external dependency. You shouldn't
                // be publishing artifacts that depend on local (e.g. project) dependencies,
                // but who knows...
                configurations.getByName(variant.name + "CompileClasspath").allDependencies
                        .findAll { it instanceof ExternalDependency }
                        .each {
                    def dependency = dependencies.appendNode('dependency')

                    dependency.appendNode('groupId', it.group)
                    dependency.appendNode('artifactId', it.name)
                    dependency.appendNode('version', it.version)
                }
            }
        }
    }
}

// Ensure that the publish task depends on assembly
tasks.all { task ->
    if (task instanceof AbstractPublishToMaven) {
        task.dependsOn assemble
    }
}

// Configure the destination repository with
// S3 URL and access credentials
publishing {
    repositories {
        maven {
            url "s3://sdk.myproject.com.s3.amazonaws.com"
            credentials(AwsCredentials) {
                accessKey AWS_ACCESS_KEY
                secretKey AWS_SECRET_KEY
            }
        }
    }
}

关于出什么问题的任何想法?谢谢!

0 个答案:

没有答案