Release plugin + publish - not publishing released artifacts

I’m trying to set up two projects with Gradle to perform releases and publish the results to a Nexus repository server. Both are failing with a similar problem - the release step is working, and the “SNAPSHOT” version is replaced by the released version, and committed and pushed to git, but the publish step is not doing anything / not running.

The setup I’m trying to achieve is:

  • Local (snapshot) builds should be published to local Maven cache.
  • Release (CI) builds should be published to our Nexus repository server.

My build.gradle:

plugins {
  id 'java'
  id 'net.researchgate.release' version '2.8.1'
  id 'maven-publish'
}

group 'com.something'

repositories {
  mavenLocal()
  mavenCentral()
  maven {
      url = uri('http://nexus:8080/repository/myrepo/')
      allowInsecureProtocol = true
  }
}

java {
  withSourcesJar()
}

publishing {
  publications {
    maven(MavenPublication) {
        from components.java
    }
  }
}

// publish every build to local maven, to enable local testing
publishToMavenLocal.dependsOn(check)
build.dependsOn(publishToMavenLocal)
// publish release builds to Nexus
afterReleaseBuild.dependsOn publish

Sample log output:

Task :release
Task :CPA-GJAP-JOB1:CPA-GJAP-JOB1:check
Task :CPA-GJAP-JOB1:CPA-GJAP-JOB1:generateMetadataFileForMavenPublication
Task :CPA-GJAP-JOB1:CPA-GJAP-JOB1:generatePomFileForMavenPublication
Task :CPA-GJAP-JOB1:CPA-GJAP-JOB1:publishMavenPublicationToMavenLocal
Task :CPA-GJAP-JOB1:CPA-GJAP-JOB1:publishToMavenLocal
Task :CPA-GJAP-JOB1:CPA-GJAP-JOB1:build
Task :CPA-GJAP-JOB1:CPA-GJAP-JOB1:publish UP-TO-DATE
Task :CPA-GJAP-JOB1:CPA-GJAP-JOB1:afterReleaseBuild UP-TO-DATE
Task :CPA-GJAP-JOB1:runBuildTasks
Task :CPA-GJAP-JOB1:preTagCommit
Task :CPA-GJAP-JOB1:createReleaseTag
Task :CPA-GJAP-JOB1:checkoutMergeFromReleaseBranch SKIPPED
Task :CPA-GJAP-JOB1:updateVersion
Task :CPA-GJAP-JOB1:commitNewVersion
Task :compileJava UP-TO-DATE
Task :processResources NO-SOURCE
Task :classes UP-TO-DATE
Task :jar
Task :sourcesJar
Task :assemble
Task :compileTestJava UP-TO-DATE
Task :processTestResources UP-TO-DATE
Task :testClasses UP-TO-DATE
Task :test UP-TO-DATE
Task :check UP-TO-DATE
Task :generateMetadataFileForMavenPublication
Task :generatePomFileForMavenPublication
Task :publishMavenPublicationToMavenLocal
Task :publishToMavenLocal
Task :build

The publish task appears to show as UP-TO-DATE. What am I missing?

Gradle version: 7.4

The publish task is a lifecycle task. It typically does not do any action itself, it is just there to depend on the publish<publication>To<repository>Repository tasks. The problem is, that you defined a publication, but no repositories where to publish to, so there are no according tasks created and wired to the publish task.

Thanks for replying. I’m confused though. I thought that the publish plugin would automatically create a task for each repository in my list. Is that not right? If not, how do i configure it to create a task to publish to my main maven repo? In this case our Nexus repository server.

It does, but not for the repositories you configured for dependency resolution. The repositories for publication are separately defined in the publishing block. Have a look at the documentation of the maven-publish plugin.

Ahhh… I had not noticed the repositories for publication are inside the publishing block! I will make that change, and add the logic to choose release or snapshot url. Thanks for all the help.

1 Like