A project can have dynamic properties. In subprojects you can refer to the
root project by using the rootProject property. So you could do something
like

    // in the root project:
    setProperty('module', module);

    // in a subproject:
    def module = rootProject.property('module')

You could use a method in the root project too, of course.

  Levi

On Fri, Feb 27, 2009 at 4:35 PM, <[email protected]> wrote:

>  I have another question regarding multiple project shared dependencies. I
> want to create a ClientModule, that I can refer to in some given
> sub-projects. Maybe I'm not familiar enough with Groovy, but that's how I
> would do (outside dependencies declaration, in root gradle.build):
>
> myModule = new ClientModule(id: 'moduleID')
>   .clientModule("compile", "eu.sanco:saas:1.1.5") {
>    dependency("org.springframework:spring-hibernate3:2.0.8") {
>     exclude(module: "ehcache")
>    }
>   }
>
> But now in the sub-project dependencies, I don't see how I could use this
> ClientModule. Looking at DependencyContainer API, I see no method to add
> directly a ClientModule object, only adding one by creating it. Is there a
> way to "register" my module in root build script, to make it available to
> all sub-scripts?
>
> Hope this is clear enough :o)
>
>  ------------------------------
> *From:* [email protected] [mailto:
> [email protected]]
> *Sent:* Tuesday, February 24, 2009 11:09 AM
> *To:* [email protected]
> *Subject:* RE: [gradle-user] Multiple project dependency management
>
>  Thank you, it does the trick. I thought I tried that option before,
> obviously not hard enough :)
> Anyway, looking forward for a more 'gradely' way to do so.
>
>  ------------------------------
> *From:* Adam Murdoch [mailto:[email protected]]
> *Sent:* Monday, February 23, 2009 7:34 PM
> *To:* [email protected]
> *Subject:* Re: [gradle-user] Multiple project dependency management
>
>
>
> [email protected] wrote:
>
> Hi all,
>
> After reading the documentation, I have a hard time understanding multiple
> projects dependency. My requirement is quite simple. I'm still used to
> Maven, and I try to reproduce features that seem the most interesting to me.
>
> Here's my problem. I have a multiple java project environment, with one
> project depending on the other. For some obvious reason, the 2 projects
> depend on one same library. I thus need to add the same dependency to both
> projects, but I don't want to add this dependency globally (for ALL
> projects). How can I make sure that the same library is used by both
> projects, i.e. the version is the same? With Maven, it was quite easy, just
> declare all libraries and versions required in the parent pom, and simply
> declare the name of the library you want to use in the appropriate
> sub-projects. Thus, if you want to upgrade a library, just change the
> version in parent pom, the rest will follow.
>
> What is the most convenient way to do so with Gradle? I keep on reading
> chapter 14, but can't really find what I'm looking for.
>
>
> Currently, there's no built-in way to do this, though we do plan to add it.
>
> In the meantime, there are plenty of options for doing this using groovy.
> For example, you could have a map of library name -> dependency definitions
> in the root project, and use this from the each project:
>
> root project build.gradle
>
> libraries = [ 'someLib': 'org:someLib:1.2', 'otherLib':
> 'other-org:otherLib:3.+' ]
>
> project1 build.gradle
>
> dependencies {
>     compile libraries.someLib
> }
>
> project2 build.gradle
>
> dependencies {
>     compile libraries.someLib, libraries.otherLib
> }
>
> Then, to upgrade a library, you change the contents of the map (ie a single
> place)
>
>  Thanks for your help, and sorry if my question is clearly stated in the
> user guide.
>
> Erwan
>
>

Reply via email to