Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publish to Sonatype using NEW gradle plugin: maven-publish

So far I am uploading java artifacts to Sonar Nexus using the Gradle upload task; for example: https://github.com/oblac/jodd/blob/master/gradle/publish-maven.gradle

Recently I noticed that Gradle has new plugin maven-publish. I wanted to use it, as it seems it is going to be the main one for publishing. However, I am not being able to upload it to Nexus. So far, my file looks like this:

repositories {
    mavenCentral()
    jcenter()
}

apply plugin: 'java'
apply plugin: 'maven-publish'

group = 'com.foo'
version = 1.0

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile "...."
}

task sourceJar(type: Jar) {
    classifier = 'sources'
    from sourceSets.main.allJava
}
javadoc {
    failOnError = false
}
task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}
publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java

            artifact sourceJar
            artifact javadocJar
        }
    }
    repositories {
        maven {
            url "https://oss.sonatype.org/service/local/staging/deploy/maven2"
        }
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '3.4.1'
}

I guess I am missing something? I know I am missing signing, but that is not relevant for uploading. I am not being able to upload artifact using gradle publish.

Current error is:

Could not transfer artifact XXX from/to remote (https://oss.sonatype.org/service/local/staging/deploy/maven2): Could not write to resource 'XXX'.

EDIT

See final version: https://github.com/igr/repo-url-parser/blob/master/build.gradle

like image 657
igr Avatar asked Sep 11 '25 18:09

igr


1 Answers

I think you miss the authentication information and thus do not have the right to release to Sonatype OSS, as you try to deploy anonymously.

like image 52
Vampire Avatar answered Sep 13 '25 11:09

Vampire