Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Organize gradle dependencies #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

error96num
Copy link
Owner

@error96num error96num commented Oct 4, 2024

Before

graph LR
%% app/build.gradle.kts
:app -.-> :feature:interests
:app -.-> :feature:foryou
:app -.-> :feature:bookmarks
:app -.-> :feature:topic
:app -.-> :feature:search
:app -.-> :feature:settings

:app -.-> :core:ui
:app -.-> :sync:work
:app -.-> :core:designsystem
:app -.-> :core:data
:app -.-> :core:analytics
:app -.-> :core:common

%% AndroidFeatureConventionPlugin
features[/"AndroidFeatureConventionPlugin"/]
features -.-> :core:ui
features -.-> :core:designsystem

%% feature/interests/build.gradle.kts
:feature:interests -.- features
:feature:interests -.-> :core:data
:feature:interests -.-> :core:domain

%% feature/foryou/build.gradle.kts
:feature:foryou -.- features
:feature:foryou -.-> :core:notifications
:feature:foryou -.-> :core:data
:feature:foryou -.-> :core:domain

%% feature/bookmarks/build.gradle.kts
:feature:bookmarks -.- features
:feature:bookmarks -.-> :core:data

%% feature/topic/build.gradle.kts
:feature:topic -.- features
:feature:bookmarks -.-> :core:data

%% feature/search/build.gradle.kts
:feature:search -.- features
:feature:search -.-> :core:data
:feature:search -.-> :core:domain

%% feature/settings/build.gradle.kts
:feature:settings -.- features
:feature:settings -.-> :core:data

%% core/common/build.gradle.kts
%% NOOP

%% core/ui/build.gradle.kts
:core:ui --> :core:analytics
:core:ui --> :core:designsystem
:core:ui --> :core:model
:core:ui --> :core:domain

%% core/designsystem/build.gradle.kts
%% NOOP

%% core/data/build.gradle.kts
:core:data -.-> :core:analytics
:core:data --> :core:common
:core:data --> :core:database
:core:data --> :core:datastore
:core:data --> :core:network
:core:data -.-> :core:notifications

%% core/model/build.gradle.kts
%% NOOP

%% core/analytics/build.gradle.kts
%% NOOP

%% core/domain/build.gradle.kts
:core:domain --> :core:data
:core:domain --> :core:model

%% core/database/build.gradle.kts
:core:database --> :core:model

%% core/datastore/build.gradle.kts
:core:datastore --> :core:model
:core:datastore -.-> :core:common

%% core/network/build.gradle.kts
:core:network --> :core:model
:core:network --> :core:common

%% core/notifications/build.gradle.kts
:core:notifications -.-> :core:common
:core:notifications --> :core:model

%% sync/work/build.gradle.kts
:sync:work -.-> :core:analytics
:sync:work -.-> :core:data
:sync:work -.-> :core:notifications
Loading

After

graph LR
%% app/build.gradle.kts
:app -.-> :feature:interests
:app -.-> :feature:foryou
:app -.-> :feature:bookmarks
:app -.-> :feature:topic
:app -.-> :feature:search
:app -.-> :feature:settings

:app -.-> :core:ui
:app -.-> :sync:work

%% sync/work/build.gradle.kts
:sync:work -.-> :core:analytics
:sync:work -.-> :core:data
:sync:work -.-> :core:notifications

%% AndroidFeatureConventionPlugin
features[/"AndroidFeatureConventionPlugin"/]
features -.-> :core:ui

%% feature/interests/build.gradle.kts
:feature:interests -.- features

%% feature/foryou/build.gradle.kts
:feature:foryou -.- features
:feature:foryou -.-> :core:notifications

%% feature/bookmarks/build.gradle.kts
:feature:bookmarks -.- features

%% feature/topic/build.gradle.kts
:feature:topic -.- features

%% feature/search/build.gradle.kts
:feature:search -.- features

%% feature/settings/build.gradle.kts
:feature:settings -.- features

%% core/common/build.gradle.kts
%% NOOP

%% core/ui/build.gradle.kts
:core:ui --> :core:designsystem
:core:ui ---> :core:domain

%% core/designsystem/build.gradle.kts
%% NOOP

%% core/domain/build.gradle.kts
:core:domain --> :core:data
:core:domain --> :core:analytics
:core:domain --> :core:model
:core:domain --> :core:common

%% core/model/build.gradle.kts
%% NOOP

%% core/analytics/build.gradle.kts
%% NOOP

%% core/data/build.gradle.kts
:core:data -.-> :core:analytics
:core:data -.-> :core:database
:core:data -.-> :core:datastore
:core:data -.-> :core:network
:core:data -.-> :core:notifications
:core:data --> :core:model
:core:data --> :core:common

%% core/database/build.gradle.kts
:core:database --> :core:model

%% core/datastore/build.gradle.kts
:core:datastore --> :core:model
:core:datastore --> :core:common

%% core/network/build.gradle.kts
:core:network --> :core:model
:core:network --> :core:common

%% core/notifications/build.gradle.kts
:core:notifications --> :core:common
:core:notifications --> :core:model
Loading

Comment on lines +35 to +37
implementation(projects.core.database)
implementation(projects.core.datastore)
implementation(projects.core.network)
Copy link
Owner Author

@error96num error96num Oct 4, 2024

Choose a reason for hiding this comment

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

データベースやネットワークスタックへは常にRepositoryを介してアクセスすべきであって、UI層・ドメイン層から直接データベースやネットワークスタックにアクセスすべきでない。
よって、:core:dataから先の依存は上方のモジュールに伝播させるべきでない

Comment on lines 28 to 31
api(projects.core.analytics)
api(projects.core.designsystem)
api(projects.core.model)
api(projects.core.domain)
Copy link
Owner Author

@error96num error96num Oct 4, 2024

Choose a reason for hiding this comment

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

:core:uiに依存するモジュールへ伝播させることによって、UI層のモジュール (:app, :feature:xxxx) はとりあえず:core:uiにだけ依存を定義すれば自ずとドメイン層やデザインシステムへの依存も持つことになる。

@@ -29,6 +29,7 @@ android {
dependencies {
ksp(libs.hilt.ext.compiler)

implementation(projects.core.datastore)
Copy link
Owner Author

Choose a reason for hiding this comment

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

本来は:core:dataだけに依存を持ってRepositoryを介してDataStoreにアクセスすべき。
実装がそうなっていないのでやむを得ず:core:datastoreに依存を持たせている。

@@ -25,9 +25,10 @@ android {

dependencies {
api(projects.core.data)
Copy link
Owner Author

Choose a reason for hiding this comment

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

:core:domainから:core:dataへの依存は上方に伝播させたままにする。
これはドメイン層がオプショナルであることを意味しており、UI層からデータ層の:core:dataにあるRepositoryへの直接アクセスを許容することを意味する。
参考:https://developer.android.com/topic/architecture/domain-layer?hl=ja

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant