Home > OS >  How to set timeout for gradle publish task?
How to set timeout for gradle publish task?

Time:10-22

I use "gradle publish" command to publish into nexus repo.

The config looks like this:

publishing {
    publications {
        maven(MavenPublication) {
            groupId = 'org.gradle.sample'
            artifactId = 'library'
            version = '1.1'

            from components.java
        }
    }
}

Timeout for task can be set like this:

task someTask {
    timeout = Duration.ofMinutes(25)
}

I would want to set timeout for all publish tasks (I think publishing config generates more tasks) generated by publishing config section. Something like this does not seem to work:

publishing {
    publications {
        maven(MavenPublication) {
            groupId = 'org.gradle.sample'
            artifactId = 'library'
            version = '1.1'

            from components.java

            timeout = Duration.ofMinutes(25)
        }
    }
}

CodePudding user response:

Task publish is an aggregate task that has no action. It will generate a task named publishPubNamePublicationToRepoNameRepository by your configuration with PubName replaced. You can use --dry-run to find which task is generated by it:

$ gradle publish --dry-run
:compileJava SKIPPED
:processResources SKIPPED
:classes SKIPPED
:jar SKIPPED
:generateMetadataFileForMavenPublication SKIPPED
:generatePomFileForMavenPublication SKIPPED
:publishMavenPublicationToMavenRepository SKIPPED
:publish SKIPPED

BUILD SUCCESSFUL in 1s

So my configuration would generate a publishing task publishMavenPublicationToMavenRepository. Then I could find that task and set its timeout duration:

plugins {
    id("java")
    id("maven-publish")
}

project.afterEvaluate {
    tasks.findByName("publishMavenPublicationToMavenRepository").configure {
        timeout = Duration.ofMillis(1)
    }
}

Note the tasks.findByName was put into the project.afterEvaluate block because publish generates that task dynamically.

Here is the expected result:

$ gradle publish

> Task :publishMavenPublicationToMavenRepository FAILED
Requesting stop of task ':publishMavenPublicationToMavenRepository' as it has exceeded its configured timeout of 1ms.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':publishMavenPublicationToMavenRepository'.
> Timeout has been exceeded

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
5 actionable tasks: 3 executed, 2 up-to-date
  • Related