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

Tom Bascom
  • 13,405
  • 2
  • 27
  • 33
Lieven Cardoen
  • 25,140
  • 52
  • 153
  • 244

2 Answers2

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
Vyacheslav Shvets
  • 1,735
  • 14
  • 23
  • 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. – Lieven Cardoen Dec 29 '16 at 07:41
  • 1
    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. – franta kocourek Jul 13 '17 at 05:12
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.

Abhijit Sarkar
  • 21,927
  • 20
  • 110
  • 219