Deploy a Jar file to remote server(ssh) dependson gradle build Success/failure

I have a multi-module gradle project setup.when i do gradle build in root dir it will build all the modules in it.

1.)I need to deploy the Jar files(subproject.jar) for every module to remote server if gradle build is success for the module.

2.)If the build fails for a particular module deployment should not happen.

–Root Dir
–Build.gradle
–settings.gradle
–Project A
–Build.gradle
–Project B
–Build.gradle
–Project c
–Build.gradle

Thanks in Advance!

What do you mean by deploy? Copy via SSH / FTP etc. ?

Thanks for your prompt reply.
Copying jar files to remote server using ssh if the gradle build is success for the module.

Is it the problem with copying files with ssh/scp? If so, you can give these plugin a try: https://github.com/aestasit/sshoogr-gradle and https://github.com/ysb33r/groovy-vfs

Regarding uploading jars only when all subproject builds are successful, one option could be to declare an upload task in root project that has dependency on all subproject’s build tasks and takes the generated artifacts from each project and uploads.

I don’t have any problem while copying files with ssh/scp. But i need an help to copy a Jar file from ($build/lib/*.jar) to remote server if the build is success.
For eg I have three Projects(A:B:C)
if gradle build fails for Project(B), then I have to copy Project(A:C) jar to remote server…

Any Idea how we can achieve this…

Thanks for your response.

:flushed:

Well, if you must then try the following. run your build with ./gradlew --continue which will allow it to continue after failure.

Then assuming you have a copyRemote task in each project.

copyRemote {
  // Only run if build task did not fail
  onlyIf { tasks.build.state == null }
}

I need to copy(subprojects.jar) task only in root dir(build.gradle). I don’t want to define the task in each project.I need to have globally only in root buld.gradle.

Any idea how we can achieve this…

The below is my copy Jar script

task copyJars(type: Copy, dependsOn: subprojects.jar) {
onlyIf { tasks.build.state == null }
from(subprojects.jar)
into project.file(‘dest’)
}
how i can integrate the above code to remote server ssh operation.My destination will be remote server.