Home > Enterprise >  not able to publish sources with Gradle
not able to publish sources with Gradle

Time:09-30

I am using Gradle 7.4.2 to build and deploy a Java library on our internal Nexus. It works well, but in addition to the binaries, I would like now to publish the sources and javadoc artifacts, and I am not able to find the right config.

Here's what I have so far :

  artifacts {
    archives jar
    archives sourceJar
  }

  publishing {
    publications {
      mavenJar(MavenPublication) {
        groupId "my-org.libraries.custom-file-upload"
        artifactId archivesBaseName
        version version
        from components.java
      }
    }
    
    ...
  }

CodePudding user response:

OK, it works now, here's what I have : we need to explicitly declare the artifacts in the publication.

  java {
    withJavadocJar()
    withSourcesJar()
  }

  
  task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier "javadoc"
    from javadoc.destinationDir
  }

  artifacts {
    archives jar
    archives sourceJar
    archives javadocJar
  }

  publishing {
    publications {
      mavenJava(MavenPublication) {
        groupId "de.gefa.libraries.blueline-file-upload"
        artifactId archivesBaseName
        version version
        from components.java
        artifact(sourceJar)
        artifact(javadocJar)
      }
    }
    ...
  }
  • Related