如何在gradle.build中编译build.finalisedBy.uploadArchives

时间:2017-08-21 15:04:03

标签: android gradle android-gradle

我的gradle.build文件看起来像这样

apply plugin: 'java-library'
apply plugin: 'maven'

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    compile gradleApi()

    compile 'com.android.tools.build:gradle:2.3.3'
    compile 'org.aspectj:aspectjtools:1.8.10'
    compile 'org.aspectj:aspectjrt:1.8.10'
}

sourceCompatibility = "1.8"
targetCompatibility = "1.8"

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "file:///Users/BrionMarkov/.m2/repository/")
        }
    }
}

目前我必须手动执行uploadArchives,我希望每次构建(或重建)项目成功时,uploadArchives会自动执行。

我已尝试过build.finalisedBy.uploadArchives但是我的构建失败并带有

Error:(25, 0) No such property: uploadArchives for class: org.gradle.api.internal.tasks.DefaultTaskDependency

如何实现自动执行的uploadArchives?

更新

我将mu构建文件更改为以下

apply plugin: 'java-library'
apply plugin: 'maven'

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    compile gradleApi()

    compile 'com.android.tools.build:gradle:2.3.3'
    compile 'org.aspectj:aspectjtools:1.8.10'
    compile 'org.aspectj:aspectjrt:1.8.10'
}

sourceCompatibility = "1.8"
targetCompatibility = "1.8"

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "file:///Users/BrionMarkov/.m2/repository/")
        }
    }

}

build.finalizedBy(uploadArchives)

这不会生成任何错误消息,但是当我清理并重建我的主项目时,不会触发上传。

我还有什么问题?

更新

如果我使用“clean.finalizedBy(uploadArchives)”,则会自动执行uploadArchives,但“build.finalizedBy(uploadArchives)”无效

1 个答案:

答案 0 :(得分:1)

只需将此行添加到build.gradle

即可
build.finalizedBy(uploadArchives)