Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publish a zip file to Nexus (Maven) with Gradle

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).

like image 308
Lieven Cardoen Avatar asked Dec 27 '16 13:12

Lieven Cardoen


2 Answers

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
like image 70
Vyacheslav Shvets Avatar answered Oct 12 '22 01:10

Vyacheslav Shvets


If you're using Kotlin DSL, declare the artifact as show below:

artifact(tasks.distZip.get())

where distZip is the task that produces the zip file, which in the above example, is from the application plugin.

like image 45
Abhijit Sarkar Avatar answered Oct 12 '22 02:10

Abhijit Sarkar