Source:
<code>public static void configureConfigurations(Project project) { Configuration compileOnlyConfig = project.getConfigurations().getByName(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME); Configuration testImplementationConfig = project.getConfigurations().getByName(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME); testImplementationConfig.extendsFrom(compileOnlyConfig); project.getConfigurations() .getByName(JavaPlugin.TEST_COMPILE_CONFIGURATION_NAME) .getIncoming() .beforeResolve(resolvableDependencies -> { if (resolvableDependencies.getDependencies().size() > 0) { throw new GradleException( "Usage of configuration " + JavaPlugin.TEST_COMPILE_CONFIGURATION_NAME + " is no longer supported. Use " + JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME + " instead." ); } }); if (project.getPath().startsWith(":test:fixtures") || project.getPath().equals(":build-tools")) { return; } project.getConfigurations().all(configuration -> { if (configuration.getName().endsWith("Fixture")) { return; } configuration.resolutionStrategy(ResolutionStrategy::failOnVersionConflict); }); Consumer<String> disableTransitiveDeps = configName -> { Configuration config = project.getConfigurations().getByName(configName); config.getDependencies().all(dep -> { if (dep instanceof ModuleDependency && dep instanceof ProjectDependency == false && dep.getGroup().startsWith("org.elasticsearch") == false) { ((ModuleDependency) dep).setTransitive(false); } }); }; disableTransitiveDeps.accept(JavaPlugin.COMPILE_CONFIGURATION_NAME); <START> disableTransitiveDeps.accept(JavaPlugin.TEST_COMPILE_CONFIGURATION_NAME); <END> disableTransitiveDeps.accept(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME); disableTransitiveDeps.accept(JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME); disableTransitiveDeps.accept(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME); }</code><technical_language>remove this fail if add dependencies this configuration</technical_language>

Target:
public static void configureConfigurations(Project project) { Configuration compileOnlyConfig = project.getConfigurations().getByName(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME); Configuration testImplementationConfig = project.getConfigurations().getByName(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME); testImplementationConfig.extendsFrom(compileOnlyConfig); project.getConfigurations() .getByName(JavaPlugin.TEST_COMPILE_CONFIGURATION_NAME) .getIncoming() .beforeResolve(resolvableDependencies -> { if (resolvableDependencies.getDependencies().size() > 0) { throw new GradleException( "Usage of configuration " + JavaPlugin.TEST_COMPILE_CONFIGURATION_NAME + " is no longer supported. Use " + JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME + " instead." ); } }); if (project.getPath().startsWith(":test:fixtures") || project.getPath().equals(":build-tools")) { return; } project.getConfigurations().all(configuration -> { if (configuration.getName().endsWith("Fixture")) { return; } configuration.resolutionStrategy(ResolutionStrategy::failOnVersionConflict); }); Consumer<String> disableTransitiveDeps = configName -> { Configuration config = project.getConfigurations().getByName(configName); config.getDependencies().all(dep -> { if (dep instanceof ModuleDependency && dep instanceof ProjectDependency == false && dep.getGroup().startsWith("org.elasticsearch") == false) { ((ModuleDependency) dep).setTransitive(false); } }); }; disableTransitiveDeps.accept(JavaPlugin.COMPILE_CONFIGURATION_NAME); disableTransitiveDeps.accept(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME); disableTransitiveDeps.accept(JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME); disableTransitiveDeps.accept(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME); }