@@ -314,8 +314,42 @@ gradle.projectsEvaluated {
314314
315315// eclipse configuration
316316allprojects {
317- apply plugin : ' elasticsearch.eclipse'
317+ apply plugin : ' eclipse'
318+ // Name all the non-root projects after their path so that paths get grouped together when imported into eclipse.
319+ if (path != ' :' ) {
320+ eclipse. project. name = path
321+ if (Os . isFamily(Os . FAMILY_WINDOWS )) {
322+ eclipse. project. name = eclipse. project. name. replace(' :' , ' _' )
323+ }
324+ }
325+
326+ plugins. withType(JavaBasePlugin ) {
327+ java. modularity. inferModulePath. set(false )
328+ eclipse. classpath. file. whenMerged { classpath ->
329+ /*
330+ * give each source folder a unique corresponding output folder
331+ * outside of the usual `build` folder. We can't put the build
332+ * in the usual build folder because eclipse becomes *very* sad
333+ * if we delete it. Which `gradlew clean` does all the time.
334+ */
335+ int i = 0 ;
336+ classpath. entries. findAll { it instanceof SourceFolder }. each { folder ->
337+ i++ ;
338+ folder. output = ' out/eclipse/' + i
339+ }
318340
341+ // Starting with Gradle 6.7 test dependencies are not exposed by eclipse
342+ // projects by default. This breaks project dependencies using the `java-test-fixtures` plugin
343+ // or dependencies on other projects manually declared testArtifacts configurations
344+ // This issue is tracked in gradle issue tracker.
345+ // See https://github.com/gradle/gradle/issues/14932 for further details
346+ classpath. entries. findAll {
347+ it instanceof ProjectDependency
348+ }. each {
349+ it. entryAttributes. remove(' without_test_code' )
350+ }
351+ }
352+ }
319353 /*
320354 * Allow accessing com/sun/net/httpserver in projects that have
321355 * configured forbidden apis to allow it.
@@ -331,6 +365,34 @@ allprojects {
331365 }
332366 }
333367 }
368+
369+ File licenseHeaderFile
370+ String prefix = ' :x-pack'
371+ if (Os . isFamily(Os . FAMILY_WINDOWS )) {
372+ prefix = prefix. replace(' :' , ' _' )
373+ }
374+ if (eclipse. project. name. startsWith(prefix)) {
375+ licenseHeaderFile = new File (project. rootDir, ' build-tools-internal/src/main/resources/license-headers/elastic-license-2.0-header.txt' )
376+ } else {
377+ licenseHeaderFile = new File (project. rootDir, ' build-tools-internal/src/main/resources/license-headers/sspl+elastic-license-header.txt' )
378+ }
379+
380+ String lineSeparator = Os . isFamily(Os . FAMILY_WINDOWS ) ? ' \\\\ r\\\\ n' : ' \\\\ n'
381+ String licenseHeader = licenseHeaderFile. getText(' UTF-8' ). replace(System . lineSeparator(), lineSeparator)
382+ tasks. register(' copyEclipseSettings' , Copy ) {
383+ mustRunAfter ' wipeEclipseSettings'
384+ // TODO: "package this up" for external builds
385+ from new File (project. rootDir, ' build-tools-internal/src/main/resources/eclipse.settings' )
386+ into ' .settings'
387+ filter { it. replaceAll(' @@LICENSE_HEADER_TEXT@@' , licenseHeader) }
388+ }
389+ // otherwise .settings is not nuked entirely
390+ tasks. register(' wipeEclipseSettings' , Delete ) {
391+ delete ' .settings'
392+ }
393+ tasks. named(' cleanEclipse' ) { dependsOn ' wipeEclipseSettings' }
394+ // otherwise the eclipse merging is *super confusing*
395+ tasks. named(' eclipse' ) { dependsOn ' cleanEclipse' , ' copyEclipseSettings' }
334396}
335397
336398tasks. named(" wrapper" ). configure {
@@ -439,18 +501,6 @@ tasks.named("assemble").configure {
439501 dependsOn gradle. includedBuild(' build-tools' ). task(' :assemble' )
440502}
441503
442- tasks. named(" cleanEclipse" ). configure {
443- dependsOn gradle. includedBuild(' build-conventions' ). task(' :cleanEclipse' )
444- dependsOn gradle. includedBuild(' build-tools' ). task(' :cleanEclipse' )
445- dependsOn gradle. includedBuild(' build-tools-internal' ). task(' :cleanEclipse' )
446- }
447-
448- tasks. named(" eclipse" ). configure {
449- dependsOn gradle. includedBuild(' build-conventions' ). task(' :eclipse' )
450- dependsOn gradle. includedBuild(' build-tools' ). task(' :eclipse' )
451- dependsOn gradle. includedBuild(' build-tools-internal' ). task(' :eclipse' )
452- }
453-
454504subprojects {
455505 project. ext. disableTasks = { String ... tasknames ->
456506 for (String taskname : tasknames) {
0 commit comments