Publish a ZIP file generated by distZip to a Maven repository

hi all!

I have a ZIP file produced by distZip command. what’s the easiest way to upload it to a Maven/Nexus repository? how do I reference that zip file in the “artifacts” section?

I tried this

publishing {
    publications {
        pdZipPublication(MavenPublication) {
            artifact "launcher/build/distributions/my.zip"
        }
    }
    repositories {
        maven {
            url "http://nexus:8081/nexus/content/repositories/snapshots"
            credentials {
                username "deploy"
                // provide "pdDeployPassword" in your <home>/.gradle/gradle.properties file.
                // example: "pdDeployPassword=abc", etc.
                password pdDeployPassword
            }
        }
/*
      maven {
             url "http://nexus:8081/nexus/content/repositories/releases"
             credentials {
                 username "deploy"
                 password pdDeployPassword
             }
         }*/
    }
}

there are several problems with this: 1) can’t provide both snapshots and releases repository. the plugin tried uploading to BOTH releases and snapshots if I uncomment the piece above. 2) I have to reference the ZIP file produced by distZip task in “launcher” subproject by name instead of doing something like “artifact launcher.distZip.archiveName” - because that gave some weird error messages. 3) everyone has to have this home/.gradle/gradle.properties file with “pdDeployPassword” setting in it even if they only run “distZip” and run “publish”, otherwise they’ll get

Could not find property ‘pdDeployPassword’ on Credentials [username: pd-deploy].

1 Like

Did you ever figure this out? I’m trying to do the same thing…

snapshots and released problem (item 1) can be solved with:

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'maven-publish'
  group = 'com.company.sample'
version = '0.1-SNAPSHOT'
  sourceCompatibility = 1.6
targetCompatibility = 1.6
  ext {
    artifactRepoBase = "http://nexus:8081/nexus/content/repositories"
}
  // password can be set in gradle.properties or environment variable (check "build environment" on Jenkins)
// uncomment this for proper security implementation:
//
def deployPassword = hasProperty("DEPLOY_PASSWORD") ? DEPLOY_PASSWORD : ""
def deployPassword = "321321321"
  // see http://www.gradle.org/docs/current/userguide/publishing_maven.html
publishing {
    // where to publish to
    repositories {
        maven {
            url "${artifactRepoBase}/${project.version.endsWith('-SNAPSHOT') ? 'snapshots' : 'releases' }"
            credentials {
                username "sample-deploy"
                password deployPassword
            }
        }
    }
    // what to publish. feel free to add sources, javadocs and custom artifacts (like ZIP files)
    publications {
          mavenJava(MavenPublication) {
            // publish the main jar file with classes
            from components.java
              // publish the jar file with sources
            artifact sourceJar {
                classifier "sources"
            }
              // publish javadoc jar
            artifact packageJavadoc
        }
      }
}
  task sourceJar(type: Jar) {
    from sourceSets.main.allJava
}
  task packageJavadoc(type: Jar, dependsOn: 'javadoc') {
    from javadoc.destinationDir
    classifier = 'javadoc'
}

problem 2 - ZIP file reference - is not solved, it’s not a big deat.

This is the part of my

build.gradle

that configures that the output of

distZip

should be published:

artifacts { archives distZip }
  // Define what should be published
publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
            artifact javadocJar
            artifact sourceJar
            artifact distZip
        }
    }
}