Skip to content

Commit d9c7764

Browse files
authored
Enable preview features on native modules during IntelliJ import (#115698)
1 parent 8357887 commit d9c7764

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

build-tools-internal/src/main/groovy/elasticsearch.ide.gradle

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,36 @@ if (providers.systemProperty('idea.active').getOrNull() == 'true') {
122122
.findAll { it != null }
123123
}
124124

125+
// force IntelliJ to generate *.iml files for each imported module
126+
tasks.register("enableExternalConfiguration") {
127+
group = 'ide'
128+
description = 'Enable per-module *.iml files'
129+
130+
doLast {
131+
modifyXml('.idea/misc.xml') {xml ->
132+
def externalStorageConfig = xml.component.find { it.'@name' == 'ExternalStorageConfigurationManager' }
133+
if (externalStorageConfig) {
134+
xml.remove(externalStorageConfig)
135+
}
136+
}
137+
}
138+
}
139+
140+
// modifies the idea module config to enable preview features on 'elasticsearch-native' module
141+
tasks.register("enablePreviewFeatures") {
142+
group = 'ide'
143+
description = 'Enables preview features on native library module'
144+
dependsOn tasks.named("enableExternalConfiguration")
145+
146+
doLast {
147+
['main', 'test'].each { sourceSet ->
148+
modifyXml(".idea/modules/libs/native/elasticsearch.libs.elasticsearch-native.${sourceSet}.iml") { xml ->
149+
xml.component.find { it.'@name' == 'NewModuleRootManager' }?.'@LANGUAGE_LEVEL' = 'JDK_21_PREVIEW'
150+
}
151+
}
152+
}
153+
}
154+
125155
tasks.register('buildDependencyArtifacts') {
126156
group = 'ide'
127157
description = 'Builds artifacts needed as dependency for IDE modules'
@@ -149,7 +179,10 @@ if (providers.systemProperty('idea.active').getOrNull() == 'true') {
149179
testRunner = 'choose_per_test'
150180
}
151181
taskTriggers {
152-
afterSync tasks.named('configureIdeCheckstyle'), tasks.named('configureIdeaGradleJvm'), tasks.named('buildDependencyArtifacts')
182+
afterSync tasks.named('configureIdeCheckstyle'),
183+
tasks.named('configureIdeaGradleJvm'),
184+
tasks.named('buildDependencyArtifacts'),
185+
tasks.named('enablePreviewFeatures')
153186
}
154187
encodings {
155188
encoding = 'UTF-8'

0 commit comments

Comments
 (0)