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.

https://pastebin.pl/view/21f2abd3

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: https://maven.pkg.github.com/XXX/mil-api-doc/7.4.18/mil-api-doc-7.4.18.jar

2021-04-05T11:38:38.2064180Z 2021-04-05T11:38:28.507+0000 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Upload https://maven.pkg.github.com/XXX/mil-api-doc/7.4.18/mil-api-doc-7.4.18.jar' completed

Could it be any proxy or cache before https://maven.pkg.github.com 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 ‘https://maven.pkg.github.com/XXX/mil-api-doc/7.4.18/mil-api-doc-7.4.18.jar’. 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.

This issue has been occcurring from time to time randomly in some of our releases which uses a gradle build. The following is a sample of the error.

> Task :testerina:testerina-runtime:publishMavenJavaPublicationToGitHubPackagesRepository
* What went wrong:
Execution failed for task ':ballerina-test-utils:publishMavenJavaPublicationToGitHubPackagesRepository'.
> Failed to publish publication 'mavenJava' to repository 'GitHubPackages'
   > Could not PUT 'https://maven.pkg.github.com/ballerina-platform/ballerina-lang/org/ballerinalang/ballerina-test-utils/2201.9.2/ballerina-test-utils-2201.9.2.pom.sha1'. Received status code 409 from server: Conflict

The package which has been indicated that has a conflict varies in the failed release builds. But as the original issue mentioned here, we didn’t have the package with the same version before the build in the maven packages.

I want know if there is a way to at least ignore 409 conflict error in the maven package publishing in a gradle build?

I don’t think there is a way to ignore it and you should not ignore it.
You tell Gradle to publish this file and the server says “no, there is something wrong”.
Afair the error means, that you try to upload something that is already present.
If you are sure this is not the case, maybe you hit some bug in GPR and should open an issue there so that their support can have a look at it.