3

I'm new to Gradle and attempting to publish a simple project to Maven Central. My build.gradle script is nearly identical to the example in their documentation but my primary/compiled JAR is not being uploaded. Source JAR, Javadoc JAR, etc. are uploading fine but not the compiled one.

When publishing local via publishToMavenLocal everything works as expected. I'll note that I'm using version 6.0.1 and using publishMavenJavaPublicationToMavenRepository to publish to Central.

What am I missing? How can I get my compiled JARs to Central?

Update: I just realized that the POM isn't being uploaded either.

Here is the complete build.gradle:

plugins {
    id 'java-library'
    id 'maven-publish'
    id 'signing'
}

repositories {
    jcenter()
    mavenCentral()
}

dependencies {
    implementation 'com.squareup.okhttp3:okhttp:4.0.1'
    implementation 'com.squareup.moshi:moshi:1.9.1'
    implementation 'com.squareup.moshi:moshi-adapters:1.9.1'
    implementation 'com.google.guava:guava:28.0-jre'

    api 'org.apache.commons:commons-math3:3.6.1'

    testImplementation 'junit:junit:4.12'
}

group   = 'com.acme'
version = '0.0.1-SNAPSHOT'

ext.isReleaseVersion = !version.endsWith("SNAPSHOT")

java {
    withJavadocJar()
    withSourcesJar()
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            artifactId = 'thttpd'
            from components.java

            pom {
                name = 'thttpd'

                licenses {
                    license {
                        name = 'The MIT License (MIT)'
                        url = 'https://opensource.org/licenses/MIT'
                    }
                }

                scm {
                    connection = 'scm:git:https://acme.com'
                    developerConnection = 'scm:git:https://acme.com'
                    url = 'https://acme.com'
                }
            }
        }
    }

    repositories {
        // Maven Central
        maven {
            def releasesRepoUrl  = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
            def snapshotsRepoUrl = 'https://oss.sonatype.org/content/repositories/snapshots/'
            url = isReleaseVersion ? releasesRepoUrl : snapshotsRepoUrl
            credentials {
                username = nexusUsername
                password = nexusPassword
            }
        }
    }
}

signing {
    required { isReleaseVersion && gradle.taskGraph.hasTask("publish") }
    if( required ) {
        sign publishing.publications.mavenJava
    }
}
richid
  • 562
  • 3
  • 7
  • 22
  • I ended up downgrading to Gradle 5.6.3 (and modifying the build script accordingly) and everything started working. ¯\_(ツ)_/¯ – richid Nov 27 '19 at 02:50
  • I'm seeing the same issue with Gradle 6.6.1, removing `withSourcesJar()` doesn't help. – Alexis Oct 06 '20 at 12:39
  • Nevermind, in my case the files were correctly uploaded, but not all of them appear in the web UI of my repository for some reason. – Alexis Oct 06 '20 at 16:02

1 Answers1

1

I had the same issue that Alexis mentions above, on the GitHub Packages web UI the sources and java-doc where not showing up. But on s01.oss.sonatype.org I was able to see them. Using Gradle 6.7

Peter.K
  • 51
  • 2
  • 7