MavenDeployer and proxy server

Hi, I need to upload jars to a nexus repository from a VM that must go through a proxy server. I can upload jars from a non-proxied machine with this gradle task:

//Upload Jar to Maven Repo (nexus)
uploadArchives {
repositories {
mavenDeployer {
repository(url: nexusRoot + “snapshots/”)
{
authentication(userName: rootProject.nexusUser , password: rootProject.nexusPassword)
}
pom.groupId = rootProject.group
pom.artifactId = project.name
pom.version = rootProject.version + “-SNAPSHOT”
}
}
}

But it fails on the proxied required Jenkins environment with:

FAILURE: Build failed with an exception.

What went wrong:
Execution failed for task ‘:utils:uploadArchives’.

Could not publish configuration ‘archives’
Failed to retrieve remote metadata :utils:1.0-SNAPSHOT/maven-metadata.xml: Could not transfer metadata :utils:1.0-SNAPSHOT/maven-metadata.xml from/to remote (https://nexus1.ci.whorocks.com/nexus/content/repositories/snapshots/): Connection to https://nexus1.ci.whorocks.com refused

We’ve tried:

  1. Supply JVM args/switches, -Dhttps.proxyHost and -Dhttps.proxyPort in the Jenkins gradle task. It’s ignored by MavenDeployer. Other unrelated tasks requiring external connections work.

  2. mavenDeployer {
    repository(url: nexusRoot + “snapshots/”)
    {
    proxyHost = System.getProperty(“https.proxyHost”)
    proxyPort = System.getProperty(“https.proxyPort”)
    println “proxyHost = " + proxyHost + " proxyPort=” + proxyPort
    authentication(userName: rootProject.nexusUser, password: rootProject.nexusPassword)
    proxy(host: proxyHost, port: Integer.valueOf(proxyPort))
    }

  3. And this:

//Upload Jar to Maven Repo (nexus)
uploadArchives {
repositories {
mavenDeployer {
repository(url: nexusRoot + “snapshots/”) {
authentication(userName: rootProject.nexusUser, password: rootProject.nexusPassword)
releases()
snapshots()
proxy()
}
pom.groupId = rootProject.group
pom.artifactId = project.name
pom.version = rootProject.version + “-SNAPSHOT”
}
}
}
}

All with the same error. We’ve run a netstat on the Jenkins slave and can see the request attempt to go directly to the nexus repo, not the proxy server. Proxy args are ignored.

Any thoughts? Appreciate it.

Got this (thanks to a colleague that read the fine print by someone else with a similar issue). The magic is supplying ‘type’:

proxy(host: “myproxyserver.net”, port: 80, type: ‘http’)

So,

mavenDeployer {
repository(url: nexusRoot + “snapshots/”)
{
authentication(userName: rootProject.nexusUser, password: rootProject.nexusPassword)
proxy(host: “myproxyserver.net”, port: 80, type: ‘http’)
}
pom.groupId = rootProject.group
pom.artifactId = project.name
pom.version = rootProject.version + “-SNAPSHOT”
}

Shershon, You are Awesome. That worked for me too. I found this solution no where. Grade should update its documentation – Adding a proxy host details to “mavenDeployer”. When it comes to publish/upload artifact to remote repository, the default proxy configuration in gradle.properties wouldn’t work for mavenDeployer plugin. Explicitly using “proxy(host: “myproxyserver.net”, port: 80, type: ‘http’)” is working.