Skip to content

Commit 86660b0

Browse files
authored
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)
1 parent 021d278 commit 86660b0

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

+14-1
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

+3-4
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

+2-2
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

+5-10
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,23 @@ apply plugin: 'elasticsearch.validate-rest-spec'
77
archivesBaseName = 'x-pack'
88

99
dependencies {
10-
yamlRestTestImplementation project(xpackModule('core')) // this redundant dependency is here to make IntelliJ happy
11-
yamlRestTestImplementation project(path: xpackModule('core'), configuration: 'testArtifacts')
10+
testImplementation project(xpackModule('core'))
11+
testImplementation project(path: xpackModule('core'), configuration: 'testArtifacts')
1212
javaRestTestImplementation project(path: xpackModule('core'), configuration: 'testArtifacts')
13+
// let the yamlRestTest see the classpath of test
14+
yamlRestTestImplementation project.sourceSets.test.runtimeClasspath
1315
}
1416

1517
configurations {
1618
testArtifacts.extendsFrom testRuntime
1719
testArtifacts.extendsFrom testImplementation
18-
testArtifacts.extendsFrom yamlRestTestImplementation
19-
testArtifacts.extendsFrom javaRestTestImplementation
2020
}
2121

2222
restResources {
2323
restApi {
2424
includeCore '*'
2525
includeXpack '*'
2626
}
27-
restTests {
28-
includeXpack '*'
29-
}
3027
}
3128

3229
//The api and tests need to stay at src/test/... since some external tooling depends on that exact file path.
@@ -37,10 +34,8 @@ artifacts {
3734

3835
def testJar = tasks.register("testJar", Jar) {
3936
appendix 'test'
40-
duplicatesStrategy = DuplicatesStrategy.INCLUDE
4137
from sourceSets.test.output
42-
from sourceSets.yamlRestTest.output
43-
from sourceSets.javaRestTest.output
38+
4439
/*
4540
* Stick the license and notice file in the jar. This isn't strictly
4641
* needed because we don't publish it but it makes our super-paranoid

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

+6-2
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

+6
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

+1
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

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

+1-1
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

+2-2
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

+1
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)