From e0eabe072ee894858b9a6004ce84ba712cf962cc Mon Sep 17 00:00:00 2001 From: Souvlakia Date: Wed, 15 Oct 2025 16:21:36 +0300 Subject: [PATCH 1/6] draft --- .../src/mill/androidlib/AndroidModule.scala | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/libs/androidlib/src/mill/androidlib/AndroidModule.scala b/libs/androidlib/src/mill/androidlib/AndroidModule.scala index c2fad558330f..5959b4507bea 100644 --- a/libs/androidlib/src/mill/androidlib/AndroidModule.scala +++ b/libs/androidlib/src/mill/androidlib/AndroidModule.scala @@ -205,6 +205,18 @@ trait AndroidModule extends JavaModule { outer => }().flatten.distinct } + def androidDirectCompiledResources: T[Seq[PathRef]] = Task { + Task.traverse(moduleDepsChecked) { + case m: AndroidModule => + Task.Anon(m.androidCompiledModuleResources()) + case _ => + Task.Anon(Seq.empty) + }().flatten.distinct + } + + + def androidNonTransitiveRClass: Boolean = false + /** * Gets all the android resources (typically in res/ directory) * from the library dependencies using [[androidUnpackArchives]] @@ -575,6 +587,12 @@ trait AndroidModule extends JavaModule { outer => PathRef(Task.dest) } + def androidDepCompiledResources: T[Seq[PathRef]] = + androidNonTransitiveRClass match { + case true => Task { androidDirectCompiledResources() } + case false => Task { androidTransitiveCompiledResources() } + } + /** * Gets all the android resources from this module, * compiles them into flata files and collects @@ -602,7 +620,8 @@ trait AndroidModule extends JavaModule { outer => os.call(aapt2Compile ++ aapt2Args) } - androidTransitiveCompiledResources() ++ Seq(PathRef(Task.dest)) + + Seq(PathRef(Task.dest)) } /** @@ -613,7 +632,7 @@ trait AndroidModule extends JavaModule { outer => */ def androidLinkedResources: T[PathRef] = Task { val compiledLibResDir = androidCompiledLibResources().path - val moduleResDirs = androidCompiledModuleResources() + val moduleResDirs = (androidCompiledModuleResources() ++ androidDepCompiledResources()) .map(_.path) val filesToLink = os.walk(compiledLibResDir).filter(os.isFile(_)) ++ From 74a717f990384d1099917e4fddc5b7c842667804 Mon Sep 17 00:00:00 2001 From: Souvlakia Date: Fri, 17 Oct 2025 12:34:54 +0300 Subject: [PATCH 2/6] scaladoc --- .../src/mill/androidlib/AndroidModule.scala | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/libs/androidlib/src/mill/androidlib/AndroidModule.scala b/libs/androidlib/src/mill/androidlib/AndroidModule.scala index 5959b4507bea..0bd57343be88 100644 --- a/libs/androidlib/src/mill/androidlib/AndroidModule.scala +++ b/libs/androidlib/src/mill/androidlib/AndroidModule.scala @@ -214,9 +214,6 @@ trait AndroidModule extends JavaModule { outer => }().flatten.distinct } - - def androidNonTransitiveRClass: Boolean = false - /** * Gets all the android resources (typically in res/ directory) * from the library dependencies using [[androidUnpackArchives]] @@ -587,6 +584,24 @@ trait AndroidModule extends JavaModule { outer => PathRef(Task.dest) } + /** + * If true, only direct module dependencies will be used to + * compile android resources for R class generation. + * Corresponds to `android.nonTransitiveRClass` in Gradle. + * + * Default is false. + * + * When overridden, make sure to override all modules + * in the project to have consistent behavior. + */ + def androidNonTransitiveRClass: Boolean = false + + /** + * Gets the [[androidCompiledModuleResources]] from + * either direct or transitive module dependencies + * depending on the value of [[androidNonTransitiveRClass]] + * @return + */ def androidDepCompiledResources: T[Seq[PathRef]] = androidNonTransitiveRClass match { case true => Task { androidDirectCompiledResources() } @@ -596,7 +611,7 @@ trait AndroidModule extends JavaModule { outer => /** * Gets all the android resources from this module, * compiles them into flata files and collects - * transitive compiled resources from dependencies. + * compiled resources from dependencies. * @return a sequence of PathRef to the compiled resources */ def androidCompiledModuleResources: T[Seq[PathRef]] = Task { From d0c360d516503fa9eddaf8dc948d08a13e95d1de Mon Sep 17 00:00:00 2001 From: Souvlakia Date: Mon, 20 Oct 2025 10:26:15 +0300 Subject: [PATCH 3/6] make default true, like gradle >= 8 --- libs/androidlib/src/mill/androidlib/AndroidModule.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/androidlib/src/mill/androidlib/AndroidModule.scala b/libs/androidlib/src/mill/androidlib/AndroidModule.scala index 0bd57343be88..6e0cdc978a5a 100644 --- a/libs/androidlib/src/mill/androidlib/AndroidModule.scala +++ b/libs/androidlib/src/mill/androidlib/AndroidModule.scala @@ -589,12 +589,12 @@ trait AndroidModule extends JavaModule { outer => * compile android resources for R class generation. * Corresponds to `android.nonTransitiveRClass` in Gradle. * - * Default is false. + * Default is true. * * When overridden, make sure to override all modules * in the project to have consistent behavior. */ - def androidNonTransitiveRClass: Boolean = false + def androidNonTransitiveRClass: Boolean = true /** * Gets the [[androidCompiledModuleResources]] from From 0f8d68ab6ae27bf0fded4a0376f0bf6607940812 Mon Sep 17 00:00:00 2001 From: Souvlakia Date: Mon, 20 Oct 2025 10:53:44 +0300 Subject: [PATCH 4/6] change Task.traverse syntax --- libs/androidlib/src/mill/androidlib/AndroidAppModule.scala | 2 +- libs/androidlib/src/mill/androidlib/AndroidModule.scala | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/androidlib/src/mill/androidlib/AndroidAppModule.scala b/libs/androidlib/src/mill/androidlib/AndroidAppModule.scala index 1b99b692468e..a0db64148386 100644 --- a/libs/androidlib/src/mill/androidlib/AndroidAppModule.scala +++ b/libs/androidlib/src/mill/androidlib/AndroidAppModule.scala @@ -1070,7 +1070,7 @@ trait AndroidAppModule extends AndroidModule { outer => def androidTransitiveTestClasspath: T[Seq[PathRef]] = Task { Task.traverse(transitiveRunModuleDeps) { m => - Task.Anon(m.localRunClasspath()) + m.localRunClasspath }().flatten } diff --git a/libs/androidlib/src/mill/androidlib/AndroidModule.scala b/libs/androidlib/src/mill/androidlib/AndroidModule.scala index 6e0cdc978a5a..856ff18a03b0 100644 --- a/libs/androidlib/src/mill/androidlib/AndroidModule.scala +++ b/libs/androidlib/src/mill/androidlib/AndroidModule.scala @@ -199,7 +199,7 @@ trait AndroidModule extends JavaModule { outer => def androidTransitiveCompiledResources: T[Seq[PathRef]] = Task { Task.traverse(transitiveModuleRunModuleDeps) { case m: AndroidModule => - Task.Anon(m.androidCompiledModuleResources()) + m.androidCompiledModuleResources case _ => Task.Anon(Seq.empty) }().flatten.distinct @@ -208,7 +208,7 @@ trait AndroidModule extends JavaModule { outer => def androidDirectCompiledResources: T[Seq[PathRef]] = Task { Task.traverse(moduleDepsChecked) { case m: AndroidModule => - Task.Anon(m.androidCompiledModuleResources()) + m.androidCompiledModuleResources case _ => Task.Anon(Seq.empty) }().flatten.distinct @@ -525,7 +525,7 @@ trait AndroidModule extends JavaModule { outer => def androidTransitiveLibRClasspath: T[Seq[PathRef]] = Task { Task.traverse(transitiveModuleDeps) { case m: AndroidModule => - Task.Anon(m.androidLibRClasspath()) + m.androidLibRClasspath case _ => Task.Anon(Seq.empty[PathRef]) }().flatten From fbfa4e6af3de11aa4fa43350c6e787464c64a5a4 Mon Sep 17 00:00:00 2001 From: Souvlakia Date: Wed, 22 Oct 2025 10:50:17 +0300 Subject: [PATCH 5/6] make `androidTransitiveCompiledResources` not contain direct module dependencies --- .../src/mill/androidlib/AndroidModule.scala | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/libs/androidlib/src/mill/androidlib/AndroidModule.scala b/libs/androidlib/src/mill/androidlib/AndroidModule.scala index 856ff18a03b0..56ca500fd7a4 100644 --- a/libs/androidlib/src/mill/androidlib/AndroidModule.scala +++ b/libs/androidlib/src/mill/androidlib/AndroidModule.scala @@ -192,12 +192,12 @@ trait AndroidModule extends JavaModule { outer => } /** - * Gets all the compiled Android resources (typically in res/ directory) - * from the [[transitiveModuleRunModuleDeps]] + * Gets all the direct compiled android resources (typically in res/ directory) + * from the [[moduleDepsChecked]] * @return a sequence of PathRef to the compiled resources */ - def androidTransitiveCompiledResources: T[Seq[PathRef]] = Task { - Task.traverse(transitiveModuleRunModuleDeps) { + def androidDirectCompiledResources: T[Seq[PathRef]] = Task { + Task.traverse(moduleDepsChecked) { case m: AndroidModule => m.androidCompiledModuleResources case _ => @@ -205,8 +205,21 @@ trait AndroidModule extends JavaModule { outer => }().flatten.distinct } - def androidDirectCompiledResources: T[Seq[PathRef]] = Task { - Task.traverse(moduleDepsChecked) { + /** + * The transitive module dependencies of this module. + * This does not include direct dependencies, meaning + * these are only the dependencies of the dependencies. + */ + def androidTransitiveModuleDeps: Seq[JavaModule] = + transitiveModuleRunModuleDeps.filterNot(moduleDepsChecked.toSet) + + /** + * Gets all the transitive compiled Android resources (typically in res/ directory) + * from the [[androidTransitiveModuleDeps]] + * @return a sequence of PathRef to the compiled resources + */ + def androidTransitiveCompiledResources: T[Seq[PathRef]] = Task { + Task.traverse(androidTransitiveModuleDeps) { case m: AndroidModule => m.androidCompiledModuleResources case _ => @@ -598,14 +611,15 @@ trait AndroidModule extends JavaModule { outer => /** * Gets the [[androidCompiledModuleResources]] from - * either direct or transitive module dependencies - * depending on the value of [[androidNonTransitiveRClass]] + * from dependencies based on + * [[androidNonTransitiveRClass]] setting. * @return */ def androidDepCompiledResources: T[Seq[PathRef]] = androidNonTransitiveRClass match { case true => Task { androidDirectCompiledResources() } - case false => Task { androidTransitiveCompiledResources() } + case false => + Task { androidDirectCompiledResources() ++ androidTransitiveCompiledResources() } } /** From 2e5be823cbdf79610855abd916b6482d23a50694 Mon Sep 17 00:00:00 2001 From: Souvlakia Date: Wed, 22 Oct 2025 11:53:55 +0300 Subject: [PATCH 6/6] . --- libs/androidlib/src/mill/androidlib/AndroidModule.scala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/androidlib/src/mill/androidlib/AndroidModule.scala b/libs/androidlib/src/mill/androidlib/AndroidModule.scala index 56ca500fd7a4..9aacf28da088 100644 --- a/libs/androidlib/src/mill/androidlib/AndroidModule.scala +++ b/libs/androidlib/src/mill/androidlib/AndroidModule.scala @@ -210,8 +210,11 @@ trait AndroidModule extends JavaModule { outer => * This does not include direct dependencies, meaning * these are only the dependencies of the dependencies. */ - def androidTransitiveModuleDeps: Seq[JavaModule] = - transitiveModuleRunModuleDeps.filterNot(moduleDepsChecked.toSet) + def androidTransitiveModuleDeps: Seq[JavaModule] = { + val moduleDepsCheckedSet = moduleDepsChecked.toSet + val isDirectDependency = (m: JavaModule) => moduleDepsCheckedSet.contains(m) + transitiveModuleRunModuleDeps.filterNot(isDirectDependency) + } /** * Gets all the transitive compiled Android resources (typically in res/ directory)