Skip to content

Commit 5930cd7

Browse files
committed
Convert compose projects without cyclic dependencies to collections kmp structure
This is part of a multi-part effort to reland aosp/2532999 in parts. Change-Id: I66941bf4a21c605992da0f24bf57c5af1068205e
1 parent 6ab6b81 commit 5930cd7

File tree

9 files changed

+423
-391
lines changed

9 files changed

+423
-391
lines changed

compose/runtime/runtime-saveable/build.gradle

+61-63
Original file line numberDiff line numberDiff line change
@@ -15,87 +15,63 @@
1515
*/
1616

1717

18-
import androidx.build.AndroidXComposePlugin
18+
import androidx.build.KmpPlatformsKt
1919
import androidx.build.LibraryType
20-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2120

2221
plugins {
2322
id("AndroidXPlugin")
2423
id("AndroidXComposePlugin")
2524
id("com.android.library")
2625
}
2726

28-
AndroidXComposePlugin.applyAndConfigureKotlinPlugin(project)
27+
def desktopEnabled = KmpPlatformsKt.enableDesktop(project)
2928

30-
dependencies {
31-
32-
if(!AndroidXComposePlugin.isMultiplatformEnabled(project)) {
33-
/* When updating dependencies, make sure to make the an an analogous update in the
34-
corresponding block below */
35-
api project(":compose:runtime:runtime")
36-
api "androidx.annotation:annotation:1.1.0"
37-
38-
implementation(libs.kotlinStdlib)
39-
40-
testImplementation(libs.junit)
41-
testImplementation(libs.truth)
42-
testImplementation(libs.testCore)
43-
testImplementation(libs.testRules)
44-
45-
androidTestImplementation projectOrArtifact(':compose:ui:ui')
46-
androidTestImplementation projectOrArtifact(":compose:ui:ui-test-junit4")
47-
androidTestImplementation projectOrArtifact(":compose:test-utils")
48-
androidTestImplementation "androidx.fragment:fragment:1.3.0"
49-
androidTestImplementation projectOrArtifact(":activity:activity-compose")
50-
androidTestImplementation(libs.testUiautomator)
51-
androidTestImplementation(libs.testCore)
52-
androidTestImplementation(libs.testRules)
53-
androidTestImplementation(libs.testRunner)
54-
androidTestImplementation(libs.espressoCore)
55-
androidTestImplementation(libs.junit)
56-
androidTestImplementation(libs.truth)
57-
androidTestImplementation(libs.dexmakerMockito)
58-
androidTestImplementation(libs.mockitoCore)
59-
60-
lintPublish(project(":compose:runtime:runtime-saveable-lint"))
61-
62-
samples(projectOrArtifact(":compose:runtime:runtime-saveable:runtime-saveable-samples"))
63-
}
64-
}
65-
66-
if(AndroidXComposePlugin.isMultiplatformEnabled(project)) {
67-
androidXComposeMultiplatform {
68-
android()
69-
desktop()
70-
}
29+
androidXMultiplatform {
30+
android()
31+
if (desktopEnabled) desktop()
7132

72-
kotlin {
73-
/* When updating dependencies, make sure to make the an an analogous update in the
74-
corresponding block above */
75-
sourceSets {
76-
commonMain.dependencies {
33+
sourceSets {
34+
commonMain {
35+
dependencies {
7736
implementation(libs.kotlinStdlibCommon)
7837

7938
api project(":compose:runtime:runtime")
8039
}
40+
}
41+
42+
commonTest {
43+
dependencies {
44+
}
45+
}
8146

82-
androidMain.dependencies {
47+
jvmMain {
48+
dependencies {
49+
}
50+
}
51+
52+
53+
androidMain {
54+
dependsOn(jvmMain)
55+
dependencies {
8356
implementation(libs.kotlinStdlib)
8457
api "androidx.annotation:annotation:1.1.0"
8558
}
59+
}
8660

87-
// TODO(b/214407011): These dependencies leak into instrumented tests as well. If you
88-
// need to add Robolectric (which must be kept out of androidAndroidTest), use a top
89-
// level dependencies block instead:
90-
// `dependencies { testImplementation(libs.robolectric) }`
91-
androidTest.dependencies {
92-
implementation(libs.testRules)
93-
implementation(libs.testRunner)
94-
implementation(libs.junit)
95-
implementation(libs.truth)
61+
if (desktopEnabled) {
62+
desktopMain {
63+
dependsOn(jvmMain)
9664
}
65+
}
9766

98-
androidAndroidTest.dependencies {
67+
jvmTest {
68+
dependencies {
69+
}
70+
}
71+
72+
androidAndroidTest {
73+
dependsOn(jvmTest)
74+
dependencies {
9975
implementation project(':compose:ui:ui')
10076
implementation project(":compose:ui:ui-test-junit4")
10177
implementation project(":compose:test-utils")
@@ -112,10 +88,32 @@ if(AndroidXComposePlugin.isMultiplatformEnabled(project)) {
11288
implementation(libs.mockitoCore)
11389
}
11490
}
91+
92+
// TODO(b/214407011): These dependencies leak into instrumented tests as well. If you
93+
// need to add Robolectric (which must be kept out of androidAndroidTest), use a top
94+
// level dependencies block instead:
95+
// `dependencies { testImplementation(libs.robolectric) }`
96+
androidTest {
97+
dependsOn(jvmTest)
98+
dependencies {
99+
implementation(libs.testRules)
100+
implementation(libs.testRunner)
101+
implementation(libs.junit)
102+
implementation(libs.truth)
103+
}
104+
}
105+
106+
if (desktopEnabled) {
107+
desktopTest {
108+
dependsOn(jvmTest)
109+
}
110+
}
115111
}
116-
dependencies {
117-
samples(projectOrArtifact(":compose:runtime:runtime-saveable:runtime-saveable-samples"))
118-
}
112+
}
113+
114+
dependencies {
115+
samples(projectOrArtifact(":compose:runtime:runtime-saveable:runtime-saveable-samples"))
116+
lintPublish(project(":compose:runtime:runtime-saveable-lint"))
119117
}
120118

121119
androidx {

compose/test-utils/build.gradle

+70-68
Original file line numberDiff line numberDiff line change
@@ -14,100 +14,102 @@
1414
* limitations under the License.
1515
*/
1616

17-
import androidx.build.AndroidXComposePlugin
1817
import androidx.build.LibraryType
1918
import androidx.build.Publish
20-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2119

2220
plugins {
2321
id("AndroidXPlugin")
2422
id("com.android.library")
2523
id("AndroidXComposePlugin")
2624
}
2725

28-
AndroidXComposePlugin.applyAndConfigureKotlinPlugin(project)
29-
30-
dependencies {
31-
32-
if(!AndroidXComposePlugin.isMultiplatformEnabled(project)) {
33-
/*
34-
* When updating dependencies, make sure to make the an an analogous update in the
35-
* corresponding block below
36-
*/
37-
38-
api("androidx.activity:activity:1.2.0")
39-
api(projectOrArtifact(":compose:ui:ui-test-junit4"))
40-
api(project(":test:screenshot:screenshot"))
41-
42-
implementation(libs.kotlinStdlibCommon)
43-
implementation(projectOrArtifact(":compose:runtime:runtime"))
44-
implementation(projectOrArtifact(":compose:ui:ui-unit"))
45-
implementation(projectOrArtifact(":compose:ui:ui-graphics"))
46-
implementation("androidx.activity:activity-compose:1.3.1")
47-
// old version of common-java8 conflicts with newer version, because both have
48-
// DefaultLifecycleEventObserver.
49-
// Outside of androidx this is resolved via constraint added to lifecycle-common,
50-
// but it doesn't work in androidx.
51-
// See aosp/1804059
52-
implementation("androidx.lifecycle:lifecycle-common-java8:2.5.1")
53-
implementation(libs.testCore)
54-
implementation(libs.testRules)
55-
56-
// This has stub APIs for access to legacy Android APIs, so we don't want
57-
// any dependency on this module.
58-
compileOnly(projectOrArtifact(":compose:ui:ui-android-stubs"))
59-
60-
testImplementation(libs.truth)
61-
62-
androidTestImplementation(libs.truth)
63-
androidTestImplementation(projectOrArtifact(":compose:material:material"))
64-
}
65-
}
26+
def desktopEnabled = false // b/276387374 TODO: KmpPlatformsKt.enableDesktop(project)
6627

67-
if (AndroidXComposePlugin.isMultiplatformEnabled(project)) {
68-
androidXComposeMultiplatform {
69-
android()
70-
}
28+
androidXMultiplatform {
29+
android()
30+
if (desktopEnabled) desktop()
7131

72-
kotlin {
73-
/*
74-
* When updating dependencies, make sure to make the an an analogous update in the
75-
* corresponding block above
76-
*/
77-
sourceSets {
78-
commonMain.dependencies {
32+
sourceSets {
33+
commonMain {
34+
dependencies {
7935
implementation(libs.kotlinStdlibCommon)
8036
implementation(projectOrArtifact(":compose:runtime:runtime"))
8137
implementation(projectOrArtifact(":compose:ui:ui-unit"))
8238
implementation(projectOrArtifact(":compose:ui:ui-graphics"))
8339
implementation(projectOrArtifact(":compose:ui:ui-test-junit4"))
8440
}
41+
}
42+
androidMain.dependencies {
43+
api("androidx.activity:activity:1.2.0")
44+
implementation "androidx.activity:activity-compose:1.3.1"
45+
api(projectOrArtifact(":compose:ui:ui-test-junit4"))
46+
api(project(":test:screenshot:screenshot"))
47+
// This has stub APIs for access to legacy Android APIs, so we don't want
48+
// any dependency on this module.
49+
compileOnly(projectOrArtifact(":compose:ui:ui-android-stubs"))
50+
implementation(libs.testCore)
51+
implementation(libs.testRules)
52+
}
8553

86-
androidMain.dependencies {
87-
api("androidx.activity:activity:1.2.0")
88-
implementation "androidx.activity:activity-compose:1.3.1"
89-
api(projectOrArtifact(":compose:ui:ui-test-junit4"))
90-
api(project(":test:screenshot:screenshot"))
91-
// This has stub APIs for access to legacy Android APIs, so we don't want
92-
// any dependency on this module.
93-
compileOnly(projectOrArtifact(":compose:ui:ui-android-stubs"))
94-
implementation(libs.testCore)
95-
implementation(libs.testRules)
54+
commonTest {
55+
dependencies {
9656
}
57+
}
9758

98-
// TODO(b/214407011): These dependencies leak into instrumented tests as well. If you
99-
// need to add Robolectric (which must be kept out of androidAndroidTest), use a top
100-
// level dependencies block instead:
101-
// `dependencies { testImplementation(libs.robolectric) }`
102-
androidTest.dependencies {
103-
implementation(libs.truth)
59+
jvmMain {
60+
dependsOn(commonMain)
61+
dependencies {
10462
}
63+
}
64+
65+
66+
androidMain {
67+
dependsOn(jvmMain)
68+
dependencies {
69+
}
70+
}
10571

106-
androidAndroidTest.dependencies {
72+
if (desktopEnabled) {
73+
desktopMain {
74+
dependsOn(jvmMain)
75+
dependencies {
76+
}
77+
}
78+
}
79+
80+
jvmTest {
81+
dependsOn(commonTest)
82+
dependencies {
83+
}
84+
}
85+
86+
androidAndroidTest {
87+
dependsOn(jvmTest)
88+
dependencies {
10789
implementation(libs.truth)
10890
implementation(projectOrArtifact(":compose:material:material"))
10991
}
11092
}
93+
94+
// TODO(b/214407011): These dependencies leak into instrumented tests as well. If you
95+
// need to add Robolectric (which must be kept out of androidAndroidTest), use a top
96+
// level dependencies block instead:
97+
// `dependencies { testImplementation(libs.robolectric) }`
98+
androidTest {
99+
dependsOn(jvmTest)
100+
dependencies {
101+
implementation(libs.truth)
102+
}
103+
}
104+
105+
if (desktopEnabled) {
106+
desktopTest {
107+
dependsOn(jvmTest)
108+
dependsOn(desktopMain)
109+
dependencies {
110+
}
111+
}
112+
}
111113
}
112114
}
113115

0 commit comments

Comments
 (0)