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

basic Gradle integration test scaffolding #789

Merged
merged 14 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ ij_shell_redirect_followed_by_space = false
ij_shell_switch_cases_indented = false

[{*.gant,*.gradle,*.groovy,*.gy}]
ij_continuation_indent_size = 2
ij_groovy_align_group_field_declarations = false
ij_groovy_align_multiline_array_initializer_expression = false
ij_groovy_align_multiline_assignment = false
Expand Down
34 changes: 29 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs :
check-latest : true

- name : KtLint
run : ./gradlew ktlintCheck --no-build-cache --no-daemon --stacktrace && ./gradlew -p build-logic ktlintCheck --no-build-cache --no-daemon --stacktrace
run : ./gradlew ktlintCheck --no-build-cache --no-daemon --stacktrace

lint :
runs-on : ubuntu-latest
Expand All @@ -92,7 +92,7 @@ jobs :
check-latest : true

- name : Android Lint
run : ./gradlew lint --no-build-cache --no-daemon --stacktrace
run : ./gradlew -p build-logic/delegate lint --no-build-cache --no-daemon --stacktrace

- name : Upload Lint Results
uses : actions/upload-artifact@v3
Expand Down Expand Up @@ -201,10 +201,10 @@ jobs :
check-latest : true

- name : Run integration tests
run : ./gradlew -p integration-tests test --no-build-cache --no-daemon --stacktrace -Doverride_kotlin=${{ matrix.kotlin-version }} -Doverride_config-generateDaggerFactoriesWithAnvil=false
run : ./gradlew -p build-logic/delegate test --no-build-cache --no-daemon --stacktrace -Doverride_kotlin=${{ matrix.kotlin-version }} -Doverride_config-generateDaggerFactoriesWithAnvil=false

- name : Build the sample
run : ./gradlew :sample:app:assembleDebug --no-build-cache --no-daemon --stacktrace -Doverride_kotlin=${{ matrix.kotlin-version }} -Doverride_config-generateDaggerFactoriesWithAnvil=false
run : ./gradlew :delegate:sample:app:assembleDebug --no-build-cache --no-daemon --stacktrace -Doverride_kotlin=${{ matrix.kotlin-version }} -Doverride_config-generateDaggerFactoriesWithAnvil=false

- name : Upload Test Results
uses : actions/upload-artifact@v3
Expand Down Expand Up @@ -248,6 +248,29 @@ jobs :
name : insrumentation-test-results
path : ./**/build/reports/androidTests/connected/**

gradle-integration-tests :
name : Gradle integration tests
runs-on : macos-latest
timeout-minutes : 20

steps :
- uses : actions/checkout@v3
- uses : actions/setup-java@v3
with :
distribution : 'temurin'
java-version : '11'
check-latest : true

- name : Gradle integration tests
run : ./gradlew gradleTest --stacktrace

- name : Upload Test Results
uses : actions/upload-artifact@v3
if : ${{ failure() }}
with :
name : test-results-gradle-integration
path : ./**/build/reports/tests/

gradle-wrapper-validation :
name : "Validate the Gradle Wrapper"
runs-on : ubuntu-latest
Expand All @@ -272,7 +295,7 @@ jobs :
run : ./gradlew :createBenchmarkProject

- name : "Build Benchmark Project"
run : ./gradlew :benchmark:app:assemble
run : ./gradlew -p benchmark :app:assemble

all-checks:
if: always()
Expand All @@ -287,6 +310,7 @@ jobs :
- test-gradle-plugin
- kapt-for-dagger-factories
- instrumentation-tests
- gradle-integration-tests
- gradle-wrapper-validation
- build-benchmark-project

Expand Down
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ out
# Ignore the generated project.
/benchmark/

# Since :gradle-plugin is in two builds, it has two build directories
/gradle-plugin/build-anvil/
# projects in the `build-logic/delegate` build have a second build dir
build-delegate/
build-anvil/

# old build directories that've moved
/gradle-plugin/build-composite-wrapper/
10 changes: 5 additions & 5 deletions annotations-optional/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
plugins {
id 'com.squareup.anvil.library'
id 'com.squareup.anvil.publish'
id 'conventions.library'
id 'conventions.publish'
}

publish {
configurePom(
artifactId: 'annotations-optional',
pomName: 'Anvil Optional Annotations',
pomDescription: 'Optional annotations that we\'ve found to be helpful with managing larger dependency graphs'
artifactId: 'annotations-optional',
pomName: 'Anvil Optional Annotations',
pomDescription: 'Optional annotations that we\'ve found to be helpful with managing larger dependency graphs'
)
}

Expand Down
10 changes: 5 additions & 5 deletions annotations/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
plugins {
id 'com.squareup.anvil.library'
id 'com.squareup.anvil.publish'
id 'conventions.library'
id 'conventions.publish'
}

publish {
configurePom(
artifactId: 'annotations',
pomName: 'Anvil Annotations',
pomDescription: 'Annotations used to mark classes and methods for code generation in Anvil'
artifactId: 'annotations',
pomName: 'Anvil Annotations',
pomDescription: 'Annotations used to mark classes and methods for code generation in Anvil'
)
}

Expand Down
42 changes: 0 additions & 42 deletions build-logic/build.gradle

This file was deleted.

55 changes: 55 additions & 0 deletions build-logic/conventions/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
plugins {
alias libs.plugins.kotlin.jvm
alias libs.plugins.ktlint
id 'java-gradle-plugin'
}

gradlePlugin {
plugins {
gradleTests {
id = 'conventions.gradle-tests'
implementationClass = 'com.squareup.anvil.conventions.GradleTestsPlugin'
}
library {
id = 'conventions.library'
implementationClass = 'com.squareup.anvil.conventions.LibraryPlugin'
}
minimalSupport {
id = 'conventions.minimal'
implementationClass = 'com.squareup.anvil.conventions.MinimalSupportPlugin'
}
publish {
id = 'conventions.publish'
implementationClass = 'com.squareup.anvil.conventions.PublishConventionPlugin'
}
root {
id = 'conventions.root'
implementationClass = 'com.squareup.anvil.conventions.RootPlugin'
}
}
}

kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}
}

ktlint {
version = libs.versions.ktlint.get()
}

dependencies {
compileOnly gradleApi()

api libs.ktlintRaw
api libs.kotlinpoet
api libs.kgx

api libs.kotlin.dokka
api libs.kotlin.gradlePlugin
api libs.mavenPublishRaw

// Expose the generated version catalog API to the plugins.
implementation files(libs.getClass().superclass.protectionDomain.codeSource.location)
}
14 changes: 14 additions & 0 deletions build-logic/conventions/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pluginManagement {
repositories {
google()
gradlePluginPortal()
mavenCentral()
}
includeBuild '../settings'
}

plugins {
id 'com.squareup.anvil.gradle-settings'
}

rootProject.name = "conventions"
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ open class CreateBenchmarkProjectTask : DefaultTask() {
@TaskAction fun createProject() {
val libraryModules = List(MODULE_COUNT) { index ->
val name = "lib$index"
val path = ":${rootDir.name}:$name"
val path = ":$name"
RBusarow marked this conversation as resolved.
Show resolved Hide resolved

LibraryModule(
name = name,
Expand All @@ -69,6 +69,7 @@ open class CreateBenchmarkProjectTask : DefaultTask() {
)

createSettingsGradleFile(libraryModules.values + appModule)
createGradlePropertiesFile()
createScenariosFile()
createAppModule(appModule, libraryModules)

Expand All @@ -78,26 +79,54 @@ open class CreateBenchmarkProjectTask : DefaultTask() {
}

private fun createSettingsGradleFile(modules: Collection<Module>) {
val content = modules.sortedBy { it.path }.joinToString(separator = "\n") {
"include '${it.path}'"
val content = buildString {

appendLine(
"""
pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
}

includeBuild '../build-logic/settings'
}

plugins {
id 'com.squareup.anvil.gradle-settings'
}

includeBuild '..'

""".trimIndent(),
)
modules.sortedBy { it.path }
.forEach {
appendLine("include '${it.name}'")
}
}

File(rootDir, "settings.gradle").writeTextSafely(content)
}

private fun createGradlePropertiesFile() {
rootDir.parentFile.resolve("gradle.properties")
.copyTo(rootDir.resolve("gradle.properties"))
}

private fun createScenariosFile() {
val content = """
# Prefix with aa_ to run this scenario first. The Gradle Profiler uses an alphabetical sort
# for all scenarios.
aa_fill_cache {
tasks = [":benchmark:app:assemble"]
tasks = [":app:assemble"]
warm-ups = 1
iterations = 0
}

anvil_benchmark {
tasks = [":benchmark:app:compileKotlin"]
cleanup-tasks = [":benchmark:app:cleanCompileKotlin"]
tasks = [":app:compileKotlin"]
cleanup-tasks = [":app:cleanCompileKotlin"]

warm-ups = 6
iterations = 10
Expand Down Expand Up @@ -134,8 +163,8 @@ open class CreateBenchmarkProjectTask : DefaultTask() {

val content = """
|plugins {
| alias(libs.plugins.kotlin.jvm)
| id("com.squareup.anvil")
| alias libs.plugins.kotlin.jvm
| id 'com.squareup.anvil'
|}
|
|anvil {
Expand Down Expand Up @@ -327,9 +356,9 @@ open class CreateBenchmarkProjectTask : DefaultTask() {

val content = """
|plugins {
| alias(libs.plugins.kotlin.jvm)
| alias(libs.plugins.kotlin.kapt)
| id("com.squareup.anvil")
| alias libs.plugins.kotlin.jvm
| alias libs.plugins.kotlin.kapt
| id 'com.squareup.anvil'
|}
|
|kapt {
Expand Down
Loading