             "in such environments"
   end
 
-  defp mix_compile_deps(deps, apps_to_reload, compilers) do
-    for dep <- deps, dep.app in apps_to_reload do
-      Mix.Dep.in_dependency(dep, fn _ ->
-        mix_compile_unless_stale_config(compilers)
-      end)
-    end
-
-    :ok
-  end
-
-  defp mix_compile_project(nil, _, _), do: :ok
-
-  defp mix_compile_project(app, apps_to_reload, compilers) do
+  defp mix_compile_deps(deps, apps_to_reload, compilers, purge) do
+    Enum.reduce(deps, purge, fn dep, purge ->
+      if dep.app in apps_to_reload do
+        Mix.Dep.in_dependency(dep, fn _ ->
+          mix_compile_unless_stale_config(compilers, purge)
+        end)
+      else
+        purge
+      end
+    end)
+  end
+
+  defp mix_compile_project(nil, _, _, _), do: :ok
+
+  defp mix_compile_project(app, apps_to_reload, compilers, purge) do
     if app in apps_to_reload do
-      mix_compile_unless_stale_config(compilers)
-    end
-
-    :ok
-  end
-
-  defp mix_compile_unless_stale_config(compilers) do
+      mix_compile_unless_stale_config(compilers, purge)
+    else
+      purge
+    end
+  end
+
+  defp mix_compile_unless_stale_config(compilers, purge) do
     manifests = Mix.Tasks.Compile.Elixir.manifests()
     configs = Mix.Project.config_files()
 
     case Mix.Utils.extract_stale(configs, manifests) do
       [] ->
+        purge = purge.()
         mix_compile(compilers)
+        purge
 
       files ->
         raise """

  end

  defp mix_compile(compilers) do
    all = Mix.Project.config()[:compilers] || Mix.compilers()

    compilers =
      for compiler <- compilers, compiler in all do

  end

  defp mix_compile({:module, Mix.Task}, compilers, apps_to_reload) do
    config = Mix.Project.config()
    path = Mix.Project.consolidation_path(config)
    purge = fn -> purge_consolidated(path) end

    purge = mix_compile_deps(Mix.Dep.cached(), apps_to_reload, compilers, purge)
    mix_compile_project(config[:app], apps_to_reload, compilers, purge)
    Code.prepend_path(path)
    :ok
  end

  defp mix_compile({:error, _reason}, _, _) do
