From 0f6463c70338584a4d7caa65733411cad5e0f16b Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Sat, 2 Jul 2022 03:35:57 -0700 Subject: [PATCH 1/7] Emulate and deprecate generatedFilesBaseDir Fixes #33 for users not changing generatedFilesBaseDir. Stop documenting generatedFilesBaseDir since it produces poor results, but keep it functional with its existing Copy semantics. Fixes #332 --- README.md | 48 +++---------------- .../protobuf/gradle/GenerateProtoTask.groovy | 1 + .../protobuf/gradle/ProtobufExtension.groovy | 8 ++++ .../protobuf/gradle/ProtobufPlugin.groovy | 18 +++++-- 4 files changed, 30 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 59ab744b..3960353c 100644 --- a/README.md +++ b/README.md @@ -315,12 +315,10 @@ task.plugins { ```gradle protobuf { - generatedFilesBaseDir = "$projectDir/generated" - generateProtoTasks { all().each { task -> task.builtins { - // Generates Python code in the output folder: + // Generates Python code python { } // If you wish to avoid generating Java files: @@ -410,7 +408,7 @@ protobuf { ```gradle { task -> // If true, will generate a descriptor_set.desc file under - // $generatedFilesBaseDir/$sourceSet. Default is false. + // task.outputBaseDir. Default is false. // See --descriptor_set_out in protoc documentation about what it is. task.generateDescriptorSet = true @@ -430,19 +428,11 @@ protobuf { #### Change where files are generated -By default generated Java files are under -``$generatedFilesBaseDir/$sourceSet/$builtinPluginName``, where -``$generatedFilesBaseDir`` is ``$buildDir/generated/source/proto`` by default, -and is configurable. E.g., - -```gradle -protobuf { - ... -  generatedFilesBaseDir = "$projectDir/src/generated" -} -``` +Generated files are under `task.outputBaseDir` with a subdirectory per +builtin and plugin. This produces a folder structure of +``$buildDir/generated/source/proto/$sourceSet/$builtinPluginName``. -The subdirectory name, which is by default ``$builtinPluginName``, can also be +The subdirectory name, which is by default ``$builtinPluginName``, can be changed by setting the ``outputSubDir`` property in the ``builtins`` or ``plugins`` block of a task configuration within ``generateProtoTasks`` block (see previous section). E.g., @@ -451,8 +441,7 @@ changed by setting the ``outputSubDir`` property in the ``builtins`` or { task -> task.plugins { grpc { - // Write the generated files under - // "$generatedFilesBaseDir/$sourceSet/grpcjava" + // Use subdirectory 'grpcjava' instead of the default 'grpc' outputSubDir = 'grpcjava' } } @@ -521,29 +510,6 @@ This plugin integrates with the ``idea`` plugin and automatically registers the proto files and generated Java code as sources. -```gradle -apply plugin: 'idea' - -protobuf { - ... - generatedFilesBaseDir = "$projectDir/gen" -} - -clean { - delete protobuf.generatedFilesBaseDir -} - -idea { - module { - // proto files and generated Java files are automatically added as - // source dirs. - // If you have additional sources, add them here: - sourceDirs += file("/path/to/other/sources"); - } -} -``` - - ## Testing the plugin ``testProject*`` are testing projects that uses this plugin to compile diff --git a/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy b/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy index 2e6f2510..ba5a4e1b 100644 --- a/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy @@ -587,6 +587,7 @@ public abstract class GenerateProtoTask extends DefaultTask { void compile() { Preconditions.checkState(state == State.FINALIZED, 'doneConfig() has not been called') + project.delete(outputBaseDir) // Sort to ensure generated descriptors have a canonical representation // to avoid triggering unnecessary rebuilds downstream List protoFiles = sourceDirs.asFileTree.files.sort() diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy index 2ccf4db9..21012e7a 100644 --- a/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy @@ -54,6 +54,8 @@ abstract class ProtobufExtension { * "${project.buildDir}/generated/source/proto". */ private String generatedFilesBaseDir + @PackageScope + final String defaultGeneratedFilesBaseDir public ProtobufExtension(final Project project) { this.project = project @@ -61,6 +63,7 @@ abstract class ProtobufExtension { this.tools = new ToolsLocator(project) this.taskConfigActions = [] this.generatedFilesBaseDir = "${project.buildDir}/generated/source/proto" + this.defaultGeneratedFilesBaseDir = generatedFilesBaseDir } @PackageScope @@ -83,6 +86,11 @@ abstract class ProtobufExtension { } } + @PackageScope + boolean isGeneratedFilesBaseDirChanged() { + return generatedFilesBaseDir != defaultGeneratedFilesBaseDir + } + //=========================================================================== // Configuration methods //=========================================================================== diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy index bab71b7c..6e0c8349 100644 --- a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy @@ -383,17 +383,27 @@ class ProtobufPlugin implements Plugin { Action configureAction) { String generateProtoTaskName = 'generate' + Utils.getSourceSetSubstringForTaskNames(sourceSetOrVariantName) + 'Proto' - Provider outDir = project.providers.provider { - "${this.protobufExtension.generatedFilesBaseDir}/${sourceSetOrVariantName}".toString() - } return project.tasks.register(generateProtoTaskName, GenerateProtoTask) { it.description = "Compiles Proto source for '${sourceSetOrVariantName}'".toString() - it.outputBaseDir = outDir + it.outputBaseDir = project.providers.provider { + "${protobufExtension.defaultGeneratedFilesBaseDir}/${sourceSetOrVariantName}".toString() + } it.addSourceDirs(protoSourceSet) it.addIncludeDir(protoSourceSet.sourceDirectories) it.addSourceDirs(extractProtosDirs) it.addIncludeDir(extractProtosDirs) it.addIncludeDir(project.files(extractIncludeProtosTask)) + it.doLast { task -> + if (!protobufExtension.isGeneratedFilesBaseDirChanged()) { + return + } + // Purposefully don't wire this up to outputs, as it can be mixed with other files. + project.copy { CopySpec spec -> + spec.includeEmptyDirs = false + spec.from(it.outputBaseDir) + spec.into("${protobufExtension.generatedFilesBaseDir}/${sourceSetOrVariantName}") + } + } configureAction.execute(it) } } From adc5f5dd1c9cdd615b0aedf1abad3457261bf67e Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Sun, 6 Nov 2022 20:03:22 -0800 Subject: [PATCH 2/7] Use FileSystemOperations when available Can't reference project from action --- .../protobuf/gradle/CopyActionFacade.java | 25 +++++++++++++++++++ .../protobuf/gradle/GenerateProtoTask.groovy | 5 +++- .../protobuf/gradle/ProtobufExtract.groovy | 10 +------- .../protobuf/gradle/ProtobufPlugin.groovy | 3 ++- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/main/groovy/com/google/protobuf/gradle/CopyActionFacade.java b/src/main/groovy/com/google/protobuf/gradle/CopyActionFacade.java index 804f3aa7..64e08389 100644 --- a/src/main/groovy/com/google/protobuf/gradle/CopyActionFacade.java +++ b/src/main/groovy/com/google/protobuf/gradle/CopyActionFacade.java @@ -33,8 +33,11 @@ import org.gradle.api.Action; import org.gradle.api.Project; import org.gradle.api.file.CopySpec; +import org.gradle.api.file.DeleteSpec; import org.gradle.api.file.FileSystemOperations; +import org.gradle.api.model.ObjectFactory; import org.gradle.api.tasks.WorkResult; +import org.gradle.util.GradleVersion; import javax.inject.Inject; @@ -46,6 +49,18 @@ @CompileStatic interface CopyActionFacade { WorkResult copy(Action var1); + WorkResult delete(Action action); + + @CompileStatic + final class Loader { + public static CopyActionFacade create(Project project, ObjectFactory objectFactory) { + if (GradleVersion.current().compareTo(GradleVersion.version("6.0")) >= 0) { + // Use object factory to instantiate as that will inject the necessary service. + return objectFactory.newInstance(CopyActionFacade.FileSystemOperationsBased.class); + } + return new CopyActionFacade.ProjectBased(project); + } + } @CompileStatic class ProjectBased implements CopyActionFacade { @@ -59,6 +74,11 @@ public ProjectBased(Project project) { public WorkResult copy(Action action) { return project.copy(action); } + + @Override + public WorkResult delete(Action action) { + return project.delete(action); + } } @CompileStatic @@ -70,5 +90,10 @@ abstract class FileSystemOperationsBased implements CopyActionFacade { public WorkResult copy(Action action) { return getFileSystemOperations().copy(action); } + + @Override + public WorkResult delete(Action action) { + return getFileSystemOperations().delete(action); + } } } diff --git a/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy b/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy index ba5a4e1b..ff419f2e 100644 --- a/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy @@ -81,6 +81,7 @@ public abstract class GenerateProtoTask extends DefaultTask { static final int CMD_ARGUMENT_EXTRA_LENGTH = 3 private static final String JAR_SUFFIX = ".jar" + private final CopyActionFacade copyActionFacade = CopyActionFacade.Loader.create(project, objectFactory) // include dirs are passed to the '-I' option of protoc. They contain protos // that may be "imported" from the source protos, but will not be compiled. private final ConfigurableFileCollection includeDirs = objectFactory.fileCollection() @@ -587,7 +588,9 @@ public abstract class GenerateProtoTask extends DefaultTask { void compile() { Preconditions.checkState(state == State.FINALIZED, 'doneConfig() has not been called') - project.delete(outputBaseDir) + copyActionFacade.delete { spec -> + spec.delete(outputBaseDir) + } // Sort to ensure generated descriptors have a canonical representation // to avoid triggering unnecessary rebuilds downstream List protoFiles = sourceDirs.asFileTree.files.sort() diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufExtract.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufExtract.groovy index 3da54eab..faafcae8 100644 --- a/src/main/groovy/com/google/protobuf/gradle/ProtobufExtract.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/ProtobufExtract.groovy @@ -57,7 +57,7 @@ import javax.inject.Inject @CompileStatic abstract class ProtobufExtract extends DefaultTask { - private final CopyActionFacade copyActionFacade = instantiateCopyActionFacade() + private final CopyActionFacade copyActionFacade = CopyActionFacade.Loader.create(project, objectFactory) private final ArchiveActionFacade archiveActionFacade = instantiateArchiveActionFacade() private final FileCollection filteredProtos = instantiateFilteredProtos() @@ -98,14 +98,6 @@ abstract class ProtobufExtract extends DefaultTask { @Inject protected abstract ProviderFactory getProviderFactory() - private CopyActionFacade instantiateCopyActionFacade() { - if (GradleVersion.current() >= GradleVersion.version("6.0")) { - // Use object factory to instantiate as that will inject the necessary service. - return objectFactory.newInstance(CopyActionFacade.FileSystemOperationsBased) - } - return new CopyActionFacade.ProjectBased(project) - } - private ArchiveActionFacade instantiateArchiveActionFacade() { if (GradleVersion.current() >= GradleVersion.version("6.0")) { // Use object factory to instantiate as that will inject the necessary service. diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy index 6e0c8349..6fb6a173 100644 --- a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy @@ -384,6 +384,7 @@ class ProtobufPlugin implements Plugin { String generateProtoTaskName = 'generate' + Utils.getSourceSetSubstringForTaskNames(sourceSetOrVariantName) + 'Proto' return project.tasks.register(generateProtoTaskName, GenerateProtoTask) { + CopyActionFacade copyActionFacade = CopyActionFacade.Loader.create(it.project, it.objectFactory) it.description = "Compiles Proto source for '${sourceSetOrVariantName}'".toString() it.outputBaseDir = project.providers.provider { "${protobufExtension.defaultGeneratedFilesBaseDir}/${sourceSetOrVariantName}".toString() @@ -398,7 +399,7 @@ class ProtobufPlugin implements Plugin { return } // Purposefully don't wire this up to outputs, as it can be mixed with other files. - project.copy { CopySpec spec -> + copyActionFacade.copy { CopySpec spec -> spec.includeEmptyDirs = false spec.from(it.outputBaseDir) spec.into("${protobufExtension.generatedFilesBaseDir}/${sourceSetOrVariantName}") From ffcdc3843553a7083141f0171df34ce7dbde4814 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Sun, 6 Nov 2022 20:16:27 -0800 Subject: [PATCH 3/7] Deprecate setter I don't know how to make this trigger a warning, for either Groovy and Kotlin. Both seem to ignore it. --- .../groovy/com/google/protobuf/gradle/ProtobufExtension.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy index 21012e7a..b59c2526 100644 --- a/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy @@ -75,6 +75,7 @@ abstract class ProtobufExtension { return generatedFilesBaseDir } + @Deprecated void setGeneratedFilesBaseDir(String generatedFilesBaseDir) { this.generatedFilesBaseDir = generatedFilesBaseDir } From f9cf0610f8e9712871f864a197b9ff3fb64e6603 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Mon, 7 Nov 2022 08:19:33 -0800 Subject: [PATCH 4/7] Redefine extension as local variable so it is available in the closure This fixes `class java.lang.Object cannot be cast to class com.google.protobuf.gradle.ProtobufPlugin` in "testProjectAndroid succeeds with configuration cache". The configuration cache is somehow confusing things, including defeating static typing. Redefining the variable locally avoids the reference to ProtobufPlugin. --- src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy index 6fb6a173..51b9cbc9 100644 --- a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy @@ -381,6 +381,7 @@ class ProtobufPlugin implements Plugin { FileCollection extractProtosDirs, Provider extractIncludeProtosTask, Action configureAction) { + ProtobufExtension protobufExtension = this.protobufExtension; String generateProtoTaskName = 'generate' + Utils.getSourceSetSubstringForTaskNames(sourceSetOrVariantName) + 'Proto' return project.tasks.register(generateProtoTaskName, GenerateProtoTask) { From 20e5d2a2bb4a15c213a1b294587d4899e5639854 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Mon, 7 Nov 2022 08:54:59 -0800 Subject: [PATCH 5/7] Avoid project reference for compatibility with configuration cache --- .../protobuf/gradle/ProtobufExtension.groovy | 23 +++++++++++++------ .../protobuf/gradle/ProtobufPlugin.groovy | 10 ++++---- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy index b59c2526..1cd57038 100644 --- a/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy @@ -35,7 +35,11 @@ import groovy.transform.TypeCheckingMode import org.gradle.api.Action import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.Project +import org.gradle.api.provider.Provider +import org.gradle.api.provider.ProviderFactory import org.gradle.api.tasks.TaskCollection +import java.util.concurrent.atomic.AtomicReference +import javax.inject.Inject /** * Adds the protobuf {} block as a property of the project. @@ -53,7 +57,7 @@ abstract class ProtobufExtension { * The base directory of generated files. The default is * "${project.buildDir}/generated/source/proto". */ - private String generatedFilesBaseDir + private final AtomicReference generatedFilesBaseDir = new AtomicReference() @PackageScope final String defaultGeneratedFilesBaseDir @@ -62,22 +66,25 @@ abstract class ProtobufExtension { this.tasks = new GenerateProtoTaskCollection(project) this.tools = new ToolsLocator(project) this.taskConfigActions = [] - this.generatedFilesBaseDir = "${project.buildDir}/generated/source/proto" - this.defaultGeneratedFilesBaseDir = generatedFilesBaseDir + this.defaultGeneratedFilesBaseDir = "${project.buildDir}/generated/source/proto" + this.generatedFilesBaseDir.set(defaultGeneratedFilesBaseDir) } + @Inject + protected abstract ProviderFactory getProviderFactory() + @PackageScope ToolsLocator getTools() { return tools } String getGeneratedFilesBaseDir() { - return generatedFilesBaseDir + return generatedFilesBaseDir.get() } @Deprecated void setGeneratedFilesBaseDir(String generatedFilesBaseDir) { - this.generatedFilesBaseDir = generatedFilesBaseDir + this.generatedFilesBaseDir.set(generatedFilesBaseDir) } @PackageScope @@ -88,8 +95,10 @@ abstract class ProtobufExtension { } @PackageScope - boolean isGeneratedFilesBaseDirChanged() { - return generatedFilesBaseDir != defaultGeneratedFilesBaseDir + Provider getGeneratedFilesBaseDirProvider() { + // Avoid any reference to `project` for compatibility with configuration cache + AtomicReference generatedFilesBaseDir = this.generatedFilesBaseDir + return providerFactory.provider { generatedFilesBaseDir.get() } } //=========================================================================== diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy index 51b9cbc9..554ae2e2 100644 --- a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy @@ -381,14 +381,15 @@ class ProtobufPlugin implements Plugin { FileCollection extractProtosDirs, Provider extractIncludeProtosTask, Action configureAction) { - ProtobufExtension protobufExtension = this.protobufExtension; String generateProtoTaskName = 'generate' + Utils.getSourceSetSubstringForTaskNames(sourceSetOrVariantName) + 'Proto' + String defaultGeneratedFilesBaseDir = protobufExtension.defaultGeneratedFilesBaseDir + Provider generatedFilesBaseDirProvider = protobufExtension.generatedFilesBaseDirProvider return project.tasks.register(generateProtoTaskName, GenerateProtoTask) { CopyActionFacade copyActionFacade = CopyActionFacade.Loader.create(it.project, it.objectFactory) it.description = "Compiles Proto source for '${sourceSetOrVariantName}'".toString() it.outputBaseDir = project.providers.provider { - "${protobufExtension.defaultGeneratedFilesBaseDir}/${sourceSetOrVariantName}".toString() + "${defaultGeneratedFilesBaseDir}/${sourceSetOrVariantName}".toString() } it.addSourceDirs(protoSourceSet) it.addIncludeDir(protoSourceSet.sourceDirectories) @@ -396,14 +397,15 @@ class ProtobufPlugin implements Plugin { it.addIncludeDir(extractProtosDirs) it.addIncludeDir(project.files(extractIncludeProtosTask)) it.doLast { task -> - if (!protobufExtension.isGeneratedFilesBaseDirChanged()) { + String generatedFilesBaseDir = generatedFilesBaseDirProvider.get() + if (generatedFilesBaseDir == defaultGeneratedFilesBaseDir) { return } // Purposefully don't wire this up to outputs, as it can be mixed with other files. copyActionFacade.copy { CopySpec spec -> spec.includeEmptyDirs = false spec.from(it.outputBaseDir) - spec.into("${protobufExtension.generatedFilesBaseDir}/${sourceSetOrVariantName}") + spec.into("${generatedFilesBaseDir}/${sourceSetOrVariantName}") } } configureAction.execute(it) From 1296159241a82d06297919b1c09e1b77544374f9 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Thu, 5 Jan 2023 08:21:06 -0800 Subject: [PATCH 6/7] Swap to Property --- .../protobuf/gradle/ProtobufExtension.groovy | 33 +++++++------------ .../protobuf/gradle/ProtobufPlugin.groovy | 2 +- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy index 1cd57038..6a0484ee 100644 --- a/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy @@ -35,11 +35,8 @@ import groovy.transform.TypeCheckingMode import org.gradle.api.Action import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.Project -import org.gradle.api.provider.Provider -import org.gradle.api.provider.ProviderFactory +import org.gradle.api.provider.Property import org.gradle.api.tasks.TaskCollection -import java.util.concurrent.atomic.AtomicReference -import javax.inject.Inject /** * Adds the protobuf {} block as a property of the project. @@ -53,11 +50,6 @@ abstract class ProtobufExtension { private final ToolsLocator tools private final ArrayList> taskConfigActions - /** - * The base directory of generated files. The default is - * "${project.buildDir}/generated/source/proto". - */ - private final AtomicReference generatedFilesBaseDir = new AtomicReference() @PackageScope final String defaultGeneratedFilesBaseDir @@ -67,26 +59,30 @@ abstract class ProtobufExtension { this.tools = new ToolsLocator(project) this.taskConfigActions = [] this.defaultGeneratedFilesBaseDir = "${project.buildDir}/generated/source/proto" - this.generatedFilesBaseDir.set(defaultGeneratedFilesBaseDir) + this.generatedFilesBaseDirProperty.convention(defaultGeneratedFilesBaseDir) } - @Inject - protected abstract ProviderFactory getProviderFactory() - @PackageScope ToolsLocator getTools() { return tools } String getGeneratedFilesBaseDir() { - return generatedFilesBaseDir.get() + return generatedFilesBaseDirProperty.get() } @Deprecated void setGeneratedFilesBaseDir(String generatedFilesBaseDir) { - this.generatedFilesBaseDir.set(generatedFilesBaseDir) + generatedFilesBaseDirProperty.set(generatedFilesBaseDir) } + /** + * The base directory of generated files. The default is + * "${project.buildDir}/generated/source/proto". + */ + @PackageScope + abstract Property getGeneratedFilesBaseDirProperty() + @PackageScope void configureTasks() { this.taskConfigActions.each { action -> @@ -94,13 +90,6 @@ abstract class ProtobufExtension { } } - @PackageScope - Provider getGeneratedFilesBaseDirProvider() { - // Avoid any reference to `project` for compatibility with configuration cache - AtomicReference generatedFilesBaseDir = this.generatedFilesBaseDir - return providerFactory.provider { generatedFilesBaseDir.get() } - } - //=========================================================================== // Configuration methods //=========================================================================== diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy index 554ae2e2..5e65071b 100644 --- a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy @@ -384,7 +384,7 @@ class ProtobufPlugin implements Plugin { String generateProtoTaskName = 'generate' + Utils.getSourceSetSubstringForTaskNames(sourceSetOrVariantName) + 'Proto' String defaultGeneratedFilesBaseDir = protobufExtension.defaultGeneratedFilesBaseDir - Provider generatedFilesBaseDirProvider = protobufExtension.generatedFilesBaseDirProvider + Provider generatedFilesBaseDirProvider = protobufExtension.generatedFilesBaseDirProperty return project.tasks.register(generateProtoTaskName, GenerateProtoTask) { CopyActionFacade copyActionFacade = CopyActionFacade.Loader.create(it.project, it.objectFactory) it.description = "Compiles Proto source for '${sourceSetOrVariantName}'".toString() From f53854d231d4941243038dfab14b8afd32397c0e Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Thu, 5 Jan 2023 08:41:04 -0800 Subject: [PATCH 7/7] Turn off UnnecessaryObjectReferences --- config/codenarc/codenarc.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/codenarc/codenarc.xml b/config/codenarc/codenarc.xml index 17af312e..12e743c1 100644 --- a/config/codenarc/codenarc.xml +++ b/config/codenarc/codenarc.xml @@ -82,9 +82,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + +