I am trying to write some unit tests for a custom Gradle plugin and task and am running into issues with the transitive dependencies brought in by the ‘gradleApi()’ dependency. Specifically, I am writing a plugin that will generate JAX-RS resource stubs from RAML (http://raml.org) configuration files. The plugin works as expected, but the unit tests fail because the ‘gradleApi()’ dependency brings in a version of the ‘org.yaml:snakeyaml’ dependency that is incompatible with the RAML code (it appears that Gradle depends on version 1.6, and RAML wants version 1.13). It’s possible that there is a better way to test the plugin and task. My first attempt was to use the 'GradleConnector’class (http://www.gradle.org/docs/current/javadoc/org/gradle/tooling/GradleConnector.html) to load a dynamically generated Gradle build script that would use the plugin and task, but I could not find a way to get it to delegate the classloader from the test to the connected project to ensure that it could find the plugin to load and the task to execute. My next (and current attempt) is to use the ‘ProjectBuilder’ class (http://www.gradle.org/docs/current/javadoc/org/gradle/testfixtures/ProjectBuilder.html) from the Gradle test fixtures to load the plugin and execute the task. This works, but fails when the underlying RAML code attempts to call a method on a class in the ‘snakeyaml’ dependency that exists in 1.13, but not in 1.6. I then attempted to modify my build.gradle script to use the Gradle Maven repo and directly declare gradle-core and gradle-tooling as dependencies, but ran into an issue where gradle-base-services-groovy is not in the repo. So, I am back to square one again. Is there any way (either declarative or programmatically) to exclude dependencies brought in by the Gradle API (or better yet, replace them with the proper version)? It seems like this should be something that at a minimum should be supported in the test scope, as it doesn’t necessarily make sense to much with the versions used for compilation, as Gradle is suppose to be a set of “provided” dependencies. I would like to avoid having to create a whole project just to test the plugin. If I am way off base here and there is a better/approved way to unit test/integration test a custom Gradle task in the same project, I am all ears. Thanks in advance for any insight/help.
I am having similar issue when using betamax for testing a gradle plugin am working on. betamax needs at least snakeyaml 1.10 and gradle API overrides it with its own dependnecy on 1.6. Not able to work get both gradleApi and betamax to work together.