Gradle : How to upload the Jar or War file to custom path in local machine

Points to Remember

  1. Default location for gradle dependencies is ~/.gradle or /home/{user}/.gradle.
  2. We can specify the location from where to gradle should find dependencies and where it should upload the created artifacts.

How to upload an Artifact to a custom location in file system

buildscript {
    repositories {
        maven {
            url uri("$buildDir/repo")
        }
    }
}

group 'com.ekiras'
version '1.0-SNAPSHOT'

apply plugin: 'groovy'
apply plugin: 'maven'

repositories {
    mavenCentral()
}

dependencies {
    // dependencies
}
uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: uri("$buildDir/repo"))
        }
    }
}

In the above example,

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: uri("$buildDir/repo"))
        }
    }
}

This tells gradle that it will upload the created artifact (jar or war ) to the directory build/repo. You can specify any location on your machine where you want gradle to upload the artifact.

buildscript {
    repositories {
        maven {
            url uri("$buildDir/repo")
        }
    }
}

The above code tells gradle that it should look for the given dependencies in this repository/directory we have specified to resolve the specified dependencies. You can also specify the same in repositories { } closure.

No comments :

Post a Comment