@@ -30,6 +30,7 @@ defmodule Mix.Tasks.App.Start do
3030 * `--force` - forces compilation regardless of compilation times
3131 * `--temporary` - starts the application as temporary
3232 * `--permanent` - starts the application as permanent
33+ * `--preload-modules` - preloads all modules defined in applications
3334 * `--no-compile` - does not compile even if files require compilation
3435 * `--no-protocols` - does not load consolidated protocols
3536 * `--no-archives-check` - does not check archives
@@ -38,11 +39,18 @@ defmodule Mix.Tasks.App.Start do
3839 * `--no-start` - does not start applications after compilation
3940
4041 """
42+
43+ @ switches [
44+ permanent: :boolean ,
45+ temporary: :boolean ,
46+ preload_modules: :boolean
47+ ]
48+
4149 def run ( args ) do
4250 Mix.Project . get! ( )
4351 config = Mix.Project . config ( )
4452
45- { opts , _ , _ } = OptionParser . parse ( args , switches: [ permanent: :boolean , temporary: :boolean ] )
53+ { opts , _ , _ } = OptionParser . parse ( args , switches: @ switches )
4654 Mix.Task . run ( "loadpaths" , args )
4755
4856 unless "--no-compile" in args do
@@ -76,6 +84,13 @@ defmodule Mix.Tasks.App.Start do
7684 end
7785 else
7886 start ( Mix.Project . config ( ) , opts )
87+
88+ # If there is a build path, we will let the application
89+ # that owns the build path do the actual check
90+ unless config [ :build_path ] do
91+ loaded = loaded_applications ( opts )
92+ check_configured ( loaded )
93+ end
7994 end
8095
8196 :ok
@@ -97,13 +112,6 @@ defmodule Mix.Tasks.App.Start do
97112
98113 type = type ( config , opts )
99114 Enum . each ( apps , & ensure_all_started ( & 1 , type ) )
100-
101- # If there is a build path, we will let the application
102- # that owns the build path do the actual check
103- unless config [ :build_path ] do
104- check_configured ( )
105- end
106-
107115 :ok
108116 end
109117
@@ -146,25 +154,35 @@ defmodule Mix.Tasks.App.Start do
146154 end
147155 end
148156
149- defp check_configured ( ) do
157+ defp loaded_applications ( opts ) do
158+ preload_modules? = opts [ :preload_modules ]
159+
160+ for { app , _ , _ } <- Application . loaded_applications ( ) do
161+ if modules = preload_modules? && Application . spec ( app , :modules ) do
162+ :code . ensure_modules_loaded ( modules )
163+ end
164+
165+ app
166+ end
167+ end
168+
169+ defp check_configured ( loaded ) do
150170 configured = Mix.ProjectStack . configured_applications ( )
151- loaded = for { app , _ , _ } <- Application . loaded_applications ( ) , do: app
152171
153- _ =
154- for app <- configured -- loaded , :code . lib_dir ( app ) == { :error , :bad_name } do
155- Mix . shell ( ) . error ( """
156- You have configured application #{ inspect ( app ) } in your configuration
157- file, but the application is not available.
172+ for app <- configured -- loaded , :code . lib_dir ( app ) == { :error , :bad_name } do
173+ Mix . shell ( ) . error ( """
174+ You have configured application #{ inspect ( app ) } in your configuration file,
175+ but the application is not available.
158176
159- This usually means one of:
177+ This usually means one of:
160178
161179 1. You have not added the application as a dependency in a mix.exs file.
162180
163181 2. You are configuring an application that does not really exist.
164182
165- Please ensure #{ inspect ( app ) } exists or remove the configuration.
166- """ )
167- end
183+ Please ensure #{ inspect ( app ) } exists or remove the configuration.
184+ """ )
185+ end
168186
169187 :ok
170188 end
0 commit comments