Publish a zip file to Nexus (Maven) with Gradle

Lieven Cardoen picture Lieven Cardoen · Dec 27, 2016 · Viewed 11.2k times · Source

Say you have a PL file you want to upload to Nexus with Gradle. How would such a script look like.

group 'be.mips' version = '1.4.0-SNAPSHOT'

In settings.gradle --> rootProject.name = 'stomp'

And let's say that the pl file is in a subdirectory dist (./dist/stomp.pl).

Now I want to publish this stomp.pl file to a nexus snapshot repository.

As long as you go with Java, then Gradle (just like Maven) works like a charm. But there's little documentation found what to do if you have a DLL, or a ZIP, or a PL (Progress Library).

Answer

Vyacheslav Shvets picture Vyacheslav Shvets · Dec 28, 2016

I publish such artifacts for a long time. For example, ZIP archives with SQL files. Let me give you an example from real project:

build.gradle:

apply plugin: "base"
apply plugin: "maven"
apply plugin: "maven-publish"

repositories {
    maven { url defaultRepository }
}

task assembleArtifact(type: Zip, group: 'DB') {
    archiveName 'db.zip'
    destinationDir file("$buildDir/libs/")
    from "src/main/sql"
    description "Assemble archive $archiveName into ${relativePath(destinationDir)}"
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            artifact source: assembleArtifact, extension: 'zip'
        }
    }
    repositories {
        maven {
            credentials {
                username nexusUsername
                password nexusPassword
            }
            url nexusRepo
        }
    }
}

assemble.dependsOn assembleArtifact
   build.dependsOn assemble
 publish.dependsOn build

gradle.properties:

# Maven repository for publishing artifacts
nexusRepo=http://privatenexus/content/repositories/releases
nexusUsername=admin_user
nexusPassword=admin_password

# Maven repository for resolving artifacts
defaultRepository=http://privatenexus/content/groups/public

# Maven coordinates
group=demo.group.db
version=SNAPSHOT