400 error on sample code

not-a-bug

(Patrick Gibbons) #1

I’m new to publishing and took sample code from the web as an experiment, using the OSS version of nexus, I touch 3 files in the ‘/root’ directory of my docker container and use the following json to describe the desired maven format:

{
“libs”: [
{
“cfgName”: “uploadInternal1”
, “groupId”: “com.prot.zbank.client”
, “artifactId”: “client-model”
, “version”: “0.0.8”
, “jarLocation”: “client/client-model.jar”
}
, {
“cfgName”: “uploadInternal2”
, “groupId”: “com.prot.zbank.client”
, “artifactId”: “client-model”
, “classifier”: “test”
, “version”: “0.0.8”
, “jarLocation”: “client/unit-test.jar”
}
, {
“cfgName”: “uploadInternal3”
, “groupId”: “com.prot.zbank.client”
, “artifactId”: “client-model”
, “version”: “0.0.8”
, “jarLocation”: “client/rest-api.jar”
}

]
, "repoUrl": "http://localhost:8081/nexus/content/repositories/snapshots/"
, "repoUser": "admin"
, "repoPswd": "admin123"

}

Using the following code (slightly modified, to make it simplier):

apply plugin: ‘maven’
def f = file(“upload-list.json”)
def m = f.exists() ? new groovy.json.JsonSlurper().parse(f) : null
task batchUpload() {
}
if (m == null || m.libs == null || m.libs.isEmpty()) {
batchUpload.doLast {
println “WARNING: no file to upload”
}
} else {
m.libs.each { lib ->
configurations.create( “${lib.cfgName}” )
if (lib.classifier == null) {
artifacts.add("${lib.cfgName}", file("${lib.jarLocation}"))
} else {
artifacts.add("${lib.cfgName}", file("${lib.jarLocation}")) {
setClassifier( “${lib.classifier}” )
}
}

    def repoUrl =  'http://localhost:8081/nexus/content/repositories/snapshots/';
    def repoUser = 'admin';
    def repoPswd = 'admin123'; 
    def classifier = lib.classifier == null ? "" : ("-" + lib.classifier)
    println "define task '${lib.cfgName}' to upload ${lib.jarLocation} to ${repoUrl} as ${lib.groupId}:${lib.artifactId}-${lib.version}${classifier}.jar"
    project.tasks.create("${lib.cfgName}", Upload.class) {
        configuration = configurations[lib.cfgName]
        repositories {
            mavenDeployer {
                repository(url: "${repoUrl}") {
                    authentication(userName: "${repoUser}", password: "${repoPswd}")
                }
                pom.version = "${lib.version}"
                pom.artifactId = "${lib.artifactId}"
                pom.groupId = "${lib.groupId}"
            }
        }
    }
    batchUpload.dependsOn "${lib.cfgName}"
}

}

I’m getting a 400 “bad request” error. I’ve successfully published using other code, so the gradle container can get through to the nexus OSS container, that’s not the issue. As I’m publishing to ‘snapshot’ and ‘snapshot’ is empty, I don’t see the reason why the above isn’t publishing, any suggestions are appreciated.