Skip to content

Commit

Permalink
Merge pull request #1 from nicolasb29/test-gradle-1
Browse files Browse the repository at this point in the history
Test gradle 1
  • Loading branch information
nicolasb29 authored Nov 29, 2024
2 parents bffb2fd + 3cb8a98 commit 6228b70
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions plugin/src/main/java/org/openrewrite/gradle/RewritePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void apply(Project project) {
);
});


// Because of how this Gradle has no criteria with which to select between variants of
// dependencies which expose differing capabilities. So those must be manually configured
try {
Expand Down Expand Up @@ -108,7 +109,7 @@ public void apply(Project project) {
// Old versions of Gradle don't have all of these attributes and that's OK
}

Provider<Set<File>> resolvedDependenciesProvider = project.provider(() -> getResolvedDependencies(rewriteConf));
Provider<Set<File>> resolvedDependenciesProvider = project.provider(() -> getResolvedDependencies(project, extension, rewriteConf));

TaskProvider<RewriteRunTask> rewriteRun = project.getTasks().register("rewriteRun", RewriteRunTask.class, task -> {
task.setExtension(extension);
Expand Down Expand Up @@ -190,12 +191,22 @@ private static void configureProject(Project project, RewriteExtension extension
});
}

private Set<File> getResolvedDependencies(Configuration rewriteConf) {
if (resolvedDependencies != null) {
return resolvedDependencies;
}
private Set<File> getResolvedDependencies(Project project, RewriteExtension extension, Configuration rewriteConf) {
if (resolvedDependencies == null) {
Dependency[] dependencies = Stream.concat(
knownRewriteDependencies(extension, project.getDependencies()).stream(),
rewriteConf.getDependencies().stream()
).toArray(Dependency[]::new);
// By using a detached configuration, we separate this dependency resolution from the rest of the project's
// configuration. This also means that Gradle has no criteria with which to select between variants of
// dependencies which expose differing capabilities. So those must be manually configured
Configuration detachedConf = project.getConfigurations().detachedConfiguration(dependencies);


resolvedDependencies = rewriteConf.resolve();

resolvedDependencies = detachedConf.resolve();

}
return resolvedDependencies;
}

Expand Down

0 comments on commit 6228b70

Please sign in to comment.