Showing posts with label gradle. Show all posts
Showing posts with label gradle. Show all posts

Friday, October 5, 2018

Gradle: Publish artifacts to maven repo (nexus) - an working example

Refer my github repo https://github.com/siddeshbg/gradle-uploadArchives for a working  demonstration of Gradle way of publishing artifacts to Maven repos (both local and Nexus).

The README.md has a detailed description of how it works

Wednesday, February 22, 2017

Simple Gradle file to just download dependencies

If you are managing repositories like Nexus or Artifactory, you often receive complaints from developers that, there dependency is not getting downloaded, though it is present in Nexus/Artifactory. Particularly if you are hosting a local mirror repository (for example for local India developers), then they will doubt on mirror caching as well. But you can always browse the artefacts at there expected paths in Nexus/Artifactory and if it is found there and still developer complains that it is not getting downloaded, then you need to troubleshoot either issue with Gradle or Maven config file or could be network issue as well.

In this blog post, I'm just posting simple Gradle file to just download a dependency, which will help us to debug download issues.

Where Gradle stores artifacts locally on our machine?

Typically at $HOME/.gradle/caches/modules-2/files-2.1/<GROUP-ID>/<ARTIFACT-ID>/<VERSION>

Simple Gradle file to download dependencies

$ cat build.gradle 
apply plugin: 'java'

repositories {
   //The properties nexusMavenRepos, localNexusBaseUrl, etc will be defined gradle.properties file as shown in the end
   nexusMavenRepos.split().each { repo ->
            maven { url(localNexusBaseUrl + repo) }
        }
}

//Below code contacts external maven central repo. comment it, if you don't want to go external
repositories {
    mavenCentral()
}

dependencies {
    testCompile 'junit:junit:4.8.2'
    compile 'commons-beanutils:commons-beanutils:1.8.3'
    testCompile group: 'com.typesafe.akka', name: 'akka-http-core_2.11', version: '2.4.4'
}

Then run gradle dependencies task

$ gradle dependencies 

or


$ gradle dependencies --refresh-dependencies    #In case if you want to force gradle to download

This will download the requested artefacts under $HOME/.gradle/caches/modules-2/files-2.1/ 

// typical gradle.properties file for reference
$ cat gradle.properties
nexusBaseUrl = https://my-org-nexus/nexus/content/repositories/
localNexusBaseUrl = https://my-org-blr-nexus/nexus/content/repositories/
nexusMavenRepos = central my-org-third-party-lib