Search code examples
gradledependency-managementbintray

How to use a Bintray user repo (correctly) for a dependency from gradle?


This is more of a 'am I doing it right' question.

Quick back story: I have built a gradle plugin (in a standalone gradle/groovy project). I am using it in a different java project. The client project was referring to it via something like:

buildScript
{
      flatDir {
            dirs '../my-gradle-plugin/build/libs'
      }

      classpath name: 'gradle-my-plugin'
}

So I didn't want the relative reference to the plugin project (nor make plugin part of the client). I thought I'd see if I can put it up in a BinTray and refer to like a 'real' plugin.

So set up BinTray and after much trial and error, I got it to work, but I don't think I did correct. Here is what I did:

  1. Made a maven repo: MyStuff
  2. Made a package: gradle-my-plugin
  3. Made a version: 0.1
  4. uploaded a file for that version, but specified a target path like "org/fhw/gradle-my-plugin/0.1"

My buildScript block looks like this:

buildScript {
    repositories {
        maven {
            url 'http://dl.bintray.com/my-bintray-id/MyStuff
        }
    }    
    dependencies {
        classpath 'org.fhw:gradle-my-plugin:0.1'
   }
}

So what I am curious about is the hack I did with the target on BinTray. W/O this, the proper path wasn't in place for uploaded files/jars (for a version).

So is this a correct, process for BinTray and Gradle dependencies?


Solution

  • What you did is OK, although using the official Bintray plugin could make your life much easier. It's getting better by the day, adding features and doing more and more work for you (e.g. it can lazily create a package and a version for you if they aren't exist).

    Another thing to consider is including your package to jcenter. One of the benefits of this inclusion will be a free account in oss.jfrog.org for your development process. It's a free Artifactory account (like nexus, but so much better).

    Please also note that you can include your plugin the Gradle plugins portal. Once you do that, the usage of your plugin is down to

    plugins {
      id "org.fhw.gradle-my-plugin" version "0.1"
    }
    

    Here are the inclusion instructions.

    P.S. Regarding the group id that nexus 'hides' - Bintray is not limited to Maven artifacts layout, you can deploy files in any layout that you need, that's why you need to provide the path when uploading files via the UI. Saying that, when Bintray encounters a pom file among the uploaded files, it sets up the path automatically. The path is also optional when using maven or maven-publish with the Bintray plugin - it calculates the path from artifacts once it's clear that those are Maven files.