How to use a common build file as a dependency from a repository?

From the User Guide:

I would like my common build file, ‘other.gradle’ in a Maven repository and the build.gradle for the current project I am building to get the most current without having to make a code change to build.gradle.

So the url could be something like:
http://myhost:8081/repository/…/1.0/other-1.0.gradle or

I started to add a buildscript section to the build.gradle, but wasn’t sure how to use the dependency in the apply from.

I would be very grateful if someone could give me an example of how to use a common build file as a dependency from a repository.


Resolving the latest version of an external build script from a Maven repository is beyond the scope of the functionality mentioned in the user guide. That section is simply saying that you can also replace apply from: 'other.gradle' with a remote URL, i.e:

apply from: 'http://myhost:8081/other.gradle'

The expectation here is that you’re just uploading the file somewhere and can replace it as needed.

If you actually need to use a file published to a Maven repository conventionally (as opposed to just thinking that’s what you needed to do for the feature), the buildscript {...} isn’t particularly helpful as it is primarily designed to add binary plugins to the buildscript classpath. Instead, you should be able to use a detached configuration to resolve the latest version of other.gradle as a single file:

apply from: configurations.detachedConfiguration(dependencies.create('group:other:latest.release')).singleFile
1 Like

Thank you James. This works for me.