Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/mix/lib/mix/dep/loader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,23 @@ defmodule Mix.Dep.Loader do
current environment, behavior can be overridden via options.
"""
def children(locked?) do
mix_children(Mix.Project.config(), locked?, []) ++ Mix.Dep.Umbrella.unloaded()
deps = mix_children(Mix.Project.config(), locked?, []) ++ Mix.Dep.Umbrella.unloaded()
# warn if project app matches a dep
warn_on_duplicate_app_name(Mix.Project.config()[:app], deps)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move it inside the with_scm_and_app, so we don't have to traverse deps twice!

Copy link
Contributor Author

@pckrishnadas88 pckrishnadas88 Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback!

I’ve moved the duplicate app name warning into with_scm_and_app. Please let me know if anything else is needed.


deps
end

def warn_on_duplicate_app_name(nil, _deps), do: :ok

def warn_on_duplicate_app_name(app, deps) do
dep_apps = Enum.map(deps, & &1.app)

if app in dep_apps do
Mix.shell().error(
"warning: the application name #{inspect(app)} is the same as one of its dependencies"
)
end
end

@doc """
Expand Down
23 changes: 1 addition & 22 deletions lib/mix/lib/mix/project.ex
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,7 @@ defmodule Mix.Project do
true -> "nofile"
end

config = push_config(module, app)
warn_on_duplicate_app_name(config)

case Mix.ProjectStack.push(module, config, file) do
case Mix.ProjectStack.push(module, push_config(module, app), file) do
:ok ->
:ok

Expand Down Expand Up @@ -1073,24 +1070,6 @@ defmodule Mix.Project do
end
end

defp warn_on_duplicate_app_name(config) do
app = config[:app]
deps = Keyword.get(config, :deps, [])

dep_apps =
Enum.map(deps, fn
{dep_app, _opts} -> dep_app
dep_app -> dep_app
end)

if app in dep_apps do
# Use Mix.shell().error to print to stderr
Mix.shell().error(
"warning: the application name #{inspect(app)} is the same as one of its dependencies"
)
end
end

defp default_config do
[
aliases: [],
Expand Down
35 changes: 13 additions & 22 deletions lib/mix/test/mix/project_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -161,30 +161,21 @@ defmodule Mix.ProjectTest do
end

test "warns when project app name matches a dependency" do
in_tmp("duplicate_app_name", fn ->
File.write!("mix.exs", """
defmodule DuplicateAppName.MixProject do
use Mix.Project

def project do
[
app: :foo,
version: "0.1.0",
deps: [{:foo, "~> 0.1.0"}]
]
end
end
""")
Mix.shell(Mix.Shell.Process)

Mix.Project.in_project(:foo, ".", fn _ ->
:ok
end)
app = :clash_app

assert_receive {:mix_shell, :error,
[
"warning: the application name :foo is the same as one of its dependencies"
]}
end)
deps = [
%Mix.Dep{app: :clash_app},
%Mix.Dep{app: :other_dep}
]

Mix.Dep.Loader.warn_on_duplicate_app_name(app, deps)

assert_received {:mix_shell, :error,
[
"warning: the application name :clash_app is the same as one of its dependencies"
]}
end

test "in_project prints nice error message if fails to load file", context do
Expand Down
Loading