On 27/02/10 4:01 AM, Gregory Boissinot wrote:
I use lots of the 'buildscript' section in my Gradle scripts.

However, my Gradle scripts often use the same elements of the buildscript
classpath (plugins, common jar) and I would like to  externalize the'
builscript' section in a common Gradle script (called for example
'common.gradle') and use the apply url element with the 'common.gradle' as
value in the target Gradle build script.

Regarding my tests, that doesn't work.


Example

In 'common.gradle':
buildscript {
   repositories {
    flatDir dirs: '.'
   }
   dependencies {
    classpath ':myjar:1.0'
   }
}
(and myjar has a main class com.example.App)

In a target Gradle script:

apply url:'common.gradle'
task test {
  println com.example.App.main(new String[0])
}

I think is quite difficult because the 'buildscript' section is evaluated
before the script evaluation (with the 'apply url' element).

Any suggestions?

You need to move the buildscript { } closure from the common script to the target scripts. For example:

// target.gradle
buildscript {
    apply url: 'common.gradle'
}

// common.gradle
repositories { ... }

Alternatively, you could leave the buildscript closure in the common script and inject it from the root project:

// root.gradle
subprojects { apply url: 'common.gradle' }

// common.gradle
buildscript {
    repositories { ... }
}

There would be other options depending on why you're using buildscript { }. What sort of things do you need it for?


--
Adam Murdoch
Gradle Developer
http://www.gradle.org


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply via email to