diff --git a/plugin/src/main/java/org/openrewrite/gradle/AbstractRewriteTask.java b/plugin/src/main/java/org/openrewrite/gradle/AbstractRewriteTask.java index 3bb49156b..f1744d412 100644 --- a/plugin/src/main/java/org/openrewrite/gradle/AbstractRewriteTask.java +++ b/plugin/src/main/java/org/openrewrite/gradle/AbstractRewriteTask.java @@ -199,7 +199,8 @@ protected List parse(Project subproject, List styles, I .projectName(getProject().getName()) .buildToolVersion(GradleVersion.current().getVersion()) .vmRuntimeVersion(System.getProperty("java.runtime.version")) - .vmVendor(System.getProperty("java.vm.vendor")); + .vmVendor(System.getProperty("java.vm.vendor")) + .classpath(new HashSet<>()); Set sourceSets; if(javaConvention == null) { @@ -212,10 +213,6 @@ protected List parse(Project subproject, List styles, I List sourceFiles = new ArrayList<>(); for(SourceSet sourceSet : sourceSets) { - JavaProvenance javaProvenance = getRewrite() - .javaProvenanceBuilder(sharedProvenance) - .sourceSetName(sourceSet.getName()) - .build(); List javaPaths = sourceSet.getAllJava().getFiles().stream() .filter(it -> it.isFile() && it.getName().endsWith(".java")) @@ -228,6 +225,12 @@ protected List parse(Project subproject, List styles, I .map(AbstractRewriteTask::toRealPath) .collect(toList()); + JavaProvenance javaProvenance = getRewrite() + .javaProvenanceBuilder(sharedProvenance) + .sourceSetName(sourceSet.getName()) + .classpath(dependencyPaths) + .build(); + if(javaPaths.size() > 0) { getLog().lifecycle("Parsing " + javaPaths.size() + " Java files from " + sourceSet.getAllJava().getSourceDirectories().getAsPath()); Instant start = Instant.now(); diff --git a/plugin/src/main/java/org/openrewrite/gradle/RewriteReflectiveFacade.java b/plugin/src/main/java/org/openrewrite/gradle/RewriteReflectiveFacade.java index b9e35bac3..061e394a5 100755 --- a/plugin/src/main/java/org/openrewrite/gradle/RewriteReflectiveFacade.java +++ b/plugin/src/main/java/org/openrewrite/gradle/RewriteReflectiveFacade.java @@ -295,6 +295,9 @@ public class JavaProvenanceBuilder { private String sourceCompatibility; private String targetCompatibility; + //Classpath + private Iterable classpath; + //Publication private String publicationGroupId; private String publicationArtifactId; @@ -328,6 +331,10 @@ public JavaProvenanceBuilder targetCompatibility(String targetCompatibility) { this.targetCompatibility = targetCompatibility; return this; } + public JavaProvenanceBuilder classpath(Iterable classpath) { + this.classpath = classpath; + return this; + } public JavaProvenanceBuilder publicationGroupId(String publicationGroupId) { this.publicationGroupId = publicationGroupId; return this; @@ -366,11 +373,9 @@ public JavaProvenance build() { .newInstance(this.publicationGroupId, this.publicationArtifactId, this.publicationVersion); //Provenance - return new JavaProvenance(getClassLoader() - .loadClass("org.openrewrite.java.marker.JavaProvenance") - .getConstructor(UUID.class, String.class, String.class, buildTool.getClass(), javaVersion.getClass(), Set.class, publication.getClass()) - .newInstance(UUID.randomUUID(), this.projectName, this.sourceSetName, buildTool, javaVersion, Collections.emptySet(), publication)); - + Class c = getClassLoader().loadClass("org.openrewrite.java.marker.JavaProvenance"); + Method javaProvenanceBuilder = c.getMethod("build", String.class, String.class, buildTool.getClass(), javaVersion.getClass(), Iterable.class, publication.getClass()); + return new JavaProvenance(javaProvenanceBuilder.invoke(c.getName(), this.projectName, this.sourceSetName, buildTool, javaVersion, classpath, publication)); } catch (Exception e) { throw new RuntimeException(e); }