Gradle - conflicting jar files (plugin) on classpath
If you get an issue related to incorrect jar files on classpath while invoking gradle plugin, move the plugin's tasks into seperate build file. Use GradleBuild task type with reference to seperated build file.
When developing small extension for ratpack manual I had to add gradle-js plugin with two tasks for combining javascript files into one file and then minifying it. Minification task thrown exception idicating that there are conflicting jar file versions for google's guava library:
java.lang.NoSuchMethodError: com.google.common.io.ByteStreams.limit
Create separate gradle build file with plugin dependcies and task definitions:
// minifyjs.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "com.eriwen:gradle-js-plugin:1.12.1"
}
}
apply plugin: "com.eriwen.gradle.js"
// grunt-js tasks
// merge listed js files into one file
combineJs {
source = [
"${projectDir}/src/assets/js/googleAnalytics.js",
"${projectDir}/src/assets/js/modernizr.js",
"${projectDir}/src/assets/js/prism.js",
"${projectDir}/src/assets/js/jquery.js",
"${projectDir}/src/assets/js/anchorHighlight.js",
"${projectDir}/src/assets/js/toggleImports.js"
]
dest = file("${buildDir}/assets/js/all.js")
}
minifyJs {
source = combineJs
dest = file("${buildDir}/assets/js/all.min.js")
}
Add new task definition in your main gradle build file with reference to minifyjs.gradle
:
// ratpack-manual.gradle
task buildJs(type: GradleBuild) {
buildFile = "minifyjs.gradle"
tasks = ["combineJs", "minifyJs"]
}
Call new task in the target task
// ratpack-manual.gradle
task stylizeManual(type: Sync) {
into "$buildDir/stylized-manual"
from compileManual
from compassCompile
from buildJs // <=== call external tasks
}
The minifyjs.gradle
tasks are executed in their own environment, so with their own classpath.