diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy index 619cfe1ac24..69931a02c34 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy @@ -18,9 +18,12 @@ */ package org.elasticsearch.gradle.precommit +import org.gradle.api.GradleException import org.gradle.api.Project import org.gradle.api.Task +import org.gradle.api.file.FileCollection import org.gradle.api.plugins.JavaBasePlugin +import org.gradle.api.tasks.Exec import org.gradle.api.tasks.TaskContainer /** @@ -32,7 +35,8 @@ class PrecommitTasks { static void configure(Project project) { List precommitTasks = [ configureForbiddenApis(project), - configureForbiddenPatterns(project.tasks)] + configureForbiddenPatterns(project.tasks), + configureJarHell(project)] Map precommitOptions = [ name: 'precommit', @@ -90,4 +94,31 @@ class PrecommitTasks { rule name: 'tab', pattern: /\t/ } } + + static Task configureJarHell(Project project) { + File successMarker = new File(project.buildDir, 'markers/jarHell') + Exec task = project.tasks.create(name: 'jarHell', type: Exec) + FileCollection testClasspath = project.sourceSets.test.runtimeClasspath + task.dependsOn(testClasspath) + task.inputs.files(testClasspath) + task.outputs.file(successMarker) + task.executable = new File(project.javaHome, 'bin/java') + task.doFirst({ + task.args('-cp', testClasspath.asPath, 'org.elasticsearch.bootstrap.JarHell') + }) + if (task.logger.isInfoEnabled() == false) { + task.standardOutput = new ByteArrayOutputStream() + task.errorOutput = task.standardOutput + task.ignoreExitValue = true + task.doLast({ + if (execResult.exitValue != 0) { + logger.error(standardOutput.toString()) + throw new GradleException("JarHell failed") + } + successMarker.parentFile.mkdirs() + successMarker.setText("", 'UTF-8') + }) + } + return task + } }