gradle publish: Usage & Common CI Errors
Upload artifacts to your remote repositories via maven-publish.
publish is the task added by the maven-publish (or ivy-publish) plugin that uploads all defined publications to all defined repositories. It is Gradle’s equivalent of mvn deploy.
What it does
publish runs every publish<Pub>PublicationTo<Repo>Repository task generated from the publishing { publications {} repositories {} } block. publishToMavenLocal installs to ~/.m2 instead, which is useful for local integration testing.
Common usage
./gradlew publish
./gradlew publishToMavenLocal
./gradlew publishMavenJavaPublicationToInternalRepositoryCommon error in CI (and the fix)
Symptom: "Could not PUT 'https://repo.example.com/.../app-1.0.jar'. Received status code 401 from server: Unauthorized." Cause: the publishing repository has no credentials or the wrong ones. Fix: supply credentials in the repositories block (credentials { username = …; password = … }) sourced from CI secrets / Gradle properties, and confirm the repository URL distinguishes snapshots vs releases to match the version.