Skip to content

Commit 12e35c0

Browse files
committed
flattening the build structure
This makes the IDE happier about debugging unit tests.
1 parent c68257f commit 12e35c0

26 files changed

+173
-334
lines changed

.github/workflows/ci.yml

+37-4
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,13 @@ jobs:
126126
java-version: '17'
127127
check-latest: true
128128

129-
- name: Android Lint
130-
run: ./gradlew -p build-logic/delegate lint --no-build-cache --no-daemon --stacktrace
129+
- name: Android Lint in integration-tests
130+
working-directory: ./integration-tests
131+
run: ./gradlew lint
132+
133+
- name: Android Lint in sample
134+
working-directory: ./sample
135+
run: ./gradlew lint
131136

132137
- name: Upload Lint Results
133138
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4
@@ -205,10 +210,12 @@ jobs:
205210
check-latest: true
206211

207212
- name: Run integration tests
208-
run: ./gradlew -p build-logic/delegate test --no-build-cache --no-daemon --stacktrace -Doverride_kotlin=${{ matrix.kotlin-version }} -Doverride_config-generateDaggerFactoriesWithAnvil=false
213+
working-directory: ./integration-tests
214+
run: ./gradlew test --no-build-cache --no-daemon --stacktrace -Doverride_kotlin=${{ matrix.kotlin-version }} -Doverride_config-generateDaggerFactoriesWithAnvil=false
209215

210216
- name: Build the sample
211-
run: ./gradlew :delegate:sample:app:assembleDebug --no-build-cache --no-daemon --stacktrace -Doverride_kotlin=${{ matrix.kotlin-version }} -Doverride_config-generateDaggerFactoriesWithAnvil=false
217+
working-directory: ./sample
218+
run: ./gradlew assembleDebug --no-build-cache --no-daemon --stacktrace -Doverride_kotlin=${{ matrix.kotlin-version }} -Doverride_config-generateDaggerFactoriesWithAnvil=false
212219

213220
- name: Upload Test Results
214221
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4
@@ -278,6 +285,7 @@ jobs:
278285
profile : Galaxy Nexus
279286
ram-size : 4096M
280287
target: default
288+
working-directory: ./sample
281289
script: ./gradlew connectedCheck --no-build-cache --no-daemon --stacktrace
282290

283291
- name: Upload results
@@ -286,6 +294,30 @@ jobs:
286294
name: instrumentation-test-results
287295
path: ./**/build/reports/androidTests/connected/**
288296

297+
integration-tests:
298+
name: Integration tests
299+
runs-on: macos-latest
300+
timeout-minutes: 25
301+
302+
steps:
303+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
304+
- uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b # v4
305+
with:
306+
distribution: 'zulu'
307+
java-version: '17'
308+
check-latest: true
309+
310+
- name: Integration tests
311+
working-directory: ./integration-tests
312+
run: ./gradlew test allTests --stacktrace
313+
314+
- name: Upload Test Results
315+
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4
316+
if: ${{ failure() }}
317+
with:
318+
name: test-results-gradle-integration
319+
path: ./integration-tests/**/build/reports/tests/
320+
289321
gradle-integration-tests:
290322
name: Gradle integration tests
291323
runs-on: macos-latest
@@ -349,6 +381,7 @@ jobs:
349381
- test-gradle-plugin
350382
- kapt-for-dagger-factories
351383
- instrumentation-tests
384+
- integration-tests
352385
- gradle-integration-tests
353386
- gradle-wrapper-validation
354387
- build-benchmark-project

build-logic/conventions/src/main/kotlin/com/squareup/anvil/conventions/BasePlugin.kt

+3-61
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
package com.squareup.anvil.conventions
22

3-
import com.rickbusarow.kgx.buildDir
4-
import com.rickbusarow.kgx.extras
53
import com.rickbusarow.kgx.fromInt
64
import com.rickbusarow.kgx.getValue
75
import com.rickbusarow.kgx.javaExtension
86
import com.rickbusarow.kgx.provideDelegate
9-
import com.squareup.anvil.conventions.utils.isInAnvilBuild
10-
import com.squareup.anvil.conventions.utils.isInAnvilIncludedBuild
11-
import com.squareup.anvil.conventions.utils.isInAnvilRootBuild
127
import com.squareup.anvil.conventions.utils.libs
138
import org.gradle.api.JavaVersion
149
import org.gradle.api.Plugin
@@ -18,9 +13,9 @@ import org.gradle.api.tasks.testing.Test
1813
import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
1914
import org.gradle.jvm.toolchain.JavaLanguageVersion
2015
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
16+
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
2117
import org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper
2218
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
23-
import java.util.Properties
2419

2520
abstract class BasePlugin : Plugin<Project> {
2621

@@ -33,10 +28,6 @@ abstract class BasePlugin : Plugin<Project> {
3328

3429
val extension = target.extensions.create("conventions", ConventionsExtension::class.java)
3530

36-
if (!target.isInAnvilBuild()) {
37-
target.copyRootProjectGradleProperties()
38-
}
39-
4031
beforeApply(target)
4132

4233
target.plugins.apply("base")
@@ -45,8 +36,6 @@ abstract class BasePlugin : Plugin<Project> {
4536

4637
configureGradleProperties(target)
4738

48-
configureBuildDirs(target)
49-
5039
configureJava(target)
5140

5241
target.plugins.withType(KotlinBasePluginWrapper::class.java) {
@@ -55,29 +44,9 @@ abstract class BasePlugin : Plugin<Project> {
5544

5645
configureTests(target)
5746

58-
target.configurations.configureEach { config ->
59-
config.resolutionStrategy {
60-
it.force(target.libs.kotlin.metadata)
61-
}
62-
}
63-
6447
afterApply(target)
6548
}
6649

67-
/**
68-
* Included builds need the `GROUP` and `VERSION_NAME` values from the main build's
69-
* `gradle.properties`. We can't just use a symlink because Windows exists.
70-
* See https://github.com/square/anvil/pull/763#discussion_r1379563691
71-
*/
72-
private fun Project.copyRootProjectGradleProperties() {
73-
rootProject.file("../../gradle.properties")
74-
.inputStream()
75-
.use { Properties().apply { load(it) } }
76-
.forEach { key, value ->
77-
extras.set(key.toString(), value.toString())
78-
}
79-
}
80-
8150
private fun configureGradleProperties(target: Project) {
8251
target.version = target.property("VERSION_NAME") as String
8352
target.group = target.property("GROUP") as String
@@ -123,38 +92,11 @@ abstract class BasePlugin : Plugin<Project> {
12392
freeCompilerArgs.add("-Xexplicit-api=strict")
12493
}
12594

126-
jvmTarget.set(JvmTarget.fromInt(target.jvmTargetInt()))
127-
}
128-
}
129-
}
130-
131-
/**
132-
* The "anvil" projects exist in two different builds, they need two different build directories
133-
* so that there is no shared mutable state.
134-
*/
135-
private fun configureBuildDirs(target: Project) {
136-
137-
when {
138-
!target.isInAnvilBuild() -> return
95+
languageVersion.set(KotlinVersion.KOTLIN_2_0)
13996

140-
target.isInAnvilRootBuild() -> {
141-
target.layout.buildDirectory.set(target.file("build/root-build"))
142-
}
143-
144-
target.isInAnvilIncludedBuild() -> {
145-
target.layout.buildDirectory.set(target.file("build/included-build"))
97+
jvmTarget.set(JvmTarget.fromInt(target.jvmTargetInt()))
14698
}
14799
}
148-
149-
// Set the kase working directory ('<build directory>/kase/<test|gradleTest>') as a System property,
150-
// so that it's in the right place for projects with relocated directories.
151-
// https://github.com/rickbusarow/kase/blob/255db67f40d5ec83e31755bc9ce81b1a2b08cf11/kase/src/main/kotlin/com/rickbusarow/kase/files/HasWorkingDir.kt#L93-L96
152-
target.tasks.withType(Test::class.java).configureEach { task ->
153-
task.systemProperty(
154-
"kase.baseWorkingDir",
155-
target.buildDir().resolve("kase/${task.name}"),
156-
)
157-
}
158100
}
159101

160102
/**

build-logic/conventions/src/main/kotlin/com/squareup/anvil/conventions/CompositePlugin.kt

-123
This file was deleted.

build-logic/conventions/src/main/kotlin/com/squareup/anvil/conventions/RootPlugin.kt

+2-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.squareup.anvil.conventions
22

33
import com.rickbusarow.kgx.checkProjectIsRoot
44
import com.squareup.anvil.benchmark.BenchmarkPlugin
5-
import com.squareup.anvil.conventions.utils.isInAnvilRootBuild
5+
import com.squareup.anvil.conventions.utils.isInAnvilBuild
66
import com.squareup.anvil.conventions.utils.libs
77
import org.gradle.api.Project
88

@@ -12,15 +12,11 @@ open class RootPlugin : BasePlugin() {
1212

1313
target.checkProjectIsRoot { "RootPlugin must only be applied to the root project" }
1414

15-
if (target.isInAnvilRootBuild()) {
15+
if (target.isInAnvilBuild()) {
1616
target.plugins.apply(BenchmarkPlugin::class.java)
1717
}
1818

1919
target.plugins.apply("java-base")
20-
21-
if (target.gradle.includedBuilds.isNotEmpty()) {
22-
target.plugins.apply(CompositePlugin::class.java)
23-
}
2420
}
2521

2622
override fun afterApply(target: Project) {

build-logic/conventions/src/main/kotlin/com/squareup/anvil/conventions/utils/project.kt

-14
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,16 @@ import org.gradle.plugin.devel.GradlePluginDevelopmentExtension
2626
* - This build is included by the `:delegate` build in order to consume the gradle plugin.
2727
*
2828
* @see isInAnvilRootBuild to check if this project is part of the true root build
29-
* @see isInAnvilIncludedBuild to check if this project is part of the plugin included build
3029
*/
3130
internal fun Project.isInAnvilBuild() = rootProject.name == "anvil"
3231

3332
/**
3433
* Returns true if this project is in the root 'anvil' build, and it is the true root of the build.
3534
*
3635
* @see isInAnvilBuild
37-
* @see isInAnvilIncludedBuild
3836
*/
3937
internal fun Project.isInAnvilRootBuild() = isInAnvilBuild() && gradle.parent == null
4038

41-
/**
42-
* Returns true if this project is in the root 'anvil' build,
43-
* but it is not the true root of the build.
44-
* Unless something changes, that means it is included by the `:delegate` build.
45-
*/
46-
internal fun Project.isInAnvilIncludedBuild() = isInAnvilBuild() && gradle.parent != null
47-
48-
/**
49-
* Returns true if this project is included in the 'delegate' build.
50-
*/
51-
internal fun Project.isInDelegateBuild() = rootProject.name == "delegate"
52-
5339
internal val Project.gradlePublishingExtension: PublishingExtension
5440
get() = extensions.getByType(PublishingExtension::class.java)
5541

build-logic/delegate/gradle.properties

-1
This file was deleted.

0 commit comments

Comments
 (0)