4343import org .gradle .api .provider .Provider ;
4444import org .gradle .util .GradleVersion ;
4545
46- import java .lang .reflect .Method ;
4746import java .util .*;
4847import java .util .concurrent .atomic .AtomicInteger ;
4948
@@ -129,9 +128,6 @@ public Unit invoke(ResolvableDependencies resolvableDependencies) {
129128
130129 for (Dependency dependency : resolvableDependencies .getDependencies ()) {
131130 applyRecommendationToDependency (rsFactory , dependency , new ArrayList <ProjectDependency >(), project );
132-
133- // if project dependency, pull all first orders and apply recommendations if missing dependency versions
134- // dependency.getProjectConfiguration().allDependencies iterate and inspect them as well
135131 }
136132
137133 conf .getResolutionStrategy ().eachDependency (new Action <DependencyResolveDetails >() {
@@ -156,7 +152,7 @@ public void execute(DependencyResolveDetails details) {
156152 details .because ("Recommending version " + version + " for dependency " + coordinate + " via " + strategyText + "\n " +
157153 "\t with reasons: " + StringUtils .join (getReasonsRecursive (project ), ", " ));
158154 } else {
159- if (recommendationProviderContainer .getStrictMode ()) {
155+ if (recommendationProviderContainer .getStrictMode (). get () ) {
160156 String errorMessage = "Dependency " + details .getRequested ().getGroup () + ":" + details .getRequested ().getName () + " omitted version with no recommended version. General causes include a dependency being removed from the recommendation source or not applying a recommendation source to a project that depends on another project using a recommender." ;
161157 project .getLogger ().error (errorMessage );
162158 throw new GradleException (errorMessage );
@@ -174,11 +170,11 @@ public void execute(DependencyResolveDetails details) {
174170 }
175171
176172 private boolean isExcludedConfiguration (String confName ) {
177- if (recommendationProviderContainer .getExcludedConfigurations ().contains (confName )) {
173+ if (recommendationProviderContainer .getExcludedConfigurations ().get (). contains (confName )) {
178174 return true ;
179175 }
180176
181- for (String prefix : recommendationProviderContainer .getExcludedConfigurationPrefixes ()) {
177+ for (String prefix : recommendationProviderContainer .getExcludedConfigurationPrefixes (). get () ) {
182178 if (confName .startsWith (prefix )) {
183179 return true ;
184180 }
@@ -194,25 +190,11 @@ private void applyRecommendationToDependency(final RecommendationStrategyFactory
194190 ProjectDependency projectDependency = (ProjectDependency ) dependency ;
195191 if (!visited .contains (projectDependency )) {
196192 visited .add (projectDependency );
197- final Configuration [] configuration = new Configuration [1 ];
198- try {
199- ProjectDependency .class .getMethod ("getTargetConfiguration" );
200- String targetConfiguration = projectDependency .getTargetConfiguration () == null ? Dependency .DEFAULT_CONFIGURATION : projectDependency .getTargetConfiguration ();
201- Project dependencyProject = rootProject .findProject (projectDependency .getPath ());
202- if (dependencyProject != null ) {
203- configuration [0 ] = dependencyProject .getConfigurations ().getByName (targetConfiguration );
204- }
205-
206- } catch (NoSuchMethodException ignore ) {
207- try {
208- Method method = ProjectDependency .class .getMethod ("getProjectConfiguration" );
209- configuration [0 ] = (Configuration ) method .invoke (dependency );
210- } catch (Exception e ) {
211- throw new RuntimeException ("Unable to retrieve configuration for project dependency" , e );
212- }
213- }
214- if (configuration [0 ] != null ) {
215- DependencySet dependencies = configuration [0 ].getAllDependencies ();
193+ String targetConfiguration = projectDependency .getTargetConfiguration () == null ? Dependency .DEFAULT_CONFIGURATION : projectDependency .getTargetConfiguration ();
194+ Project dependencyProject = rootProject .findProject (projectDependency .getPath ());
195+ if (dependencyProject != null ) {
196+ Configuration configuration = dependencyProject .getConfigurations ().getByName (targetConfiguration );
197+ DependencySet dependencies = configuration .getAllDependencies ();
216198 for (Dependency dep : dependencies ) {
217199 applyRecommendationToDependency (factory , dep , visited , rootProject );
218200 }
0 commit comments