0

我有一个 Android 库项目,我正在尝试使用 gradle 将 AAR 文件发布到 JFrog 工件。一旦我有了 AAR 文件并且当我执行构建任务时,发布按预期工作,问题是如果 AAR 文件不存在,我无法将它作为我的构建过程的一部分。

我想在有新文件可用时发布 AAR 文件。我试图把 assembleIntegrated.finalizedBy (artifactoryPublish),但这并没有帮助。在生成 AAR 之前触发发布任务。

mygradle.gradle -->

apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'

    File AARFile1 = file("$buildDir/outputs/aar/my_aar_file1.aar")
    File AARFile2 = file("$buildDir/outputs/aar/my_aar_file2.aar")

    publishing {
    publications {

        AAR1(MavenPublication) {
            groupId repoFolder
            version libVersion

            // Tell maven to prepare the generated "*.aar" file for publishing
            if (AARFile1.exists()) {
                artifactId libRelease
                artifact(AARFile1)
            } else {
                println 'AAR1 files not found in' + AARFile1.absolutePath
            }
        }

        AAR2(MavenPublication) {
            groupId repoFolder
            version libVersion

            // Tell maven to prepare the generated "*.aar" file for publishing
            if (AARFile2.exists()) {
                artifactId libDebug
                artifact(AARFile2)
            } else {
                println 'AAR2 files not found in' + AARFile2.absolutePath
            }
        }
    }
}


artifactory {
    contextUrl = "https://bintray.com/jfrog/artifactory:8080"
    publish {
        repository {
            // The Artifactory repository key to publish to
            repoKey = 'my_key'
           username = 'my_username'
           password = 'my_encrypt_password'
        }
        defaults {
            // Tell the Artifactory Plugin which artifacts should be published to Artifactory.
            if (AARFile1.exists() || AARFile2.exists()) {
                publications('AAR1', 'AAR2')
                publishArtifacts = true

                // Properties to be attached to the published artifacts.
                properties = ['qa.level': 'basic', 'dev.team':'Me' ]
                // Publish generated POM files to Artifactory (true by default)
                publishPom = true
            }
        }
    }
}

我看到 gradle 任务列表如下:

executing tasks: [assembleIntegrated]

    AAR1 files not found in /myfolder/.../my_lib_project/app/build/outputs/aar/my_aar_file1.aar
    AAR2 files not found in /myfolder/.../my_lib_project/app/build/outputs/aar/my_aar_file2.aar
      .
      .
      .

    > Task :app:preBuild UP-TO-DATE
    > Task :app:test UP-TO-DATE
    > Task :app:check
    > Task :app:build
    > Task :app:artifactoryPublish
    > Task :artifactoryDeploy
4

1 回答 1

0

发生这种情况是因为您手动将文件添加到 Maven 发布。当 maven 发布运行时,这些文件不存在。因此,您应该手动配置任务依赖项。当您将发布添加到项目中时,Gradle 将使用您的发布名称和 repo 名称的组合生成一些任务。类似的东西:publish{publicationName}PublicationTo{RepositoryName}Repository。因此,您应该将这些任务设置为依赖于assembleIntegration任务。

或者你可以使用android-maven-publish插件,它会自动完成这项工作。

于 2019-09-10T13:45:59.780 回答