From 1721c42e997f76b1f642095fc7daa6d2635d1fc1 Mon Sep 17 00:00:00 2001 From: Rick Busarow Date: Thu, 23 Jan 2025 14:29:49 -0600 Subject: [PATCH] flattening the build structure This makes the IDE happier about debugging unit tests. --- .github/workflows/ci.yml | 41 +++++- .../squareup/anvil/conventions/BasePlugin.kt | 64 +-------- .../anvil/conventions/CompositePlugin.kt | 123 ------------------ .../squareup/anvil/conventions/RootPlugin.kt | 8 +- .../anvil/conventions/utils/project.kt | 14 -- build-logic/delegate/gradle.properties | 1 - build-logic/delegate/settings.gradle.kts | 110 ---------------- .../build.gradle.kts | 3 +- .../code-generator-tests/build.gradle.kts | 2 +- integration-tests/gradle.properties | 1 + .../gradle/wrapper/gradle-wrapper.jar | 1 + .../gradle/wrapper/gradle-wrapper.properties | 1 + integration-tests/gradlew | 1 + integration-tests/gradlew.bat | 1 + .../mpp/android-module/build.gradle.kts | 2 +- integration-tests/settings.gradle.kts | 59 +++++++++ integration-tests/tests/build.gradle.kts | 2 +- sample/app/build.gradle.kts | 4 +- sample/gradle.properties | 1 + sample/gradle/wrapper/gradle-wrapper.jar | 1 + .../gradle/wrapper/gradle-wrapper.properties | 1 + sample/gradlew | 1 + sample/gradlew.bat | 1 + sample/library/build.gradle.kts | 2 +- sample/settings.gradle.kts | 55 ++++++++ settings.gradle.kts | 7 - 26 files changed, 173 insertions(+), 334 deletions(-) delete mode 100644 build-logic/conventions/src/main/kotlin/com/squareup/anvil/conventions/CompositePlugin.kt delete mode 100644 build-logic/delegate/gradle.properties delete mode 100644 build-logic/delegate/settings.gradle.kts rename {build-logic/delegate => integration-tests}/build.gradle.kts (90%) create mode 120000 integration-tests/gradle.properties create mode 120000 integration-tests/gradle/wrapper/gradle-wrapper.jar create mode 120000 integration-tests/gradle/wrapper/gradle-wrapper.properties create mode 120000 integration-tests/gradlew create mode 120000 integration-tests/gradlew.bat create mode 100644 integration-tests/settings.gradle.kts create mode 120000 sample/gradle.properties create mode 120000 sample/gradle/wrapper/gradle-wrapper.jar create mode 120000 sample/gradle/wrapper/gradle-wrapper.properties create mode 120000 sample/gradlew create mode 120000 sample/gradlew.bat create mode 100644 sample/settings.gradle.kts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 91c27dc90..47736d577 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -126,8 +126,13 @@ jobs: java-version: '17' check-latest: true - - name: Android Lint - run: ./gradlew -p build-logic/delegate lint --no-build-cache --no-daemon --stacktrace + - name: Android Lint in integration-tests + working-directory: ./integration-tests + run: ./gradlew lint + + - name: Android Lint in sample + working-directory: ./sample + run: ./gradlew lint - name: Upload Lint Results uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4 @@ -205,10 +210,12 @@ jobs: check-latest: true - name: Run integration tests - run: ./gradlew -p build-logic/delegate test --no-build-cache --no-daemon --stacktrace -Doverride_kotlin=${{ matrix.kotlin-version }} -Doverride_config-generateDaggerFactoriesWithAnvil=false + working-directory: ./integration-tests + run: ./gradlew -p test --no-build-cache --no-daemon --stacktrace -Doverride_kotlin=${{ matrix.kotlin-version }} -Doverride_config-generateDaggerFactoriesWithAnvil=false - name: Build the sample - run: ./gradlew :delegate:sample:app:assembleDebug --no-build-cache --no-daemon --stacktrace -Doverride_kotlin=${{ matrix.kotlin-version }} -Doverride_config-generateDaggerFactoriesWithAnvil=false + working-directory: ./sample + run: ./gradlew assembleDebug --no-build-cache --no-daemon --stacktrace -Doverride_kotlin=${{ matrix.kotlin-version }} -Doverride_config-generateDaggerFactoriesWithAnvil=false - name: Upload Test Results uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4 @@ -278,6 +285,7 @@ jobs: profile : Galaxy Nexus ram-size : 4096M target: default + working-directory: ./sample script: ./gradlew connectedCheck --no-build-cache --no-daemon --stacktrace - name: Upload results @@ -286,6 +294,30 @@ jobs: name: instrumentation-test-results path: ./**/build/reports/androidTests/connected/** + integration-tests: + name: Integration tests + runs-on: macos-latest + timeout-minutes: 25 + + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + - uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b # v4 + with: + distribution: 'zulu' + java-version: '17' + check-latest: true + + - name: Integration tests + working-directory: ./integration-tests + run: ./gradlew test jvmTest android --stacktrace + + - name: Upload Test Results + uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4 + if: ${{ failure() }} + with: + name: test-results-gradle-integration + path: ./integration-tests/**/build/reports/tests/ + gradle-integration-tests: name: Gradle integration tests runs-on: macos-latest @@ -349,6 +381,7 @@ jobs: - test-gradle-plugin - kapt-for-dagger-factories - instrumentation-tests + - integration-tests - gradle-integration-tests - gradle-wrapper-validation - build-benchmark-project diff --git a/build-logic/conventions/src/main/kotlin/com/squareup/anvil/conventions/BasePlugin.kt b/build-logic/conventions/src/main/kotlin/com/squareup/anvil/conventions/BasePlugin.kt index 7ef8e6414..f1c522a8b 100644 --- a/build-logic/conventions/src/main/kotlin/com/squareup/anvil/conventions/BasePlugin.kt +++ b/build-logic/conventions/src/main/kotlin/com/squareup/anvil/conventions/BasePlugin.kt @@ -1,14 +1,9 @@ package com.squareup.anvil.conventions -import com.rickbusarow.kgx.buildDir -import com.rickbusarow.kgx.extras import com.rickbusarow.kgx.fromInt import com.rickbusarow.kgx.getValue import com.rickbusarow.kgx.javaExtension import com.rickbusarow.kgx.provideDelegate -import com.squareup.anvil.conventions.utils.isInAnvilBuild -import com.squareup.anvil.conventions.utils.isInAnvilIncludedBuild -import com.squareup.anvil.conventions.utils.isInAnvilRootBuild import com.squareup.anvil.conventions.utils.libs import org.gradle.api.JavaVersion import org.gradle.api.Plugin @@ -18,9 +13,9 @@ import org.gradle.api.tasks.testing.Test import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL import org.gradle.jvm.toolchain.JavaLanguageVersion import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.dsl.KotlinVersion import org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import java.util.Properties abstract class BasePlugin : Plugin { @@ -33,10 +28,6 @@ abstract class BasePlugin : Plugin { val extension = target.extensions.create("conventions", ConventionsExtension::class.java) - if (!target.isInAnvilBuild()) { - target.copyRootProjectGradleProperties() - } - beforeApply(target) target.plugins.apply("base") @@ -45,8 +36,6 @@ abstract class BasePlugin : Plugin { configureGradleProperties(target) - configureBuildDirs(target) - configureJava(target) target.plugins.withType(KotlinBasePluginWrapper::class.java) { @@ -55,29 +44,9 @@ abstract class BasePlugin : Plugin { configureTests(target) - target.configurations.configureEach { config -> - config.resolutionStrategy { - it.force(target.libs.kotlin.metadata) - } - } - afterApply(target) } - /** - * Included builds need the `GROUP` and `VERSION_NAME` values from the main build's - * `gradle.properties`. We can't just use a symlink because Windows exists. - * See https://github.com/square/anvil/pull/763#discussion_r1379563691 - */ - private fun Project.copyRootProjectGradleProperties() { - rootProject.file("../../gradle.properties") - .inputStream() - .use { Properties().apply { load(it) } } - .forEach { key, value -> - extras.set(key.toString(), value.toString()) - } - } - private fun configureGradleProperties(target: Project) { target.version = target.property("VERSION_NAME") as String target.group = target.property("GROUP") as String @@ -123,38 +92,11 @@ abstract class BasePlugin : Plugin { freeCompilerArgs.add("-Xexplicit-api=strict") } - jvmTarget.set(JvmTarget.fromInt(target.jvmTargetInt())) - } - } - } - - /** - * The "anvil" projects exist in two different builds, they need two different build directories - * so that there is no shared mutable state. - */ - private fun configureBuildDirs(target: Project) { - - when { - !target.isInAnvilBuild() -> return + languageVersion.set(KotlinVersion.KOTLIN_2_0) - target.isInAnvilRootBuild() -> { - target.layout.buildDirectory.set(target.file("build/root-build")) - } - - target.isInAnvilIncludedBuild() -> { - target.layout.buildDirectory.set(target.file("build/included-build")) + jvmTarget.set(JvmTarget.fromInt(target.jvmTargetInt())) } } - - // Set the kase working directory ('/kase/') as a System property, - // so that it's in the right place for projects with relocated directories. - // https://github.com/rickbusarow/kase/blob/255db67f40d5ec83e31755bc9ce81b1a2b08cf11/kase/src/main/kotlin/com/rickbusarow/kase/files/HasWorkingDir.kt#L93-L96 - target.tasks.withType(Test::class.java).configureEach { task -> - task.systemProperty( - "kase.baseWorkingDir", - target.buildDir().resolve("kase/${task.name}"), - ) - } } /** diff --git a/build-logic/conventions/src/main/kotlin/com/squareup/anvil/conventions/CompositePlugin.kt b/build-logic/conventions/src/main/kotlin/com/squareup/anvil/conventions/CompositePlugin.kt deleted file mode 100644 index 3539ae4cc..000000000 --- a/build-logic/conventions/src/main/kotlin/com/squareup/anvil/conventions/CompositePlugin.kt +++ /dev/null @@ -1,123 +0,0 @@ -package com.squareup.anvil.conventions - -import com.rickbusarow.kgx.checkProjectIsRoot -import com.squareup.anvil.conventions.utils.hasTask -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.composite.internal.DefaultIncludedBuild -import org.gradle.composite.internal.DefaultIncludedBuild.IncludedBuildImpl -import org.gradle.internal.DefaultTaskExecutionRequest - -/** - * This plugin propagates unqualified task invocations to included builds. Conceptually, it - * behaves as if the included builds were subprojects of the root build. - * - * For example, if the root project has an included build named `:included`, - * and `:included` has a task named `:included:foo`, then the root project can invoke - * `./gradlew foo` and the task `:included:foo` will be executed. - */ -class CompositePlugin : Plugin { - - override fun apply(target: Project) { - - target.checkProjectIsRoot() - require(target.gradle.includedBuilds.isNotEmpty()) { - "Only apply the 'composite' plugin to a root project with included builds. " + - "This project has no included builds, " + - "so the plugin would just waste time searching the task graph." - } - - target.gradle.projectsEvaluated { gradle -> - - val oldRequests = gradle.startParameter.taskRequests - - val newRequests = oldRequests.map { request -> - - val originalSplit = request.args.splitTaskArgs() - - val taskPaths = originalSplit.mapTo(mutableSetOf()) { it.first() } - - val includedProjects = gradle.includedBuilds - .asSequence() - .filterIsInstance() - .flatMap { impl -> - - val defaultIncludedBuild = impl.target as DefaultIncludedBuild - - defaultIncludedBuild.mutableModel.projectRegistry.allProjects - } - - val newSplit = originalSplit.flatMap { taskWithArgs -> - - val taskName = taskWithArgs.first() - - if (taskName.startsWith(':')) { - // qualified task names aren't propagated to included builds - return@flatMap listOf(taskWithArgs) - } - - // Don't propagate help tasks - if (taskName == "help") return@flatMap listOf(taskWithArgs) - - val included = includedProjects.mapNotNull { includedProject -> - - val includedPath = "${includedProject.identityPath}:$taskName" - - // Don't include tasks that are already in the task graph - if (taskPaths.contains(includedPath)) return@mapNotNull null - - if (!includedProject.hasTask(taskName)) return@mapNotNull null - - target.logger.quiet("The task $taskName will delegate to $includedPath") - - buildList { - add(includedPath) - addAll(taskWithArgs.subList(1, taskWithArgs.size)) - } - } - - buildList { - - // Looks to see if any project in this build has a task with this name. - val resolvedInRootBuild = target.allprojects.any { it.hasTask(taskName) } - - if (resolvedInRootBuild) { - add(taskWithArgs) - } - addAll(included) - } - } - - DefaultTaskExecutionRequest.of(newSplit.flatten(), request.projectPath, request.rootDir) - } - - gradle.startParameter.setTaskRequests(newRequests) - } - } - - private fun List.splitTaskArgs(): List> { - - val toSplit = this@splitTaskArgs - - if (toSplit.isEmpty()) return emptyList() - - val args = toSplit.subList(1, toSplit.size) - - return args - .fold( - mutableListOf(mutableListOf(toSplit[0])), - ) { acc: MutableList>, arg -> - - val lastArg = acc.last().last() - - when { - arg.startsWith('-') -> acc.last().add(arg) - // Matches 'foo' in `./gradlew test --tests foo` - // Does not match 'foo' in `./gradlew test --tests=foo` - lastArg.startsWith('-') && !lastArg.contains('=') -> acc.last().add(arg) - else -> acc.add(mutableListOf(arg)) - } - acc - } - } -} diff --git a/build-logic/conventions/src/main/kotlin/com/squareup/anvil/conventions/RootPlugin.kt b/build-logic/conventions/src/main/kotlin/com/squareup/anvil/conventions/RootPlugin.kt index ca6aac9ed..2313812ac 100644 --- a/build-logic/conventions/src/main/kotlin/com/squareup/anvil/conventions/RootPlugin.kt +++ b/build-logic/conventions/src/main/kotlin/com/squareup/anvil/conventions/RootPlugin.kt @@ -2,7 +2,7 @@ package com.squareup.anvil.conventions import com.rickbusarow.kgx.checkProjectIsRoot import com.squareup.anvil.benchmark.BenchmarkPlugin -import com.squareup.anvil.conventions.utils.isInAnvilRootBuild +import com.squareup.anvil.conventions.utils.isInAnvilBuild import com.squareup.anvil.conventions.utils.libs import org.gradle.api.Project @@ -12,15 +12,11 @@ open class RootPlugin : BasePlugin() { target.checkProjectIsRoot { "RootPlugin must only be applied to the root project" } - if (target.isInAnvilRootBuild()) { + if (target.isInAnvilBuild()) { target.plugins.apply(BenchmarkPlugin::class.java) } target.plugins.apply("java-base") - - if (target.gradle.includedBuilds.isNotEmpty()) { - target.plugins.apply(CompositePlugin::class.java) - } } override fun afterApply(target: Project) { diff --git a/build-logic/conventions/src/main/kotlin/com/squareup/anvil/conventions/utils/project.kt b/build-logic/conventions/src/main/kotlin/com/squareup/anvil/conventions/utils/project.kt index 8ea2195d4..09138102f 100644 --- a/build-logic/conventions/src/main/kotlin/com/squareup/anvil/conventions/utils/project.kt +++ b/build-logic/conventions/src/main/kotlin/com/squareup/anvil/conventions/utils/project.kt @@ -26,7 +26,6 @@ import org.gradle.plugin.devel.GradlePluginDevelopmentExtension * - This build is included by the `:delegate` build in order to consume the gradle plugin. * * @see isInAnvilRootBuild to check if this project is part of the true root build - * @see isInAnvilIncludedBuild to check if this project is part of the plugin included build */ internal fun Project.isInAnvilBuild() = rootProject.name == "anvil" @@ -34,22 +33,9 @@ internal fun Project.isInAnvilBuild() = rootProject.name == "anvil" * Returns true if this project is in the root 'anvil' build, and it is the true root of the build. * * @see isInAnvilBuild - * @see isInAnvilIncludedBuild */ internal fun Project.isInAnvilRootBuild() = isInAnvilBuild() && gradle.parent == null -/** - * Returns true if this project is in the root 'anvil' build, - * but it is not the true root of the build. - * Unless something changes, that means it is included by the `:delegate` build. - */ -internal fun Project.isInAnvilIncludedBuild() = isInAnvilBuild() && gradle.parent != null - -/** - * Returns true if this project is included in the 'delegate' build. - */ -internal fun Project.isInDelegateBuild() = rootProject.name == "delegate" - internal val Project.gradlePublishingExtension: PublishingExtension get() = extensions.getByType(PublishingExtension::class.java) diff --git a/build-logic/delegate/gradle.properties b/build-logic/delegate/gradle.properties deleted file mode 100644 index 5bac8ac50..000000000 --- a/build-logic/delegate/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -android.useAndroidX=true diff --git a/build-logic/delegate/settings.gradle.kts b/build-logic/delegate/settings.gradle.kts deleted file mode 100644 index 0665a076e..000000000 --- a/build-logic/delegate/settings.gradle.kts +++ /dev/null @@ -1,110 +0,0 @@ -pluginManagement { - repositories { - google() - gradlePluginPortal() - mavenCentral() - } - - includeBuild("../settings") - includeBuild("../conventions") - - /* - * Only include the root build here if this build is being included. If this build is the root, - * then the root build will be included below (not as a plugin build). - * - * When this build is included by the root build, the graph winds up as: - * - * ┌──────────────────────────┐ - * │ anvil project │ - * │ (root directory) │ - * │ ┌─────────────────┐ │ - * ┌──────────────────────┼────│ : (actual root) │ │ - * ▼ │ └─────────────────┘ │ - * ┌────────────────────────────────────────┐ │ │ - * │ :delegate │ │ │ - * │ build-logic/delegate │ │ │ - * │ ┌────────────┐ ┌───────────────────┐ │ │ │ - * │ │ :sample │ │:integration-tests │ │ │ │ - * │ └────────────┘ └───────────────────┘ │ │ │ - * └────────────────────────────────────────┘ │ ┌───────────────────┐ │ - * │ │ └───────────────────┼──▶│ :anvil (included) │ │ - * │ │ │ └───────────────────┘ │ - * │ └─────────────┐ └──────────────────────────┘ - * │ │ ┌──────────────────┘ │ - * │ ▼ ▼ │ - * │ ┌───────────────────────────┐ │ - * │ │ :conventions │ │ - * │ │ build-logic/conventions │ │ - * │ └───────────────────────────┘ │ - * │ ┌───────────────┘ │ - * │ │ ┌─────────────────────────────────┘ - * ▼ ▼ ▼ - * ┌───────────────────────────┐ - * │ :settings │ - * │ build-logic/settings │ - * └───────────────────────────┘ - */ - if (gradle.parent != null) { - includeBuild("../..") - } -} - -plugins { - id("com.squareup.anvil.gradle-settings") -} - -rootProject.name = "delegate" - -listOf( - "integration-tests:code-generator", - "integration-tests:code-generator-tests", - "integration-tests:dagger-factories-only", - "integration-tests:library", - "integration-tests:mpp:android-module", - "integration-tests:mpp:jvm-module", - "integration-tests:tests", - "sample:app", - "sample:library", - "sample:scopes", -).forEach { name -> - include(":$name") - project(":$name").projectDir = file("../../${name.replace(":", "/")}") -} - -/* - * If this build is the root, then we include the root build here in order to get the gradle plugin. - * - * We include it here instead of in the pluginManagement block above because both of these builds - * include the conventions build in `pluginManagement`, and that causes a race condition since - * composite builds aren't thread-safe. Moving the root build down here ensures that they're - * evaluated in order. - * - * When this build is the root build, the graph winds up as: - * - * ┌────────────────────────────────────────┐ - * │ :delegate │ - * │ build-logic/delegate │ - * │ ┌────────────┐ ┌───────────────────┐ │ - * │ │ :sample │ │:integration-tests │ │ - * │ └────────────┘ └───────────────────┘ │ - * └────────────────────────────────────────┘ ┌───────────────────┐ - * │ │ └──────────────────────▶│ :anvil │ - * │ │ │ (root directory) │ - * │ └─────────────┐ └───────────────────┘ - * │ │ ┌──────────────────┘ │ - * │ ▼ ▼ │ - * │ ┌───────────────────────────┐ │ - * │ │ :conventions │ │ - * │ │ build-logic/conventions │ │ - * │ └───────────────────────────┘ │ - * │ ┌───────────────┘ │ - * │ │ ┌─────────────────────────────────┘ - * ▼ ▼ ▼ - * ┌───────────────────────────┐ - * │ :settings │ - * │ build-logic/settings │ - * └───────────────────────────┘ - */ -if (gradle.parent == null) { - includeBuild("../..") -} diff --git a/build-logic/delegate/build.gradle.kts b/integration-tests/build.gradle.kts similarity index 90% rename from build-logic/delegate/build.gradle.kts rename to integration-tests/build.gradle.kts index 5ef2c6ad8..a3871b9bf 100644 --- a/build-logic/delegate/build.gradle.kts +++ b/integration-tests/build.gradle.kts @@ -1,6 +1,6 @@ buildscript { dependencies { - // This resolves to the gradle-plugin artifact generated by the delegate build. + // This resolves to the gradle-plugin artifact generated by the included build. // Now that it's in the build classpath, it can be applied by its ID in subprojects. classpath("com.squareup.anvil:gradle-plugin") } @@ -12,7 +12,6 @@ plugins { alias(libs.plugins.agp.library) apply false alias(libs.plugins.gradlePublish) apply false alias(libs.plugins.kotlin.android) apply false - alias(libs.plugins.kotlin.dokka) apply false alias(libs.plugins.kotlin.jvm) apply false alias(libs.plugins.kotlin.kapt) apply false alias(libs.plugins.kotlin.multiplatform) apply false diff --git a/integration-tests/code-generator-tests/build.gradle.kts b/integration-tests/code-generator-tests/build.gradle.kts index 8bd399111..36e4ae878 100644 --- a/integration-tests/code-generator-tests/build.gradle.kts +++ b/integration-tests/code-generator-tests/build.gradle.kts @@ -10,7 +10,7 @@ anvil { } dependencies { - anvil(project(":integration-tests:code-generator")) + anvil(project(":code-generator")) implementation(libs.dagger2) diff --git a/integration-tests/gradle.properties b/integration-tests/gradle.properties new file mode 120000 index 000000000..7677fb73b --- /dev/null +++ b/integration-tests/gradle.properties @@ -0,0 +1 @@ +../gradle.properties \ No newline at end of file diff --git a/integration-tests/gradle/wrapper/gradle-wrapper.jar b/integration-tests/gradle/wrapper/gradle-wrapper.jar new file mode 120000 index 000000000..b4214b888 --- /dev/null +++ b/integration-tests/gradle/wrapper/gradle-wrapper.jar @@ -0,0 +1 @@ +../../../gradle/wrapper/gradle-wrapper.jar \ No newline at end of file diff --git a/integration-tests/gradle/wrapper/gradle-wrapper.properties b/integration-tests/gradle/wrapper/gradle-wrapper.properties new file mode 120000 index 000000000..579c670a3 --- /dev/null +++ b/integration-tests/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1 @@ +../../../gradle/wrapper/gradle-wrapper.properties \ No newline at end of file diff --git a/integration-tests/gradlew b/integration-tests/gradlew new file mode 120000 index 000000000..502f5a2d3 --- /dev/null +++ b/integration-tests/gradlew @@ -0,0 +1 @@ +../gradlew \ No newline at end of file diff --git a/integration-tests/gradlew.bat b/integration-tests/gradlew.bat new file mode 120000 index 000000000..284013288 --- /dev/null +++ b/integration-tests/gradlew.bat @@ -0,0 +1 @@ +../gradlew.bat \ No newline at end of file diff --git a/integration-tests/mpp/android-module/build.gradle.kts b/integration-tests/mpp/android-module/build.gradle.kts index ec55735f3..db3ef3f24 100644 --- a/integration-tests/mpp/android-module/build.gradle.kts +++ b/integration-tests/mpp/android-module/build.gradle.kts @@ -81,5 +81,5 @@ dependencies { // This dependency isn't needed. It's only here for testing purposes (this is still an // integration test). - anvilAndroidTest(project(":integration-tests:code-generator")) + anvilAndroidTest(project(":code-generator")) } diff --git a/integration-tests/settings.gradle.kts b/integration-tests/settings.gradle.kts new file mode 100644 index 000000000..2efe6d019 --- /dev/null +++ b/integration-tests/settings.gradle.kts @@ -0,0 +1,59 @@ +pluginManagement { + repositories { + gradlePluginPortal() + mavenCentral() + google() + } + + includeBuild("../build-logic/settings") + includeBuild("../build-logic/conventions") +} + +plugins { + id("com.squareup.anvil.gradle-settings") +} + +rootProject.name = "integration-tests" + +include( + "code-generator", + "code-generator-tests", + "dagger-factories-only", + "library", + "mpp:android-module", + "mpp:jvm-module", + "tests", +) + +/* + * We include the root build here in order to get the Anvil gradle plugin. + * + * We include it here instead of in the pluginManagement block above because anvil, samples, + * and integration-tests all include the conventions build in `pluginManagement`, + * and that causes a race condition since composite builds aren't thread-safe. + * Moving the root build down here ensures that they're evaluated in order. + * + * When this build is the root build, the graph winds up as: + * + * ┌────────────────────────────────────┐ + * │ :integration-tests │ + * │ anvil/integration-tests │ + * └────────────────────────────────────┘ ┌───────────────────┐ + * │ │ └──────────────────▶│ :anvil │ + * │ │ │ (root directory) │ + * │ └─────────────┐ └───────────────────┘ + * │ │ ┌──────────────┘ │ + * │ ▼ ▼ │ + * │ ┌───────────────────────────┐ │ + * │ │ :conventions │ │ + * │ │ build-logic/conventions │ │ + * │ └───────────────────────────┘ │ + * │ ┌───────────────┘ │ + * │ │ ┌─────────────────────────────┘ + * ▼ ▼ ▼ + * ┌───────────────────────────┐ + * │ :settings │ + * │ build-logic/settings │ + * └───────────────────────────┘ + */ +includeBuild("..") diff --git a/integration-tests/tests/build.gradle.kts b/integration-tests/tests/build.gradle.kts index a38428a37..86461f22b 100644 --- a/integration-tests/tests/build.gradle.kts +++ b/integration-tests/tests/build.gradle.kts @@ -16,7 +16,7 @@ anvil { } dependencies { - testImplementation(project(":integration-tests:library")) + testImplementation(project(":library")) testImplementation(testFixtures("com.squareup.anvil:compiler-utils")) testImplementation(libs.dagger2) testImplementation(libs.junit) diff --git a/sample/app/build.gradle.kts b/sample/app/build.gradle.kts index 1eae27e74..d95209656 100644 --- a/sample/app/build.gradle.kts +++ b/sample/app/build.gradle.kts @@ -40,8 +40,8 @@ androidComponents { } dependencies { - implementation(project(":sample:library")) - implementation(project(":sample:scopes")) + implementation(project(":library")) + implementation(project(":scopes")) implementation(libs.androidx.appcompat) implementation(libs.androidx.core) diff --git a/sample/gradle.properties b/sample/gradle.properties new file mode 120000 index 000000000..7677fb73b --- /dev/null +++ b/sample/gradle.properties @@ -0,0 +1 @@ +../gradle.properties \ No newline at end of file diff --git a/sample/gradle/wrapper/gradle-wrapper.jar b/sample/gradle/wrapper/gradle-wrapper.jar new file mode 120000 index 000000000..b4214b888 --- /dev/null +++ b/sample/gradle/wrapper/gradle-wrapper.jar @@ -0,0 +1 @@ +../../../gradle/wrapper/gradle-wrapper.jar \ No newline at end of file diff --git a/sample/gradle/wrapper/gradle-wrapper.properties b/sample/gradle/wrapper/gradle-wrapper.properties new file mode 120000 index 000000000..579c670a3 --- /dev/null +++ b/sample/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1 @@ +../../../gradle/wrapper/gradle-wrapper.properties \ No newline at end of file diff --git a/sample/gradlew b/sample/gradlew new file mode 120000 index 000000000..502f5a2d3 --- /dev/null +++ b/sample/gradlew @@ -0,0 +1 @@ +../gradlew \ No newline at end of file diff --git a/sample/gradlew.bat b/sample/gradlew.bat new file mode 120000 index 000000000..284013288 --- /dev/null +++ b/sample/gradlew.bat @@ -0,0 +1 @@ +../gradlew.bat \ No newline at end of file diff --git a/sample/library/build.gradle.kts b/sample/library/build.gradle.kts index 5bb82fe82..9a8731508 100644 --- a/sample/library/build.gradle.kts +++ b/sample/library/build.gradle.kts @@ -17,6 +17,6 @@ if (libs.versions.config.generateDaggerFactoriesWithAnvil.get().toBoolean()) { } dependencies { - api(project(":sample:scopes")) + api(project(":scopes")) api(libs.dagger2) } diff --git a/sample/settings.gradle.kts b/sample/settings.gradle.kts new file mode 100644 index 000000000..347c4c102 --- /dev/null +++ b/sample/settings.gradle.kts @@ -0,0 +1,55 @@ +pluginManagement { + repositories { + gradlePluginPortal() + mavenCentral() + google() + } + + includeBuild("../build-logic/settings") + includeBuild("../build-logic/conventions") +} + +plugins { + id("com.squareup.anvil.gradle-settings") +} + +rootProject.name = "sample" + +include( + "app", + "library", + "scopes", +) + +/* + * We include the root build here in order to get the Anvil gradle plugin. + * + * We include it here instead of in the pluginManagement block above because anvil, samples, + * and integration-tests all include the conventions build in `pluginManagement`, + * and that causes a race condition since composite builds aren't thread-safe. + * Moving the root build down here ensures that they're evaluated in order. + * + * When this build is the root build, the graph winds up as: + * + * ┌────────────────┐ + * │ :sample │ + * │ anvil/sample │ + * └────────────────┘ ┌───────────────────┐ + * │ │ └────────────▶│ :anvil │ + * │ │ │ (root directory) │ + * │ └───────────┐ └───────────────────┘ + * │ │ ┌─────────┘ │ + * │ ▼ ▼ │ + * │ ┌───────────────────────────┐ │ + * │ │ :conventions │ │ + * │ │ build-logic/conventions │ │ + * │ └───────────────────────────┘ │ + * │ ┌───────────────┘ │ + * │ │ ┌───────────────────────────┘ + * ▼ ▼ ▼ + * ┌───────────────────────────┐ + * │ :settings │ + * │ build-logic/settings │ + * └───────────────────────────┘ + */ +includeBuild("..") diff --git a/settings.gradle.kts b/settings.gradle.kts index 25e4183a2..1e0c76f36 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -21,10 +21,3 @@ include(":compiler") include(":compiler-api") include(":compiler-utils") include(":gradle-plugin") - -// The delegate build is only necessary for convenience, when this build is the root. -// If this build is being included elsewhere, there's no need for it. If the root build is actually -// the delegate build, then including it here would create a circular dependency. -if (gradle.parent == null) { - includeBuild("build-logic/delegate") -}