How to make ivy-publish generated publish task depend on another task?

(Dave Smith) #1

What I have: ./gradlew packageFoo && ./gradlew publishFoo
What I want: ./gradlew publishFoo

I’m applying and configuring ivy-publish in a project.afterEvaluate block, to publish android apks to a local ivy repo for sharing with other tools How do I make the publications’ publish tasks depend on the tasks that produce the artifact they are publishing? Right now, I have to run the packageFoo task before I run the publishFooPublicationToLocalRepository.

project.afterEvaluate {
    apply plugin: 'ivy-publish'
    project.publishing { projPub ->
        publications { pubCfg ->

        // create a publication for each flavor and type { flavor ->
            ['debug', 'release'].each { type ->
                def buildName = "${}${type.capitalize()}"
                def pkgTaskName = "package${buildName}"
                def pkgTask = project.tasks.getByName(pkgTaskName)
                def apkFile = pkgTask.outputs.files.find { f ->'.apk') }

                "${buildName}"(IvyPublication) {
                    artifact apkFile
                    organisation ""
                    module "myname-${}-${type}"
                    revision project.version
    repositories { ... set up "local" repo }

I tried having more code after the project.publishing block which then explicitly wires up the dependencides, but those don’t seem to run in order so it doesn’t work.

(Chris Doré) #2

Configure the artifact of the publication to be built by the task:

artifact( apkFile ) {
    builtBy pkgTask

(Dave Smith) #3

Thanks a lot, that works great, not sure I how I missed the documentation for it.