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:
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?
The location for storing modules is called a repository. By specifying the repositories for a project, Gradle can find and retrieve modules. Repositories can be in different forms, such as a local directory or a remote repository.
flatDir(configureClosure) Adds an configures a repository which will look for dependencies in a number of local directories. flatDir(args) Adds a resolver that looks into a number of directories for artifacts. The artifacts are expected to be located in the root of the specified directories.
The dependencyResolutionManagement repositories block accepts the same notations as in a project, which includes Maven or Ivy repositories, with or without credentials, etc. By default, repositories declared by a project will override whatever is declared in settings.
Using gradlePluginPortal() allows you to resolve any plugin in the buildscript { } block that is published to the Plugin Portal or JCenter(or Maven Central) without caring where it was published or defining multiple repositories.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With