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

Resolve Gradle configurations cache issues #731

Merged
merged 1 commit into from
Jul 28, 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
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"
)
}
}
}
}