Issue
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
Solution
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.
Answered By - Vampire
Answer Checked By - Candace Johnson (JavaFixing Volunteer)