Maven publish plugin to github repo

I am using the maven publish plugin from gradle 6.5 to publish generated artifacts to a github repository with the “publishGprPublicationToGitHubPackagesRepository” task but occasionally the publication fails with a 409 because the artifact is published. I am suspecting that for some reason the task executes more than once but not all the times. Is there a way to suppress the additional publication errors or make sure that the task executes only once?

Tasks cannot execute multiple times, they are always just run once.
You might want to enable build scans to have a better insight on what is happening when it fails next time.
Or if possible check when the files already present were published to maybe see why you try to publish the same files again.

1 Like

I recently spent time debugging a similar issue with our Artifactory server sometimes failing publications with a 409 even though the artifact was successfully published.

During execution of the publishing task, Gradle will retry its requests if it thinks there might have been a transient network failure. One of those cases is a timeout waiting for a response, sorry I cannot remember what Gradle’s internal timeout is, I think maybe it is 10 seconds. We had an issue with our server that would cause random delays in servicing the requests. Gradle would time out and then retry. The first request would store the artifact and then the second would fail with a 409 because we have overwrites disabled. Gradle would then fail the publishing task with the 409 response from the retry.

Running Gradle with info logging enabled should show you the retries if they are happening.

1 Like

Increasing the gradle log level to DEBUG, I can’t see an retries or duplicate PUT requests, however the 409 error code is still returned by Github.

Enabled gradle debug level logs but the output seems correct, only one occurrence of

2021-04-05T11:38:38.1961664Z 2021-04-05T11:38:26.962+0000 [DEBUG] [org.gradle.internal.resource.transport.http.HttpClientHelper] Performing HTTP PUT:

2021-04-05T11:38:38.2064180Z 2021-04-05T11:38:28.507+0000 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Upload' completed

Could it be any proxy or cache before that could be causing this?

That’s the log of a successful try, isn’t it? You need to look at a failing try.

If my previous investigation is correct, the default timeout is 30 seconds. If you want to tweak/experiment, the value can be manipulated using the system property org.gradle.internal.http.socketTimeout. There is also a default 30 second connection timeout controlled by org.gradle.internal.http.connectionTimeout.

See also JavaSystemPropertiesHttpTimeoutSettings.

Thanks for your time replying on this issue :slight_smile:
Actually, the logs that I posted above come from a failed task execution where the github action reports
Failed to publish publication ‘gpr’ to repository ‘GitHubPackages’
Could not PUT ‘’. Received status code 409 from server: Conflict`

As you can see, enabling the gradle -d flag gives the complete logs stack in which all PUT actions are successful, which is very odd.

Another failed run with 409

The PUT request fails with 409 even though no previous requests were logged for the same artifact.

If you’re certain that the file did not already exist in the repo and that Gradle isn’t trying to put the file multiple times, then perhaps this is something that you need to bring up with GitHub. I see there is a section for GitHub Packages on their community support forum.

Similar post, 409 from server: Conflict occurrs when publishing to GitHub Packages - GitHub Help - GitHub Support Community

Thanks, already tracked an issue on Github side. Thanks for your help.