 
   ## App loading helpers
 
-  defp load_apps(config, validate_compile_env?) do
+  defp load_apps(config, lib_path, validate_compile_env?) do
     {runtime, optional} = Mix.Tasks.Compile.App.project_apps(config)
     parent = self()
     opts = [ordered: false, timeout: :infinity]
+    deps = for dep <- Mix.Dep.cached(), into: %{}, do: {dep.app, true}
 
     stream_apps(runtime ++ optional)
-    |> Task.async_stream(&load_app(&1, parent, validate_compile_env?), opts)
+    |> Task.async_stream(&load_app(&1, parent, deps, lib_path, validate_compile_env?), opts)
     |> Stream.run()
   end
 
-  defp load_app(app, parent, validate_compile_env?) do
+  defp load_app(app, parent, deps, lib_path, validate_compile_env?) do
     children =
-      case load_app(app, validate_compile_env?) do
+      case load_app(app, deps, lib_path, validate_compile_env?) do
         :ok ->
           Application.spec(app, :applications) ++ Application.spec(app, :included_applications)
 

    Mix.Dep.cached()

    unless "--no-app-loading" in args do
      load_apps(config, validate_compile_env?)
    end

    result =

    Mix.Project.get!()
    config = Mix.Project.config()
    validate_compile_env? = "--no-validate-compile-env" not in args
    lib_path = Path.join(Mix.Project.build_path(config), "lib")

    # Make sure Mix.Dep is cached to avoid loading dependencies
    # during compilation. It is likely this will be invoked anyway,
