On 15/03/2011, at 8:39 AM, Benjamin Muschko wrote:
> Hi,
>
> I am trying to add a classpath dependency in a custom plugin instead of
> defining it in my build script like this.:
>
> buildscript {
> repositories {
> mavenCentral()
> }
>
> dependencies {
> classpath 'commons-lang:commons-lang:2.5', <--- shows an example of a
> JAR I want to move into the plugin
> 'somegroup:myplugin:0.1'
> }
> }
>
> The classes of the dependency are being used by the plugin itself. What's
> the best way to do this?
The simplest option is to declare it as a runtime dependency of the plugin,
just as you would for a regular jar. That is, in the build for your plugin:
dependencies {
runtime 'commons-lang:commons-lang:2.5' // could be a compile dependency
}
Then, where you use the plugin:
buildscript {
repositories { ... }
dependencies {
classpath 'somegroup:myplugin:0.1'
}
}
All transitive runtime dependencies of 'somegroup:myplugin:0.1' will be made
available in the classloader which loads the plugin. For this to work, you need
to publish a dependency descriptor along with the plugin jar. For example, you
might publish the plugin plus a pom.xml to a maven repository.
> I want to prevent plugin users having to define the
> dependency. I tried to go with this in my plugin implementation:
>
> project.buildscript.dependencies.add("classpath",
> "commons-lang:commons-lang:2.5")
>
> However, that throw this exception:
>
> Caused by: org.gradle.api.InvalidUserDataException: You can't change a
> configuration which is not in unresolved state!
> at
> org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.throwExceptionIfNotInUnresolvedState(DefaultConfiguration.java:430)
> at
> org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.addDependency(DefaultConfiguration.java:297)
> at org.gradle.api.artifacts.Configuration$addDependency.call(Unknown
> Source)
> at
> org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.pushDependency(DefaultDependencyHandler.groovy:52)
> at
> org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.this$2$pushDependency(DefaultDependencyHandler.groovy)
> at
> org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler$this$2$pushDependency.callCurrent(Unknown
> Source)
> at
> org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.add(DefaultDependencyHandler.groovy:42)
>
> There must be something I am missing. Any help would be highly appreciated.
>
> Thanks,
>
> Ben
>
> --
> View this message in context:
> http://gradle.1045684.n5.nabble.com/Defining-buildscript-dependency-in-custom-plugin-tp3620230p3620230.html
> Sent from the gradle-user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
--
Adam Murdoch
Gradle Developer
http://www.gradle.org
Co-Founder and VP of Engineering, Gradleware Inc. - Gradle Training, Support,
Consulting
http://www.gradleware.com