Dynamic dependency-version for plugin

I have recently written a plugin for gradle that allows me to generate java source from wsdl using apache cxf. This plugin uses the latest release of apache cxf to do the work.

Is there some way I could allow my users to dynamically choose which version of cxf that will be used, or do I have to create a separate version for each specific cxf-release?

The cxf-libs are compile-time dependencies to the plugin.

The plugin source can be found here: https://github.com/nilsmagnus/wsdl2java

You can just set a default version as a dependency of your plugin and then allow users to define their own dependency via the buildscript classpath. Note that if they want a version lower than what your plugin calls for, they will need to force their version. For instance:

buildscript {
  dependencies {
    classpath("org.apache.cxf:cxf-tools:2.0.9") { force = true }
  }
}

Thanks! Just what I needed.

That’s a nice trick, Gary!

The alternative is more work and is what is used in the JRuby Base and Asciidoctor plugins.

Allow the user to specify the version you want in an extension i.e.

jruby {
  defaultVersion = '1.7.15'
}

Internaly the plugin uses a ‘project.afterEvaluate’ closure to check the version and add it a configuration. For instance in one of the aforementioned plugins the equivalent code could be something like

project.afterEvaluate {
       project.dependencies {
            jrubyExec "org.jruby:jruby-complete:${project.jruby.defaultVersion}"
        }
}

where it adds the specific jar to a configuration called ‘jrubyExec’.

Thanks Schalke, that is en elegant solution, but maybe not for the faint hearted.

I ended up doing the same as the asciidoctor plugin, creating my own classloader and stuff, so now I have dynamic dependencies for my plugin.