Publish a zip file to Nexus (Maven) with Gradle
Asked Answered
S

2

9

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

Subsistent answered 27/12, 2016 at 13:50 Comment(3)
Did you look into publishing file artifacts? docs.gradle.org/current/userguide/…Clover
Yes, jar files, but also zip, ocx, dll, ...Subsistent
The link i posted shows a txt file exampleClover
D
20

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
Discrepancy answered 28/12, 2016 at 6:45 Comment(2)
Thx, do you also have a best practice or example on how you differentiate between a snapshot and a release. We've seen that maven automatically takes care of this. Does Gradle also look at the artifact to be published? If it contains SNAPSHOT, then it should be published to the snapshots repository.Subsistent
Yop, this is also possible. But you have to specified that 'snapshot' repository in publishing.repositories {}, then create new publication inside publishing.publications {} with '-SNAPSHOT' attached to artifact's version number.Xanthic
T
1

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.

Taconite answered 24/9, 2020 at 19:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.