Skip to content

Commit b62d751

Browse files
committed
Fix projects that failed to build within Intellij (elastic#62258)
This commit address some build failures from the perspective of Intellij. These changes include: * changing an order of a dependency definition that seems to can cause Intellij build to fail. * introduction of an abstract class out of the test source set (seems to be an issue sharing classes cross projects with non-standard source sets. * a couple of missing dependency definitions (not sure how the command line worked prior to this) # Conflicts: # x-pack/qa/security-example-spi-extension/build.gradle
1 parent 9ac4ee9 commit b62d751

File tree

13 files changed

+331
-288
lines changed

13 files changed

+331
-288
lines changed

buildSrc/src/main/java/org/elasticsearch/gradle/util/GradleUtils.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public static void setupIdeForTestSourceSet(Project project, SourceSet testSourc
155155
project.getPluginManager().withPlugin("idea", p -> {
156156
IdeaModel idea = project.getExtensions().getByType(IdeaModel.class);
157157
idea.getModule().setTestSourceDirs(testSourceSet.getJava().getSrcDirs());
158-
idea.getModule().getScopes().put("TEST", Map.of("plus", List.of(runtimeClasspathConfiguration)));
158+
idea.getModule().getScopes().put(testSourceSet.getName(), Map.of("plus", List.of(runtimeClasspathConfiguration)));
159159
});
160160
project.getPluginManager().withPlugin("eclipse", p -> {
161161
EclipseModel eclipse = project.getExtensions().getByType(EclipseModel.class);
@@ -196,6 +196,19 @@ public static void extendSourceSet(Project project, String parentSourceSetName,
196196
child.setRuntimeClasspath(project.getObjects().fileCollection().from(child.getRuntimeClasspath(), parent.getOutput()));
197197
}
198198

199+
/**
200+
* Extends one configuration from another and refreshes the classpath of a provided Test.
201+
* The Test parameter is only needed for eagerly defined test tasks.
202+
*/
203+
public static void extendSourceSet(Project project, String parentSourceSetName, String childSourceSetName, Test test) {
204+
extendSourceSet(project, parentSourceSetName, childSourceSetName);
205+
if (test != null) {
206+
SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
207+
SourceSet child = sourceSets.getByName(childSourceSetName);
208+
test.setClasspath(child.getRuntimeClasspath());
209+
}
210+
}
211+
199212
public static Dependency projectDependency(Project project, String projectPath, String projectConfig) {
200213
if (project.findProject(projectPath) == null) {
201214
throw new GradleException("no project [" + projectPath + "], project names: " + project.getRootProject().getAllprojects());

qa/die-with-dignity/build.gradle

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import org.elasticsearch.gradle.info.BuildParams
2+
import org.elasticsearch.gradle.util.GradleUtils
23

34
apply plugin: 'elasticsearch.java-rest-test'
45
apply plugin: 'elasticsearch.esplugin'
@@ -8,10 +9,8 @@ esplugin {
89
classname 'org.elasticsearch.DieWithDignityPlugin'
910
}
1011

11-
dependencies {
12-
// let the javaRestTest see the classpath of main
13-
javaRestTestImplementation project.sourceSets.main.runtimeClasspath
14-
}
12+
// let the javaRestTest see the classpath of main
13+
GradleUtils.extendSourceSet(project, "main", "javaRestTest", javaRestTest)
1514

1615
javaRestTest {
1716
systemProperty 'tests.security.manager', 'false'

x-pack/docs/src/test/java/org/elasticsearch/smoketest/XDocsClientYamlTestSuiteIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import org.elasticsearch.test.rest.yaml.ClientYamlTestClient;
1818
import org.elasticsearch.test.rest.yaml.ClientYamlTestResponse;
1919
import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestSpec;
20-
import org.elasticsearch.xpack.test.rest.XPackRestIT;
20+
import org.elasticsearch.xpack.test.rest.AbstractXPackRestTest;
2121
import org.junit.After;
2222

2323
import java.util.List;
@@ -29,7 +29,7 @@
2929
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
3030
import static org.hamcrest.Matchers.is;
3131

32-
public class XDocsClientYamlTestSuiteIT extends XPackRestIT {
32+
public class XDocsClientYamlTestSuiteIT extends AbstractXPackRestTest {
3333
private static final String USER_TOKEN = basicAuthHeaderValue("test_admin", new SecureString("x-pack-test-password".toCharArray()));
3434

3535
public XDocsClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {

x-pack/plugin/build.gradle

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ apply plugin: 'elasticsearch.validate-rest-spec'
1212
archivesBaseName = 'x-pack'
1313

1414
dependencies {
15-
yamlRestTestImplementation project(xpackModule('core')) // this redundant dependency is here to make IntelliJ happy
16-
yamlRestTestImplementation project(path: xpackModule('core'), configuration: 'testArtifacts')
15+
testImplementation project(xpackModule('core'))
16+
testImplementation project(path: xpackModule('core'), configuration: 'testArtifacts')
1717
javaRestTestImplementation project(path: xpackModule('core'), configuration: 'testArtifacts')
18+
// let the yamlRestTest see the classpath of test
19+
yamlRestTestImplementation project.sourceSets.test.runtimeClasspath
1820
}
1921

2022
subprojects {
@@ -61,18 +63,13 @@ subprojects {
6163
configurations {
6264
testArtifacts.extendsFrom testRuntime
6365
testArtifacts.extendsFrom testImplementation
64-
testArtifacts.extendsFrom yamlRestTestImplementation
65-
testArtifacts.extendsFrom javaRestTestImplementation
6666
}
6767

6868
restResources {
6969
restApi {
7070
includeCore '*'
7171
includeXpack '*'
7272
}
73-
restTests {
74-
includeXpack '*'
75-
}
7673
}
7774

7875
//The api and tests need to stay at src/test/... since some external tooling depends on that exact file path.
@@ -83,10 +80,8 @@ artifacts {
8380

8481
def testJar = tasks.register("testJar", Jar) {
8582
appendix 'test'
86-
duplicatesStrategy = DuplicatesStrategy.INCLUDE
8783
from sourceSets.test.output
88-
from sourceSets.yamlRestTest.output
89-
from sourceSets.javaRestTest.output
84+
9085
/*
9186
* Stick the license and notice file in the jar. This isn't strictly
9287
* needed because we don't publish it but it makes our super-paranoid

x-pack/plugin/deprecation/qa/rest/build.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.elasticsearch.gradle.util.GradleUtils
2+
13
apply plugin: 'elasticsearch.esplugin'
24
apply plugin: 'elasticsearch.java-rest-test'
35

@@ -9,10 +11,12 @@ esplugin {
911
dependencies {
1012
javaRestTestImplementation("com.fasterxml.jackson.core:jackson-annotations:${versions.jackson}")
1113
javaRestTestImplementation("com.fasterxml.jackson.core:jackson-databind:${versions.jackson}")
12-
// let the javaRestTest see the classpath of main
13-
javaRestTestImplementation project.sourceSets.main.runtimeClasspath
1414
}
1515

16+
// let the javaRestTest see the classpath of main
17+
GradleUtils.extendSourceSet(project, "main", "javaRestTest", javaRestTest)
18+
19+
1620
restResources {
1721
restApi {
1822
includeCore '_common', 'indices', 'index'

x-pack/plugin/ilm/qa/multi-node/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
import org.elasticsearch.gradle.util.GradleUtils
2+
13
apply plugin: 'elasticsearch.java-rest-test'
24

35
dependencies {
46
javaRestTestImplementation project(path: xpackProject('plugin').path, configuration: 'testArtifacts')
57
}
68

9+
// let the javaRestTest see the classpath of main
10+
GradleUtils.extendSourceSet(project, "main", "javaRestTest", javaRestTest)
11+
12+
713
File repoDir = file("$buildDir/testclusters/repo")
814

915
javaRestTest {

x-pack/plugin/ilm/qa/with-security/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
apply plugin: 'elasticsearch.java-rest-test'
22

33
dependencies {
4+
javaRestTestImplementation project(path: xpackModule('core'))
45
javaRestTestImplementation project(path: xpackProject('plugin').path, configuration: 'testArtifacts')
56
testImplementation project(":client:rest-high-level")
67
}

x-pack/plugin/ml/qa/ml-with-security/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
apply plugin: 'elasticsearch.yaml-rest-test'
22

33
dependencies {
4-
yamlRestTestImplementation project(path: xpackModule('core'), configuration: 'testArtifacts')
54
yamlRestTestImplementation project(path: xpackModule('core'))
5+
yamlRestTestImplementation project(path: xpackModule('core'), configuration: 'testArtifacts')
66
yamlRestTestImplementation project(path: xpackProject('plugin').path, configuration: 'testArtifacts')
77
}
88

x-pack/plugin/ml/qa/ml-with-security/src/yamlRestTest/java/org/elasticsearch/smoketest/MlWithSecurityIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
import org.elasticsearch.common.util.concurrent.ThreadContext;
1212
import org.elasticsearch.test.SecuritySettingsSourceField;
1313
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
14-
import org.elasticsearch.xpack.test.rest.XPackRestIT;
14+
import org.elasticsearch.xpack.test.rest.AbstractXPackRestTest;
1515

1616
import java.util.Collections;
1717
import java.util.Map;
1818

1919
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
2020

2121

22-
public class MlWithSecurityIT extends XPackRestIT {
22+
public class MlWithSecurityIT extends AbstractXPackRestTest {
2323

2424
private static final String TEST_ADMIN_USERNAME = "x_pack_rest_user";
2525

x-pack/plugin/runtime-fields/qa/with-security/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
apply plugin: 'elasticsearch.java-rest-test'
22

33
dependencies {
4+
javaRestTestImplementation project(path: xpackModule('core'))
45
javaRestTestImplementation project(path: xpackProject('plugin').path, configuration: 'testArtifacts')
56
}
67

0 commit comments

Comments
 (0)