10
10
import org .gradle .api .Plugin ;
11
11
import org .gradle .api .Project ;
12
12
import org .gradle .api .initialization .Settings ;
13
+ import org .gradle .api .plugins .ExtensionAware ;
14
+ import org .gradle .api .plugins .ExtensionContainer ;
13
15
import org .gradle .api .provider .ProviderFactory ;
14
16
import org .gradle .caching .configuration .BuildCacheConfiguration ;
15
17
@@ -92,12 +94,12 @@ private void applySettingsPlugin(Settings settings) {
92
94
AtomicBoolean somePluginAlreadyConfigured = new AtomicBoolean (false );
93
95
settings .getPluginManager ().withPlugin ("com.gradle.develocity" , __ -> {
94
96
if (somePluginAlreadyConfigured .compareAndSet (false , true )) {
95
- applySettingsPlugin (new DevelocityConfigurationAdapter (settings . getExtensions (). getByName ( "develocity" ) ), providers , settings );
97
+ applySettingsPlugin (createDevelocityAdapter (settings ), providers , settings );
96
98
}
97
99
});
98
100
settings .getPluginManager ().withPlugin ("com.gradle.enterprise" , __ -> {
99
101
if (somePluginAlreadyConfigured .compareAndSet (false , true )) {
100
- applySettingsPlugin (new GradleEnterpriseExtensionAdapter (settings . getExtensions (). getByName ( "gradleEnterprise" ) ), providers , settings );
102
+ applySettingsPlugin (createDevelocityAdapter (settings ), providers , settings );
101
103
}
102
104
});
103
105
}
@@ -107,16 +109,27 @@ private void applyProjectPluginGradle5(Project project) {
107
109
AtomicBoolean somePluginAlreadyConfigured = new AtomicBoolean (false );
108
110
project .getPluginManager ().withPlugin ("com.gradle.develocity" , __ -> {
109
111
if (somePluginAlreadyConfigured .compareAndSet (false , true )) {
110
- applyProjectPlugin (project , new DevelocityConfigurationAdapter (project . getExtensions (). getByName ( "develocity" ) ));
112
+ applyProjectPlugin (project , createDevelocityAdapter (project ));
111
113
}
112
114
});
113
115
project .getPluginManager ().withPlugin ("com.gradle.build-scan" , __ -> {
114
116
if (somePluginAlreadyConfigured .compareAndSet (false , true )) {
115
- applyProjectPlugin (project , new GradleEnterpriseExtensionAdapter (project . getExtensions (). getByName ( "gradleEnterprise" ) ));
117
+ applyProjectPlugin (project , createDevelocityAdapter (project ));
116
118
}
117
119
});
118
120
}
119
121
122
+ private static <T extends ExtensionAware > DevelocityAdapter createDevelocityAdapter (T target ) {
123
+ ExtensionContainer extensions = target .getExtensions ();
124
+
125
+ Object develocityExtension = extensions .findByName ("develocity" );
126
+ if (develocityExtension != null ) {
127
+ return new DevelocityConfigurationAdapter (develocityExtension );
128
+ }
129
+
130
+ return new GradleEnterpriseExtensionAdapter (extensions .getByName ("gradleEnterprise" ));
131
+ }
132
+
120
133
private void applyProjectPluginGradle4 (Project project ) {
121
134
ensureRootProject (project );
122
135
project .getPluginManager ().withPlugin ("com.gradle.build-scan" ,
0 commit comments