Fix eclipse issues related to rest client shading (#25874)

* A cycle was detected in eclipse, and was fixed in the same fashion as
  core and core-tests.
* The rest client deps jar was not properly exported in the generated
  eclipse classpath file for rest client.

Relates #25208
This commit is contained in:
Michael Basnight 2017-07-27 10:20:53 -05:00 committed by GitHub
parent 2c271f0f22
commit 3a20922046
4 changed files with 40 additions and 1 deletions

View File

@ -100,6 +100,18 @@ if (isIdea == false && isEclipse == false) {
} }
} }
if (isEclipse) {
// in eclipse the project is under a fake root, we need to change around the source sets
sourceSets {
if (project.path == ":client:rest") {
main.java.srcDirs = ['java']
//main.resources.srcDirs = ['resources']
} else {
test.java.srcDirs = ['java']
test.resources.srcDirs = ['resources']
}
}
}
// adds a dependency to compile, so the -deps jar is built first // adds a dependency to compile, so the -deps jar is built first
sourceSets.main.output.dir(shadedSrcDir, builtBy: 'shadeDeps') sourceSets.main.output.dir(shadedSrcDir, builtBy: 'shadeDeps')
@ -113,7 +125,12 @@ dependencies {
compile shadeDeps.outputs.files compile shadeDeps.outputs.files
testCompile "org.elasticsearch.client:test:${version}" if (isEclipse == false || project.path == ":client:rest-tests") {
testCompile("org.elasticsearch.client:test:${version}") {
// tests use the locally compiled version of core
exclude group: 'org.elasticsearch', module: 'elasticsearch'
}
}
testCompile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}" testCompile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
testCompile "junit:junit:${versions.junit}" testCompile "junit:junit:${versions.junit}"
testCompile "org.hamcrest:hamcrest-all:${versions.hamcrest}" testCompile "org.hamcrest:hamcrest-all:${versions.hamcrest}"
@ -123,6 +140,14 @@ dependencies {
signature "org.codehaus.mojo.signature:java17:1.0@signature" signature "org.codehaus.mojo.signature:java17:1.0@signature"
} }
// Set the exported=true for the generated rest client deps since it is used by other projects in eclipse.
// https://docs.gradle.org/3.3/userguide/eclipse_plugin.html#sec:eclipse_modify_domain_objects
eclipse.classpath.file {
whenMerged { classpath ->
classpath.entries.findAll { entry -> entry.path.contains("elasticsearch-rest-client") }*.exported = true
}
}
dependencyLicenses.dependencies = project.configurations.shade dependencyLicenses.dependencies = project.configurations.shade
forbiddenApisMain { forbiddenApisMain {

View File

@ -0,0 +1,2 @@
// this is just shell gradle file for eclipse to have separate projects for src and tests
apply from: '../../build.gradle'

View File

@ -0,0 +1,6 @@
// this is just shell gradle file for eclipse to have separate projects for src and tests
apply from: '../../build.gradle'
dependencies {
testCompile project(':client:rest')
}

View File

@ -96,6 +96,7 @@ if (isEclipse) {
// eclipse cannot handle an intermediate dependency between main and test, so we must create separate projects // eclipse cannot handle an intermediate dependency between main and test, so we must create separate projects
// for core-src and core-tests // for core-src and core-tests
projects << 'core-tests' projects << 'core-tests'
projects << 'client:rest-tests'
} }
include projects.toArray(new String[0]) include projects.toArray(new String[0])
@ -119,6 +120,11 @@ if (isEclipse) {
project(":core").buildFileName = 'eclipse-build.gradle' project(":core").buildFileName = 'eclipse-build.gradle'
project(":core-tests").projectDir = new File(rootProject.projectDir, 'core/src/test') project(":core-tests").projectDir = new File(rootProject.projectDir, 'core/src/test')
project(":core-tests").buildFileName = 'eclipse-build.gradle' project(":core-tests").buildFileName = 'eclipse-build.gradle'
project(":client:rest").projectDir = new File(rootProject.projectDir, 'client/rest/src/main')
project(":client:rest").buildFileName = 'eclipse-build.gradle'
project(":client:rest-tests").projectDir = new File(rootProject.projectDir, 'client/rest/src/test')
project(":client:rest-tests").buildFileName = 'eclipse-build.gradle'
} }
/** /**