Pull project artifacts from maven repo

(Ketan Padegaonkar) #1


We have a huge maven project that we’re migrating over to gradle (yay!).

However we’re missing out on one interesting maven feature(?) that allows us to get our builds to run faster on CI servers. Currently we have a several stage pipeline, the first stage of which builds all maven artifacts and publishes it into a repository. Subsequent stages in the pipeline don’t need to build all maven sub-modules because it’s able to resolve them from the repository (published out of the first stage).

Is there a way to achieve this using gradle. Ideally what we’d want is for gradle to figure out that project(':foo') is really com.example:foo:1.0 and resolve it out of the maven repository instead of having to build foo along with its transitive dependencies.

Is there any way to speed up such multi-project builds on a fairly large deployment pipeline?


(Lance Java) #2

Using the current gradle version, you can solve this with a custom ResolutionStrategy

def isCi = System.properties['ci'] == "true"
if (isCi) {
   configurations.all {
      resolutionStrategy {
         dependencySubstitution {
            substitute project(':foo') with module('mycompany:foo:1.2.3')

There’s a new composite build feature coming to gradle soon. This may also help in future

(Ketan Padegaonkar) #3

Thank you, this is neat and works for the most part.

I can’t seem to figure out how I can use it for dependencies that read like the following:

#project com.example:webapp

configurations {

dependencies {
  funkyWidgetModel project(path: ':funkyWidgetModel', configuration: 'fatJarConfig')

I keep getting errors like —

* What went wrong:
A problem occurred evaluating script.
> Could not resolve all dependencies for configuration ':webapp:funkyWidgetModel'.
   > Module version com.example:webapp:16.5.0-22113, configuration 'funkyWidgetModel' declares a dependency on configuration 'fatJarConfig' which is not declared in the module descriptor for com.example:funkyWidgetModel:16.5.0-22113

Thank you again for your help

(Lance Java) #4

AFAIK this configuration isn’t published to the maven repo so only works for local projects.

A few options:

  1. Refactor the configuration to a shared variable in the parent project as suggested in option 1 here

  2. Extract the configuration to a shared project which is always a local project in every build (including CI)

  3. Write the configuration dependencies to a text/json/xml file which is published to maven and downloaded/deserialized for the CI build.