18
18
import org .elasticsearch .gradle .internal .ElasticsearchJavaPlugin ;
19
19
import org .elasticsearch .gradle .internal .InternalDistributionDownloadPlugin ;
20
20
import org .elasticsearch .gradle .internal .info .BuildParams ;
21
+ import org .elasticsearch .gradle .plugin .BasePluginBuildPlugin ;
21
22
import org .elasticsearch .gradle .plugin .PluginBuildPlugin ;
22
23
import org .elasticsearch .gradle .plugin .PluginPropertiesExtension ;
23
24
import org .elasticsearch .gradle .test .SystemPropertyCommandLineArgumentProvider ;
41
42
import org .gradle .api .tasks .util .PatternFilterable ;
42
43
43
44
import java .util .Collection ;
44
- import java .util .HashSet ;
45
+ import java .util .Iterator ;
46
+ import java .util .LinkedHashSet ;
45
47
import java .util .List ;
46
48
import java .util .Map ;
47
49
import java .util .Optional ;
@@ -89,19 +91,18 @@ public void apply(Project project) {
89
91
});
90
92
91
93
// Create configures for module and plugin dependencies
92
- Configuration modulesConfiguration = createPluginConfiguration (project , MODULES_CONFIGURATION , true );
93
- Configuration pluginsConfiguration = createPluginConfiguration (project , PLUGINS_CONFIGURATION , false );
94
- Configuration extractedPluginsConfiguration = createPluginConfiguration (project , EXTRACTED_PLUGINS_CONFIGURATION , true );
94
+ Configuration modulesConfiguration = createPluginConfiguration (project , MODULES_CONFIGURATION , true , false );
95
+ Configuration pluginsConfiguration = createPluginConfiguration (project , PLUGINS_CONFIGURATION , false , false );
96
+ Configuration extractedPluginsConfiguration = createPluginConfiguration (project , EXTRACTED_PLUGINS_CONFIGURATION , true , true );
95
97
extractedPluginsConfiguration .extendsFrom (pluginsConfiguration );
96
98
configureArtifactTransforms (project );
97
99
98
100
// For plugin and module projects, register the current project plugin bundle as a dependency
99
101
project .getPluginManager ().withPlugin ("elasticsearch.esplugin" , plugin -> {
100
102
if (GradleUtils .isModuleProject (project .getPath ())) {
101
- project .getDependencies ()
102
- .add (modulesConfiguration .getName (), project .getDependencies ().project (Map .of ("path" , project .getPath ())));
103
+ project .getDependencies ().add (MODULES_CONFIGURATION , getExplodedBundleDependency (project , project .getPath ()));
103
104
} else {
104
- project .getDependencies ().add (pluginsConfiguration . getName () , project .files ( project . getTasks (). named ( "bundlePlugin" )));
105
+ project .getDependencies ().add (PLUGINS_CONFIGURATION , getBundleZipTaskDependency ( project , project .getPath ( )));
105
106
}
106
107
107
108
});
@@ -158,15 +159,15 @@ private FileTree getDistributionFiles(ElasticsearchDistribution distribution, Ac
158
159
}
159
160
160
161
private void registerConfigurationInputs (Task task , Configuration configuration ) {
161
- task .getInputs ()
162
- .files (providerFactory .provider (() -> configuration .getAsFileTree ().filter (f -> f .getName ().endsWith (".jar" ))))
163
- .withPropertyName (configuration .getName () + "-classpath" )
164
- .withNormalizer (ClasspathNormalizer .class );
165
-
166
162
task .getInputs ()
167
163
.files (providerFactory .provider (() -> configuration .getAsFileTree ().filter (f -> f .getName ().endsWith (".jar" ) == false )))
168
164
.withPropertyName (configuration .getName () + "-files" )
169
165
.withPathSensitivity (PathSensitivity .RELATIVE );
166
+
167
+ task .getInputs ()
168
+ .files (providerFactory .provider (() -> configuration .getAsFileTree ().filter (f -> f .getName ().endsWith (".jar" ))))
169
+ .withPropertyName (configuration .getName () + "-classpath" )
170
+ .withNormalizer (ClasspathNormalizer .class );
170
171
}
171
172
172
173
private void registerDistributionInputs (Task task , ElasticsearchDistribution distribution ) {
@@ -192,36 +193,64 @@ private Optional<String> findModulePath(Project project, String pluginName) {
192
193
.map (Project ::getPath );
193
194
}
194
195
195
- private Configuration createPluginConfiguration (Project project , String name , boolean useExploded ) {
196
+ private Configuration createPluginConfiguration (Project project , String name , boolean useExploded , boolean isExtended ) {
196
197
return project .getConfigurations ().create (name , c -> {
197
198
if (useExploded ) {
198
199
c .attributes (a -> a .attribute (ArtifactTypeDefinition .ARTIFACT_TYPE_ATTRIBUTE , ArtifactTypeDefinition .DIRECTORY_TYPE ));
199
200
} else {
200
201
c .attributes (a -> a .attribute (ArtifactTypeDefinition .ARTIFACT_TYPE_ATTRIBUTE , ArtifactTypeDefinition .ZIP_TYPE ));
201
202
}
202
- c .withDependencies (dependencies -> {
203
- // Add dependencies of any modules
204
- Collection <Dependency > additionalDependencies = new HashSet <>();
205
- for (Dependency dependency : dependencies ) {
206
- if (dependency instanceof ProjectDependency projectDependency ) {
207
- List <String > extendedPlugins = projectDependency .getDependencyProject ()
208
- .getExtensions ()
209
- .getByType (PluginPropertiesExtension .class )
210
- .getExtendedPlugins ();
211
-
212
- for (String extendedPlugin : extendedPlugins ) {
213
- findModulePath (project , extendedPlugin ).ifPresent (
214
- modulePath -> additionalDependencies .add (project .getDependencies ().project (Map .of ("path" , modulePath )))
215
- );
203
+ if (isExtended == false ) {
204
+ c .withDependencies (dependencies -> {
205
+ // Add dependencies of any modules
206
+ Collection <Dependency > additionalDependencies = new LinkedHashSet <>();
207
+ for (Iterator <Dependency > iterator = dependencies .iterator (); iterator .hasNext ();) {
208
+ Dependency dependency = iterator .next ();
209
+ if (dependency instanceof ProjectDependency projectDependency ) {
210
+ Project dependencyProject = projectDependency .getDependencyProject ();
211
+ List <String > extendedPlugins = dependencyProject .getExtensions ()
212
+ .getByType (PluginPropertiesExtension .class )
213
+ .getExtendedPlugins ();
214
+
215
+ // Replace project dependency with explicit dependency on exploded configuration to workaround variant bug
216
+ if (projectDependency .getTargetConfiguration () == null ) {
217
+ iterator .remove ();
218
+ additionalDependencies .add (
219
+ useExploded
220
+ ? getExplodedBundleDependency (project , dependencyProject .getPath ())
221
+ : getBundleZipTaskDependency (project , dependencyProject .getPath ())
222
+ );
223
+ }
224
+
225
+ for (String extendedPlugin : extendedPlugins ) {
226
+ findModulePath (project , extendedPlugin ).ifPresent (
227
+ modulePath -> additionalDependencies .add (
228
+ useExploded
229
+ ? getExplodedBundleDependency (project , modulePath )
230
+ : getBundleZipTaskDependency (project , modulePath )
231
+ )
232
+ );
233
+ }
216
234
}
217
235
}
218
- }
219
236
220
- dependencies .addAll (additionalDependencies );
221
- });
237
+ dependencies .addAll (additionalDependencies );
238
+ });
239
+ }
222
240
});
223
241
}
224
242
243
+ private Dependency getExplodedBundleDependency (Project project , String projectPath ) {
244
+ return project .getDependencies ()
245
+ .project (Map .of ("path" , projectPath , "configuration" , BasePluginBuildPlugin .EXPLODED_BUNDLE_CONFIG ));
246
+ }
247
+
248
+ private Dependency getBundleZipTaskDependency (Project project , String projectPath ) {
249
+ Project dependencyProject = project .findProject (projectPath );
250
+ return project .getDependencies ()
251
+ .create (project .files (dependencyProject .getTasks ().named (BasePluginBuildPlugin .BUNDLE_PLUGIN_TASK_NAME )));
252
+ }
253
+
225
254
private void configureArtifactTransforms (Project project ) {
226
255
project .getDependencies ().registerTransform (UnzipTransform .class , transformSpec -> {
227
256
transformSpec .getFrom ().attribute (ArtifactTypeDefinition .ARTIFACT_TYPE_ATTRIBUTE , ArtifactTypeDefinition .ZIP_TYPE );
0 commit comments