@@ -33,7 +33,9 @@ import static java.nio.charset.StandardCharsets.US_ASCII
3333
3434import com.google.common.base.Preconditions
3535import com.google.common.collect.ImmutableList
36- import groovy.transform.CompileDynamic
36+ import groovy.transform.CompileStatic
37+ import groovy.transform.TypeChecked
38+ import groovy.transform.TypeCheckingMode
3739import org.gradle.api.DefaultTask
3840import org.gradle.api.GradleException
3941import org.gradle.api.Named
@@ -72,7 +74,7 @@ import javax.inject.Inject
7274 * The task that compiles proto files into Java files.
7375 */
7476// TODO(zhangkun83): add per-plugin output dir reconfiguraiton.
75- @CompileDynamic
77+ @CompileStatic
7678@CacheableTask
7779public abstract class GenerateProtoTask extends DefaultTask {
7880 // Windows CreateProcess has command line limit of 32768:
@@ -180,7 +182,7 @@ public abstract class GenerateProtoTask extends DefaultTask {
180182 static List<List<String > > generateCmds (List<String > baseCmd , List<File > protoFiles , int cmdLengthLimit ) {
181183 List<List<String > > cmds = []
182184 if (! protoFiles. isEmpty()) {
183- int baseCmdLength = baseCmd. sum { it. length() + CMD_ARGUMENT_EXTRA_LENGTH }
185+ int baseCmdLength = baseCmd. sum { it. length() + CMD_ARGUMENT_EXTRA_LENGTH } as int
184186 List<String > currentArgs = []
185187 int currentArgsLength = 0
186188 for (File proto : protoFiles) {
@@ -361,7 +363,8 @@ public abstract class GenerateProtoTask extends DefaultTask {
361363 @InputFiles
362364 @PathSensitive (PathSensitivity .NONE )
363365 FileCollection getSnapshotArtifacts () {
364- Provider<Collection<FileCollection > > snapshotArtifacts = locatorToAlternativePathsMapping. map { map ->
366+ Provider<Collection<FileCollection > > snapshotArtifacts = locatorToAlternativePathsMapping. map {
367+ Map<String , FileCollection > map ->
365368 Set<String > releaseArtifactKeys = releaseDependenciesMapping. get(). keySet()
366369 map. findAll { entry ->
367370 ! releaseArtifactKeys. contains(entry. key)
@@ -372,6 +375,7 @@ public abstract class GenerateProtoTask extends DefaultTask {
372375 }
373376
374377 @Internal
378+ @TypeChecked (TypeCheckingMode .SKIP ) // entry.value always returns an Object for an unknown reason
375379 Provider<Map<String , String > > getReleaseDependenciesMapping () {
376380 providerFactory. provider {
377381 locatorToDependencyMapping. get()
@@ -386,7 +390,7 @@ public abstract class GenerateProtoTask extends DefaultTask {
386390 protocLocator. getOrNull()?. path
387391 }. from {
388392 pluginsExecutableLocators. get(). values()
389- .collect { it . path }
393+ .collect { (( ExecutableLocator ) it) . path }
390394 .findAll { it }
391395 }
392396 }
@@ -415,6 +419,7 @@ public abstract class GenerateProtoTask extends DefaultTask {
415419 return flavors
416420 }
417421
422+ @TypeChecked (TypeCheckingMode .SKIP ) // Don't depend on AGP
418423 @Internal (" Not an actual input to the task, only used to find tasks belonging to a variant" )
419424 String getBuildType () {
420425 Preconditions . checkState(isAndroidProject. get(),
@@ -619,7 +624,7 @@ public abstract class GenerateProtoTask extends DefaultTask {
619624 // to avoid triggering unnecessary rebuilds downstream
620625 List<File > protoFiles = sourceFiles. files. sort()
621626
622- [builtins, plugins]* . each { plugin ->
627+ [builtins, plugins]* . forEach { PluginOptions plugin ->
623628 String outputPath = getOutputDir(plugin)
624629 File outputDir = new File (outputPath)
625630 // protoc is capable of output generated files directly to a JAR file
@@ -632,7 +637,7 @@ public abstract class GenerateProtoTask extends DefaultTask {
632637
633638 // The source directory designated from sourceSet may not actually exist on disk.
634639 // "include" it only when it exists, so that Gradle and protoc won't complain.
635- List<String > dirs = includeDirs. filter { it . exists() }* . path. collect { " -I${ it} " }
640+ List<String > dirs = includeDirs. filter { File it -> it . exists() }* . path. collect { " -I${ it} " . toString() }
636641 logger. debug " ProtobufCompile using directories ${ dirs} "
637642 logger. debug " ProtobufCompile using files ${ protoFiles} "
638643
@@ -643,7 +648,7 @@ public abstract class GenerateProtoTask extends DefaultTask {
643648 // Handle code generation built-ins
644649 builtins. each { builtin ->
645650 String outPrefix = makeOptionsPrefix(builtin. options)
646- baseCmd + = " --${ builtin.name} _out=${ outPrefix}${ getOutputDir(builtin)} "
651+ baseCmd + = " --${ builtin.name} _out=${ outPrefix}${ getOutputDir(builtin)} " . toString()
647652 }
648653
649654 Map<String , ExecutableLocator > executableLocations = pluginsExecutableLocators. get()
@@ -652,12 +657,12 @@ public abstract class GenerateProtoTask extends DefaultTask {
652657 String name = plugin. name
653658 ExecutableLocator locator = executableLocations. get(name)
654659 if (locator != null ) {
655- baseCmd + = " --plugin=protoc-gen-${ name} =${ computeExecutablePath(locator)} "
660+ baseCmd + = " --plugin=protoc-gen-${ name} =${ computeExecutablePath(locator)} " . toString()
656661 } else {
657662 logger. warn " protoc plugin '${ name} ' not defined. Trying to use 'protoc-gen-${ name} ' from system path"
658663 }
659664 String pluginOutPrefix = makeOptionsPrefix(plugin. options)
660- baseCmd + = " --${ name} _out=${ pluginOutPrefix}${ getOutputDir(plugin)} "
665+ baseCmd + = " --${ name} _out=${ pluginOutPrefix}${ getOutputDir(plugin)} " . toString()
661666 }
662667
663668 if (generateDescriptorSet) {
@@ -668,7 +673,7 @@ public abstract class GenerateProtoTask extends DefaultTask {
668673 if (! folder. exists()) {
669674 folder. mkdirs()
670675 }
671- baseCmd + = " --descriptor_set_out=${ path} "
676+ baseCmd + = " --descriptor_set_out=${ path} " . toString()
672677 if (descriptorSetOptions. includeImports) {
673678 baseCmd + = " --include_imports"
674679 }
0 commit comments