2

I have a multi-project build with the following structure:

Root project 'just-another-root-project'
+--- Project ':producer'
\--- Project ':consumer'

The root settings.gradle file:

rootProject.name = 'just-another-root-project'
include 'consumer', 'producer'

...connects created modules.


The producer.gradle file:

plugins {
    id 'java-library'
}

group 'com.github.yarbshk.jarp'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
    maven {
        url 'http://maven.nuiton.org/release/'
    }
}

dependencies {
    implementation 'com.sun:tools:1.7.0.13'
}

...has an external dependency (com.sun.tools) that is not published in Maven Central therefore I've added a link to the Nuiton repository.


The consumer.gradle file:

plugins {
    id 'java'
}

group 'com.github.yarbshk.jarp'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    annotationProcessor project(':producer')
}

The build described above is not working! To make it so I was enforced to duplicate all repositories from producer.gradle into consumer.gradle. So the question is how to build the root project without the excessive dependency duplication? How to do it in the right way? Thanks for any answer or hint :)


UPDATE 1:

I get the following error when try to build the project with files shown above:

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all files for configuration ':consumer:compile'.
> Could not find com.sun:tools:1.7.0.13.
  Searched in the following locations:
      https://repo.maven.apache.org/maven2/com/sun/tools/1.7.0.13/tools-1.7.0.13.pom
      https://repo.maven.apache.org/maven2/com/sun/tools/1.7.0.13/tools-1.7.0.13.jar
  Required by:
      project :consumer > project :producer
Yurii Rabeshko
  • 591
  • 8
  • 17

2 Answers2

1

You can configure repositories directly in the root project like that:

root project build.gradle:

// configure repositories for all projects
allprojects {
    repositories {
        mavenCentral()
        maven {
            url 'http://maven.nuiton.org/release/'
        }
    }
}

EDIT (from you comment on other response)

You can also define only mavenCentral() repository on root project level (it will be added to repositories for all projects) and configure http://maven.nuiton.org/release repository only for producer subproject :

root project

repositories {
    // will apply to all project
    mavenCentral()
}

producer project

 repositories {
    maven {
        url 'http://maven.nuiton.org/release/'
    }
    // mavenCentral inherited from root project
}

consumer project

// no need to re-define repositories here.
M.Ricciuti
  • 11,070
  • 2
  • 34
  • 54
  • thanks for the answer @M.Ricciuti .. i thought that solution should work as well but i got the error (please see update 1 to the question) – Yurii Rabeshko Sep 22 '18 at 07:58
  • 1
    i created a simple project with same configuration as given in your quetion, and did not reproduce your problem. but if I change dependency type from `implementation` to `compile` in the *producer* build script, then I get exactly the same error as the one you described in **update 1** : maybe there are differences between the code in your project script and the scripts you gave in this question? by the way: which Gradle version are you using ? – M.Ricciuti Sep 22 '18 at 10:41
  • So strange behaviour... In my case, it's not working for both `implementation` and `compile` therefore it needs to test more detail (create a project from scratch in the same way as you did it in spite of I have copy pasted the configuration literally). I'll make it on Monday morning and then reply you again because I don't have the computer near me now. **The current Gradle version I used is 4.6** – Yurii Rabeshko Sep 22 '18 at 20:46
0

There is a section in an official gradle tutorial dedicated to this: https://guides.gradle.org/creating-multi-project-builds/#configure_from_above

The root project can configure all projects:

allprojects {
    repositories {
        jcenter() 
    }
}
eekboom
  • 5,551
  • 1
  • 30
  • 39
  • thank you @StephenFriedrich for a quick answer. i know how to configure children projects from a parent one but can i keep specific configuration in a child project (for example the `repositories` property) without modifying parent one (as shown in the `consumer.gradle` file above)? – Yurii Rabeshko Sep 21 '18 at 13:51