diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CompilerPluginManager.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CompilerPluginManager.java index 7a946223b7e0..6f2ba751ac43 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CompilerPluginManager.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CompilerPluginManager.java @@ -51,6 +51,12 @@ private CompilerPluginManager(PackageCompilation compilation, } static CompilerPluginManager from(PackageCompilation compilation) { + // Skip initialization if the compiler plugins are already initialized for the project + if (!compilation.packageContext().project().compilerPluginContexts().isEmpty()) { + List compilerPluginContexts = + compilation.packageContext().project().compilerPluginContexts(); + return new CompilerPluginManager(compilation, compilerPluginContexts); + } // TODO We need to update the DependencyGraph API. Right now it is a mess PackageResolution packageResolution = compilation.getResolution(); ResolvedPackageDependency rootPkgNode = new ResolvedPackageDependency( @@ -191,10 +197,6 @@ private static List getDirectDependencies(ResolvedPackageDependency roo private static List initializePlugins(List compilerPlugins, PackageCompilation compilation) { - // Skip initialization if the compiler plugins are already initialized for the project - if (!compilation.packageContext().project().compilerPluginContexts().isEmpty()) { - return compilation.packageContext().project().compilerPluginContexts(); - } List compilerPluginContexts = new ArrayList<>(compilerPlugins.size()); for (CompilerPluginInfo compilerPluginInfo : compilerPlugins) { CompilerPluginCache pluginCache = diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java index 00b7172dad4b..0d59cd0fb03c 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java @@ -635,6 +635,8 @@ private Package createNewPackage() { this.project.setCurrentPackage(new Package(newPackageContext, this.project)); if (isOldDependencyGraphValid(oldPackage, this.project.currentPackage())) { this.project.currentPackage().packageContext().getResolution(oldResolution); + } else { + this.project.compilerPluginContexts().clear(); } CompilationOptions offlineCompOptions = CompilationOptions.builder().setOffline(true).build(); offlineCompOptions = offlineCompOptions.acceptTheirs(project.currentPackage().compilationOptions());