trailblazer
trailblazer

Reputation: 1451

Upload a Zip file to nexus using gradle

I have a SpringBoot app and as a part of the build, I want to zip together the generated fat jar, and some directories conf and .sh scripts from my source. Then upload that zip file to nexus. I am not able to achieve that.

Following are the tasks I have in my build.gradle

task myzip(type: Zip) {
    doFirst {
        new File(buildDir, 'logs').mkdirs()
    }
    def fileName = "${jar.baseName}-${jar.version}"
    from projectDir into 'manager-service'
    include "conf/*"
    include "*.sh"
    exclude "conf/config-client"
    from buildDir into 'manager-service'
    include "logs/*"
    from file("$buildDir/libs")
    include "${fileName}.jar"
    archiveName "manager-service.zip"
}

myzip.dependsOn(bootRepackage)

artifacts {archives myzip}
build.dependsOn(myzip)

uploadArchives {
    repositories {
        apply plugin: 'maven'
        mavenDeployer {
            repository(url: System.getenv("NEXUSREPO")) {
                String username = System.getenv("NEXUS_SNAPSHOT_REPO_USERNAME");
                String password = System.getenv("NEXUS_SNAPSHOT_REPO_PASSWORD");
                print "foo"
                authentication(userName: username.toString(), password: password)
            }
        }
    }
}

but when I run the build, it fails with the following error:

Circular dependency between the following tasks:
:bootRepackage
\--- :myzip
     \--- :bootRepackage (*)

How can I resolve this?

Upvotes: 0

Views: 1136

Answers (1)

UnlikePluto
UnlikePluto

Reputation: 3379

With myzip.dependsOn(bootRepackage) your task "myZip" depends on the task "bootRepackage" which internally depends on the gradle tasks "assemble" and "build". This means "myZip" demands that "build", "assemble" and "bootRepackage" are executed first when you call "myZip".

build.dependsOn(myzip) means you make the task "build" depended on "myZip" to be executed in order to execute "build". This creates a loop.

To resolve this issue remove build.dependsOn(myzip) from your build.gradle file.

Upvotes: 1

Related Questions