7

I am writing Gradle scripts to build a lot of projects. They are using the same repositories so I would like to define repositories for all of my sub-projects instead of defining in each of them. So I try to move the repositories definition from the build.gradle in an individual project into the build.gradle in their parent folder.

subprojects{
    repositories{
        mavenCentral()
        flatDir{
            name 'uploadRepository'
            dirs '../../sharedlib'
        }
    }
}

However, the sub-projects can't find the repository definition at all. Moving other configurations in subprojects closure work. I've tried dependencies and properties configuration. They all work with no problem. I don't know why repositories work differently. When Googling, I can't find any example of putting repositories inside subprojects, I suspect I am doing it the wrong way. Please tell me what's wrong. Thanks!

user1695166
  • 621
  • 7
  • 9
  • "However, the sub-projects can't find the repository definition at all." How can you tell? Which exact effect are you seeing (which task fails, what's the error message, etc.)? – Peter Niederwieser May 08 '13 at 16:32
  • It is complaining with the following error messages: * Where: Build file 'F:\build_scripts\temp\build_standardization\experiments\portlets\TFANetRegions\build.gradle' line: 69 * What went wrong: A problem occurred evaluating root project 'TFANetRegions'. > Could not find property 'uploadRepository' on repository container. – user1695166 May 08 '13 at 19:56
  • I put the settings.gradle in the parent project which include my subproject. This makes Gradle able to find the repositories. However, now it can't find the dependencies and properties setting (sourceCompatibility=1.5). This wasn't a problem when settings.gradle wasn't there. Now I am confused what the settings.gradle actually does. – user1695166 May 08 '13 at 20:00
  • Check out the multi-project builds chapter in the [Gradle User Guide](http://gradle.org/docs/current/userguide/userguide_single.html). – Peter Niederwieser May 08 '13 at 20:32

2 Answers2

1

I finally figured out what the problem was. Originally, I missed the settings.gradle in the parent folder. (I don't know why dependencies configuration works even without this file) After I put that in, the sub-projects could find the repositories, but the dependencies and an one property (sourceCompatibility=1.5) I defined in the parent project no longer works. I have to move the apply plugin:'war' from the subproject's build.gradle to the parent's subprojects{...} I figure that's because the dependencies and sourceCompatibility are things provided by the plugin. And somehow Gradle doesn't look into the subproject's script to find the plugin first.

user1695166
  • 621
  • 7
  • 9
0

Your repository declarations look fine, except that an upload repository isn't declared in the project.repositories block but inside the upload task (e.g. uploadArchives). The Gradle User Guide has the details.

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259