Skip to content

Commit

Permalink
Avoid storing variantName property in the task (#448)
Browse files Browse the repository at this point in the history
When configuration caching is enabled, all task properties will be serialized, causing variantName to be queried even for Java-only projects which throws runtime exception. This change completely removes that property as it is required only during task configuration.
  • Loading branch information
gavra0 authored Nov 17, 2020
1 parent 5291031 commit a2d2885
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public abstract class GenerateProtoTask extends DefaultTask {
private String buildType
private boolean isTestVariant
private FileResolver fileResolver
private final Provider<String> variantName = providerFactory.provider { variant.name }
private final Provider<Boolean> isAndroidProject = providerFactory.provider { Utils.isAndroidProject(project) }
private final Provider<Boolean> isTestProvider = providerFactory.provider {
if (Utils.isAndroidProject(project)) {
Expand Down Expand Up @@ -341,11 +340,6 @@ public abstract class GenerateProtoTask extends DefaultTask {
return isAndroidProject
}

@Internal("Not an actual input to the task, only used to find tasks belonging to a variant")
Provider<String> getVariantName() {
return variantName
}

@Internal("Not an actual input to the task, only used to find tasks belonging to a variant")
boolean getIsTestVariant() {
Preconditions.checkState(isAndroidProject.get(),
Expand All @@ -367,7 +361,7 @@ public abstract class GenerateProtoTask extends DefaultTask {
Preconditions.checkState(isAndroidProject.get(),
'buildType should not be used in a Java project')
Preconditions.checkState(
variantName.get() == 'test' || buildType,
variant.name == 'test' || buildType,
'buildType is not set and task is not for local unit test variant')
return buildType
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public class ProtobufConfigurator {

public TaskCollection<GenerateProtoTask> ofVariant(String variant) {
return all().matching { GenerateProtoTask task ->
task.variantName.get() == variant
task.variant.name == variant
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import spock.lang.Unroll
@CompileDynamic
class ProtobufJavaPluginTest extends Specification {
// Current supported version is Gradle 5+.
private static final List<String> GRADLE_VERSIONS = ["5.6", "6.0", "6.5-rc-1"]
private static final List<String> GRADLE_VERSIONS = ["5.6", "6.0", "6.7.1"]
private static final List<String> KOTLIN_VERSIONS = ["1.3.20", "1.3.30"]

void "testApplying java and com.google.protobuf adds corresponding task to project"() {
Expand Down Expand Up @@ -85,13 +85,16 @@ class ProtobufJavaPluginTest extends Specification {
File projectDir = ProtobufPluginTestHelper.projectBuilder('testProject')
.copyDirs('testProjectBase', 'testProject')
.build()
// Limit max number of problems to catch regressions
new File(projectDir, "gradle.properties").write('org.gradle.unsafe.configuration-cache.max-problems=42')
and:
GradleRunner runner = GradleRunner.create()
.withProjectDir(projectDir)
.withArguments(
'build', '--stacktrace',
'--configuration-cache=warn'
'--configuration-cache',
'--configuration-cache-problems=warn'
)
.withPluginClasspath()
.withGradleVersion(gradleVersion)
Expand Down

0 comments on commit a2d2885

Please sign in to comment.