Skip to content

Commit f2e3978

Browse files
authored
[Backport] Avoid sharing source directories as it breaks intellij (#40877) (#41026)
* Avoid sharing source directories as it breaks intellij (#40877) (cherry picked from commit 71d407f)
1 parent dcdf15f commit f2e3978

File tree

11 files changed

+65
-89
lines changed

11 files changed

+65
-89
lines changed

build.gradle

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -360,14 +360,6 @@ gradle.projectsEvaluated {
360360
integTest.mustRunAfter test
361361
}
362362
configurations.all { Configuration configuration ->
363-
/*
364-
* The featureAwarePlugin configuration has a dependency on x-pack:plugin:core and x-pack:plugin:core has a dependency on the
365-
* featureAwarePlugin configuration. The below task ordering logic would force :x-pack:plugin:core:test
366-
* :x-pack:test:feature-aware:test to depend on each other circularly. We break that cycle here.
367-
*/
368-
if (configuration.name == "featureAwarePlugin") {
369-
return
370-
}
371363
dependencies.all { Dependency dep ->
372364
Project upstreamProject = dependencyToProject(dep)
373365
if (upstreamProject != null) {
@@ -379,7 +371,7 @@ gradle.projectsEvaluated {
379371
Task task = project.tasks.findByName(taskName)
380372
Task upstreamTask = upstreamProject.tasks.findByName(taskName)
381373
if (task != null && upstreamTask != null) {
382-
task.mustRunAfter(upstreamTask)
374+
task.shouldRunAfter(upstreamTask)
383375
}
384376
}
385377
}
@@ -404,21 +396,6 @@ allprojects {
404396
// also ignore other possible build dirs
405397
excludeDirs += file('build')
406398
excludeDirs += file('build-eclipse')
407-
408-
iml {
409-
// fix so that Gradle idea plugin properly generates support for resource folders
410-
// see also https://issues.gradle.org/browse/GRADLE-2975
411-
withXml {
412-
it.asNode().component.content.sourceFolder.findAll { it.@url == 'file://$MODULE_DIR$/src/main/resources' }.each {
413-
it.attributes().remove('isTestSource')
414-
it.attributes().put('type', 'java-resource')
415-
}
416-
it.asNode().component.content.sourceFolder.findAll { it.@url == 'file://$MODULE_DIR$/src/test/resources' }.each {
417-
it.attributes().remove('isTestSource')
418-
it.attributes().put('type', 'java-test-resource')
419-
}
420-
}
421-
}
422399
}
423400
}
424401

@@ -436,14 +413,6 @@ idea {
436413
vcs = 'Git'
437414
}
438415
}
439-
// Make sure gradle idea was run before running anything in intellij (including import).
440-
File ideaMarker = new File(projectDir, '.local-idea-is-configured')
441-
tasks.idea.doLast {
442-
ideaMarker.setText('', 'UTF-8')
443-
}
444-
if (System.getProperty('idea.active') != null && ideaMarker.exists() == false) {
445-
throw new GradleException('You must run `gradle idea` from the root of elasticsearch before importing into IntelliJ')
446-
}
447416

448417
// eclipse configuration
449418
allprojects {

qa/full-cluster-restart/build.gradle

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,16 @@ task bwcTestSnapshots {
107107
}
108108

109109
check.dependsOn(bwcTestSnapshots)
110+
111+
configurations {
112+
testArtifacts.extendsFrom testRuntime
113+
}
114+
115+
task testJar(type: Jar) {
116+
appendix 'test'
117+
from sourceSets.test.output
118+
}
119+
120+
artifacts {
121+
testArtifacts testJar
122+
}

x-pack/plugin/core/build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ dependencies {
4444
testCompile project(path: ':modules:reindex', configuration: 'runtime')
4545
testCompile project(path: ':modules:parent-join', configuration: 'runtime')
4646
testCompile project(path: ':modules:analysis-common', configuration: 'runtime')
47+
testCompile(project(':x-pack:license-tools')) {
48+
transitive = false
49+
}
4750
testCompile ("org.elasticsearch.client:elasticsearch-rest-high-level-client:${version}")
4851
}
4952

@@ -91,8 +94,8 @@ licenseHeaders {
9194
}
9295

9396
// make LicenseSigner available for testing signed licenses
94-
sourceSets.test.java {
95-
srcDir '../../license-tools/src/main/java'
97+
sourceSets.test.resources {
98+
srcDir 'src/main/config'
9699
}
97100

98101
unitTest {

x-pack/plugin/security/build.gradle

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ dependencies {
125125
compileJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked"
126126
compileTestJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked"
127127

128+
processTestResources {
129+
from(project(xpackModule('core')).file('src/main/config'))
130+
from(project(xpackModule('core')).file('src/test/resources'))
131+
}
132+
128133
configurations {
129134
testArtifacts.extendsFrom testRuntime
130135
}
@@ -144,13 +149,6 @@ processResources {
144149
}
145150
}
146151

147-
sourceSets.test.resources {
148-
srcDir '../core/src/test/resources'
149-
// this is required because audit logging tests (LoggingAuditTrailTests)
150-
// parse the actual log4j2.properties config file to extract and test
151-
// the log line pattern. These tests need access to the file as a resource.
152-
srcDir '../core/src/main/config'
153-
}
154152
dependencyLicenses {
155153
mapping from: /java-support|opensaml-.*/, to: 'shibboleth'
156154
mapping from: /http.*/, to: 'httpclient'

x-pack/plugin/sql/qa/security/build.gradle

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@ subprojects {
1313
// Use resources from the parent project in subprojects
1414
sourceSets {
1515
test {
16-
java {
17-
srcDirs = ["${mainProject.projectDir}/src/test/java"]
18-
}
19-
resources {
20-
srcDirs = ["${mainProject.projectDir}/src/test/resources"]
16+
mainProject.sourceSets.test.output.classesDirs.each { dir ->
17+
output.addClassesDir { dir }
2118
}
19+
runtimeClasspath += mainProject.sourceSets.test.output
2220
}
2321
}
2422

23+
processTestResources {
24+
from mainProject.file('src/test/resources')
25+
}
26+
27+
// subprojects don't contain source so ignore
28+
licenseHeaders.enabled = false
29+
2530
dependencies {
2631
testCompile "org.elasticsearch.plugin:x-pack-core:${version}"
2732
}

x-pack/qa/full-cluster-restart/build.gradle

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ dependencies {
2525
// This is total #$%, but the solution is to get the SAML realm (which uses guava) out of security proper
2626
exclude group: "com.google.guava", module: "guava"
2727
}
28+
testCompile project(path: ':qa:full-cluster-restart', configuration: 'testArtifacts')
2829
}
2930

3031
Closure waitWithAuth = { NodeInfo node, AntBuilder ant ->
@@ -72,15 +73,6 @@ Closure waitWithAuth = { NodeInfo node, AntBuilder ant ->
7273

7374
Project mainProject = project
7475

75-
String coreFullClusterRestartPath = project(':qa:full-cluster-restart').projectDir.toPath().resolve('src/test/java').toString()
76-
sourceSets {
77-
test {
78-
java {
79-
srcDirs += [coreFullClusterRestartPath]
80-
}
81-
}
82-
}
83-
8476
licenseHeaders {
8577
approvedLicenses << 'Apache'
8678
}
@@ -90,7 +82,7 @@ forbiddenPatterns {
9082
}
9183

9284
// tests are pushed down to subprojects
93-
testingConventions.enabled = false
85+
testingConventions.enabled = false
9486

9587
/**
9688
* Subdirectories of this project are test rolling upgrades with various
@@ -105,22 +97,22 @@ subprojects {
10597

10698
apply plugin: 'elasticsearch.standalone-test'
10799

108-
// Use resources from the rolling-upgrade project in subdirectories
109100
sourceSets {
110101
test {
111-
java {
112-
srcDirs = ["${mainProject.projectDir}/src/test/java", coreFullClusterRestartPath]
113-
}
114-
resources {
115-
srcDirs = ["${mainProject.projectDir}/src/test/resources"]
102+
mainProject.sourceSets.test.output.classesDirs.each { dir ->
103+
output.addClassesDir { dir }
116104
}
105+
runtimeClasspath += mainProject.sourceSets.test.output
117106
}
118107
}
119108

120-
licenseHeaders {
121-
approvedLicenses << 'Apache'
109+
processTestResources {
110+
from mainProject.file('src/test/resources')
122111
}
123112

113+
// subprojects don't contain source so ignore
114+
licenseHeaders.enabled = false
115+
124116
forbiddenPatterns {
125117
exclude '**/system_key'
126118
}
@@ -194,7 +186,7 @@ subprojects {
194186
extraConfigFile 'testnode.crt', new File(outputDir + '/testnode.crt')
195187
extraConfigFile 'testnode.jks', new File(outputDir + '/testnode.jks')
196188
if (version.before('5.1.2')) {
197-
// Disable monitoring if version is before 5.1.2 because form 5.1.2 we changed how we get DocStats
189+
// Disable monitoring if version is before 5.1.2 because form 5.1.2 we changed how we get DocStats
198190
// and we can get a negative value which cannot because serialised by <5.1.2 as it writes VLongs
199191
setting 'xpack.monitoring.enabled', 'false'
200192
}
@@ -275,7 +267,7 @@ subprojects {
275267
bwcTest.dependsOn(versionBwcTest)
276268
}
277269
}
278-
270+
279271
unitTest.enabled = false // no unit tests for full cluster restarts, only the rest integration test
280272

281273
// basic integ tests includes testing bwc against the most recent version
@@ -295,6 +287,7 @@ subprojects {
295287
testCompile project(path: xpackModule('watcher'), configuration: 'runtime')
296288
testCompile project(path: xpackModule('core'), configuration: 'testArtifacts')
297289
testCompile project(path: xpackModule('security'), configuration: 'testArtifacts')
290+
testCompile project(path: ':qa:full-cluster-restart', configuration: 'testArtifacts')
298291
}
299292

300293
// copy x-pack plugin info so it is on the classpath and security manager has the right permissions

x-pack/qa/rolling-upgrade/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,18 @@ subprojects {
8888

8989
apply plugin: 'elasticsearch.standalone-test'
9090

91-
// Use resources from the rolling-upgrade project in subdirectories
9291
sourceSets {
9392
test {
94-
java {
95-
srcDirs = ["${mainProject.projectDir}/src/test/java"]
96-
}
97-
resources {
98-
srcDirs = ["${mainProject.projectDir}/src/test/resources"]
93+
mainProject.sourceSets.test.output.classesDirs.each { dir ->
94+
output.addClassesDir { dir }
9995
}
96+
runtimeClasspath += mainProject.sourceSets.test.output
10097
}
10198
}
10299

100+
// subprojects don't contain source so ignore
101+
licenseHeaders.enabled = false
102+
103103
forbiddenPatterns {
104104
exclude '**/system_key'
105105
}

x-pack/qa/security-tools-tests/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ dependencies {
88
}
99

1010
// add test resources from security, so certificate tool tests can use example certs
11-
sourceSets.test.resources.srcDirs(project(xpackModule('security')).sourceSets.test.resources.srcDirs)
11+
processTestResources {
12+
from(project(xpackModule('security')).sourceSets.test.resources.srcDirs)
13+
}
1214

1315
// we have to repeate these patterns because the security test resources are effectively in the src of this project
1416
forbiddenPatterns {

x-pack/qa/third-party/active-directory/build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ dependencies {
99
testFixtures.useFixture ":x-pack:test:smb-fixture"
1010

1111
// add test resources from security, so tests can use example certs
12-
sourceSets.test.resources.srcDirs(project(xpackModule('security')).sourceSets.test.resources.srcDirs)
13-
compileTestJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked"
12+
processTestResources {
13+
from(project(xpackModule('security')).sourceSets.test.resources.srcDirs)
14+
}
15+
16+
compileTestJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked"
1417

1518
// we have to repeat these patterns because the security test resources are effectively in the src of this project
1619
forbiddenPatterns {

x-pack/qa/tribe-tests-with-license/build.gradle

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,8 @@ unitTest {
3434
include '**/*Tests.class'
3535
}
3636

37-
String licensePath = xpackProject('license-tools').projectDir.toPath().resolve('src/test/resources').toString()
38-
sourceSets {
39-
test {
40-
resources {
41-
srcDirs += [licensePath]
42-
}
43-
}
37+
processTestResources {
38+
from xpackProject('license-tools').file('src/test/resources')
4439
}
4540

4641
project.forbiddenPatterns {

0 commit comments

Comments
 (0)