Home > Blockchain >  `no cached resource available for offline mode` when publishing to Maven Central
`no cached resource available for offline mode` when publishing to Maven Central

Time:12-05

I've published 5 versions of my repository so far without any issues. With version 1.0.5 I'm getting an error:

Execution failed for task ':publishMavenJavaPublicationToOSSRHRepository'.

> Failed to publish publication 'mavenJava' to repository 'OSSRH'

> No cached resource 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/io/github/jspinak/brobot/1.0.5-SNAPSHOT/maven-metadata.xml' available for offline mode.

The only help I've found online is to toggle the offline mode in Gradle (No Cached Version Gradle Plugin Available for offline mode), which then produces the following error when publishing:

Could not GET 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/io/github/jspinak/brobot/1.0.5-SNAPSHOT/maven-metadata.xml'.

Received status code 400 from server: Bad Request Disable Gradle 'offline mode' and sync project

I'm not sure if this is something I've done wrong, a Sonatype issue, a Gradle issue, an Intellij issue, or something else. I've also posted on the Sonatype message boards just in case.

In the Gradle Toolbar, there is an option generateMetadataFileForMavenJavaPublication. Running this doesn't seem to change anything.

This is an open source repository and you can see the build.gradle file at https://github.com/jspinak/brobot/blob/main/library/build.gradle.

CodePudding user response:

This error occurs when trying to publish a snapshot version to the staging repository, which is for release versions. A snapshot differs from a release version in that it can be changed. Release versions cannot be changed to give developers who are using it the security that the functionality of their code will not change due to changes in the dependencies. Snapshots can be used for testing or to provide easy access to the latest code while still in development. Any version name with "-SNAPSHOT" at the end is considered a snapshot. All other names are considered release versions.

To publish a snapshot I would need the following lines of code in my build.gradle file:
version = '1.0.5-SNAPSHOT'
url = "https://s01.oss.sonatype.org/content/repositories/snapshots/"

To publish a release version, I would need the following code:
version = '1.0.5'
url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"

CodePudding user response:

It looks like you are encountering a common issue with publishing to Sonatype OSSRH. It seems that the error message you are seeing is due to a problem with the metadata file for your project.

One potential solution is to manually generate the metadata file for your project. You can do this by running the generateMetadataFileForMavenJavaPublication Gradle task. This will create a maven-metadata.xml file in the build/publications/mavenJava/ directory. You can then try publishing your project again and see if that resolves the issue.

You can also try disabling the Gradle offline mode and syncing your project. This may resolve the issue by allowing Gradle to fetch the necessary metadata from the remote repository.

If neither of these solutions work, you may want to try cleaning your local repository and rebuilding your project. This can be done by running the clean and build tasks in Gradle.

  • Related