Skip to content

Commit

Permalink
Merge pull request #731 from square/joel.configuration-cache-fixes
Browse files Browse the repository at this point in the history
Resolve Gradle configurations cache issues
  • Loading branch information
JoelWilcox authored Jul 28, 2023
2 parents 860cd1d + c7405ff commit 912367e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 30 deletions.
15 changes: 10 additions & 5 deletions compiler/generate_build_properties.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ sourceSets {
test.java.srcDirs += "$buildDir/$generatedDirPath"
}

def warningsAsErrors = rootProject.ext.warningsAsErrors

def generateBuildProperties = project.tasks.register('generateBuildProperties') {
File buildPropertiesFile = new File(new File(project.buildDir, generatedDirPath), 'BuildProperties.kt')
File buildPropertiesFile = layout.buildDirectory.file(generatedDirPath + '/BuildProperties.kt')
.get().asFile

def fullTestRun = libs.versions.config.fullTestRun.get()

inputs.property 'fullTestRun', libs.versions.config.fullTestRun.get()
inputs.property 'fullTestRun', fullTestRun
inputs.property 'kotlinVersion', libs.versions.kotlin.get()
inputs.property 'warningsAsErrors', rootProject.ext.warningsAsErrors
inputs.property 'warningsAsErrors', warningsAsErrors

outputs.file buildPropertiesFile

Expand All @@ -18,9 +23,9 @@ def generateBuildProperties = project.tasks.register('generateBuildProperties')
buildPropertiesFile.write """\
package com.squareup.anvil.compiler
internal const val WARNINGS_AS_ERRORS = ${rootProject.ext.warningsAsErrors}
internal const val WARNINGS_AS_ERRORS = $warningsAsErrors
internal const val FULL_TEST_RUN = ${rootProject.ext.fullTestRun}
internal const val FULL_TEST_RUN = $fullTestRun
""".stripIndent()
}
}
Expand Down
11 changes: 6 additions & 5 deletions gradle-plugin/generate_build_properties.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ sourceSets {
}

def generateBuildProperties = project.tasks.register('generateBuildProperties') {
def version = project.findProperty('VERSION_NAME')
def group = project.findProperty('GROUP')
def version = getProperty('VERSION_NAME').toString()
def group = getProperty('GROUP').toString()

File buildPropertiesFile =
new File(new File(project.buildDir, generatedDirPath), 'BuildProperties.kt')
File buildPropertiesFile = layout.buildDirectory.file(generatedDirPath + '/BuildProperties.kt')
.get().asFile

inputs.property 'version', version
inputs.property 'group', group
Expand Down Expand Up @@ -51,7 +51,8 @@ afterEvaluate {
tasks.named(taskName).configure {
it.dependsOn(generateBuildProperties)
}
} catch (UnknownTaskException ignored) { }
} catch (UnknownTaskException ignored) {
}
}

// javaSourcesJar is registered even later. Gradle is love.
Expand Down
20 changes: 0 additions & 20 deletions integration-tests/tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,3 @@ dependencies {

kaptTest libs.dagger2.compiler
}

// Okay, this check is sketchy here. But this module serves as integration test so it's not too
// terrible. What would be worse is setting up integration tests in the Gradle plugin itself,
// because it requires so much code and might not represent the real world usage.
gradle.taskGraph.afterTask { Task task ->
if (task.project != project) return

task.inputs.properties.each { key, value ->
if (key.contains('com.squareup.anvil.compiler.src-gen-dir')) {
boolean isAbsolute = new File(value.toString()).isAbsolute()
if (isAbsolute) {
throw new GradleException(
"The workaround for absolute paths in the Anvil Gradle plugin is broken. Key: $key, " +
"value: $value, task: $task. For more context see " +
"https://github.com/square/anvil/issues/65"
)
}
}
}
}

0 comments on commit 912367e

Please sign in to comment.