diff --git a/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy b/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy index 840960ed..4541dd66 100644 --- a/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy @@ -36,6 +36,7 @@ import com.google.common.collect.ImmutableList import groovy.transform.CompileStatic import groovy.transform.TypeChecked import groovy.transform.TypeCheckingMode +import org.gradle.api.Action import org.gradle.api.DefaultTask import org.gradle.api.GradleException import org.gradle.api.Named @@ -65,7 +66,6 @@ import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.SkipWhenEmpty import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.TaskAction -import org.gradle.util.ConfigureUtil import javax.annotation.Nullable import javax.inject.Inject @@ -463,9 +463,9 @@ public abstract class GenerateProtoTask extends DefaultTask { * Configures the protoc builtins in a closure, which will be manipulating a * NamedDomainObjectContainer. */ - public void builtins(Closure configureClosure) { + public void builtins(Action> configureAction) { checkCanConfig() - ConfigureUtil.configure(configureClosure, builtins) + configureAction.execute(this.builtins) } /** @@ -481,9 +481,9 @@ public abstract class GenerateProtoTask extends DefaultTask { * Configures the protoc plugins in a closure, which will be maniuplating a * NamedDomainObjectContainer. */ - public void plugins(Closure configureClosure) { + public void plugins(Action> configureAction) { checkCanConfig() - ConfigureUtil.configure(configureClosure, plugins) + configureAction.execute(this.plugins) } /** diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufConvention.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufConvention.groovy deleted file mode 100644 index 92a0c3c9..00000000 --- a/src/main/groovy/com/google/protobuf/gradle/ProtobufConvention.groovy +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Original work copyright (c) 2015, Alex Antonov. All rights reserved. - * Modified work copyright (c) 2015, Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.google.protobuf.gradle - -import groovy.transform.CompileStatic -import org.gradle.api.Project -import org.gradle.api.internal.file.FileResolver -import org.gradle.util.ConfigureUtil - -/** - * Adds the protobuf {} block as a property of the project. - */ -@CompileStatic -class ProtobufConvention { - ProtobufConvention(Project project, FileResolver fileResolver) { - protobuf = new ProtobufConfigurator(project, fileResolver) - } - - final ProtobufConfigurator protobuf - - ProtobufConfigurator protobuf(Closure configureClosure) { - ConfigureUtil.configure(configureClosure, protobuf) - } -} diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufConfigurator.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy similarity index 69% rename from src/main/groovy/com/google/protobuf/gradle/ProtobufConfigurator.groovy rename to src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy index 1e8dbe15..2ccf4db9 100644 --- a/src/main/groovy/com/google/protobuf/gradle/ProtobufConfigurator.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy @@ -29,44 +29,57 @@ package com.google.protobuf.gradle import groovy.transform.CompileStatic +import groovy.transform.PackageScope import groovy.transform.TypeChecked import groovy.transform.TypeCheckingMode +import org.gradle.api.Action +import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.Project -import org.gradle.api.internal.file.FileResolver import org.gradle.api.tasks.TaskCollection -import org.gradle.util.ConfigureUtil /** - * The main configuration block exposed as {@code protobuf} in the build script. + * Adds the protobuf {} block as a property of the project. */ @CompileStatic -public class ProtobufConfigurator { +// gradle require abstract modificator on extensions +@SuppressWarnings(["AbstractClassWithoutAbstractMethod", "AbstractClassWithPublicConstructor"]) +abstract class ProtobufExtension { private final Project project private final GenerateProtoTaskCollection tasks private final ToolsLocator tools - private final ArrayList taskConfigClosures + private final ArrayList> taskConfigActions /** * The base directory of generated files. The default is * "${project.buildDir}/generated/source/proto". */ - String generatedFilesBaseDir + private String generatedFilesBaseDir - public ProtobufConfigurator(Project project, FileResolver fileResolver) { + public ProtobufExtension(final Project project) { this.project = project - if (Utils.isAndroidProject(project)) { - tasks = new AndroidGenerateProtoTaskCollection() - } else { - tasks = new JavaGenerateProtoTaskCollection() - } - tools = new ToolsLocator(project) - taskConfigClosures = [] - generatedFilesBaseDir = "${project.buildDir}/generated/source/proto" + this.tasks = new GenerateProtoTaskCollection(project) + this.tools = new ToolsLocator(project) + this.taskConfigActions = [] + this.generatedFilesBaseDir = "${project.buildDir}/generated/source/proto" + } + + @PackageScope + ToolsLocator getTools() { + return tools } - void runTaskConfigClosures() { - taskConfigClosures.each { closure -> - ConfigureUtil.configure(closure, tasks) + String getGeneratedFilesBaseDir() { + return generatedFilesBaseDir + } + + void setGeneratedFilesBaseDir(String generatedFilesBaseDir) { + this.generatedFilesBaseDir = generatedFilesBaseDir + } + + @PackageScope + void configureTasks() { + this.taskConfigActions.each { action -> + action.execute(tasks) } } @@ -78,16 +91,16 @@ public class ProtobufConfigurator { * Locates the protoc executable. The closure will be manipulating an * ExecutableLocator. */ - public void protoc(Closure configureClosure) { - ConfigureUtil.configure(configureClosure, tools.protoc) + public void protoc(Action configureAction) { + configureAction.execute(tools.protoc) } /** * Locate the codegen plugin executables. The closure will be manipulating a * NamedDomainObjectContainer. */ - public void plugins(Closure configureClosure) { - ConfigureUtil.configure(configureClosure, tools.plugins) + public void plugins(Action> configureAction) { + configureAction.execute(tools.plugins) } /** @@ -101,8 +114,8 @@ public class ProtobufConfigurator { * change the task in your own afterEvaluate closure, as the change may not * be picked up correctly by the wired javaCompile task. */ - public void generateProtoTasks(Closure configureClosure) { - taskConfigClosures.add(configureClosure) + public void generateProtoTasks(Action configureAction) { + taskConfigActions.add(configureAction) } /** @@ -118,50 +131,50 @@ public class ProtobufConfigurator { } public class GenerateProtoTaskCollection { + private final Project project + + GenerateProtoTaskCollection(final Project project) { + this.project = project + } + public TaskCollection all() { return project.tasks.withType(GenerateProtoTask) } - } - public class AndroidGenerateProtoTaskCollection - extends GenerateProtoTaskCollection { + public TaskCollection ofSourceSet(String sourceSet) { + return all().matching { GenerateProtoTask task -> + !Utils.isAndroidProject(project) && task.sourceSet.name == sourceSet + } + } + public TaskCollection ofFlavor(String flavor) { return all().matching { GenerateProtoTask task -> - task.flavors.contains(flavor) + Utils.isAndroidProject(project) && task.flavors.contains(flavor) } } public TaskCollection ofBuildType(String buildType) { return all().matching { GenerateProtoTask task -> - task.buildType == buildType + Utils.isAndroidProject(project) && task.buildType == buildType } } @TypeChecked(TypeCheckingMode.SKIP) // Don't depend on AGP public TaskCollection ofVariant(String variant) { return all().matching { GenerateProtoTask task -> - task.variant.name == variant + Utils.isAndroidProject(project) && task.variant.name == variant } } public TaskCollection ofNonTest() { return all().matching { GenerateProtoTask task -> - !task.isTestVariant + Utils.isAndroidProject(project) && !task.isTestVariant } } public TaskCollection ofTest() { return all().matching { GenerateProtoTask task -> - task.isTestVariant - } - } - } - - public class JavaGenerateProtoTaskCollection - extends GenerateProtoTaskCollection { - public TaskCollection ofSourceSet(String sourceSet) { - return all().matching { GenerateProtoTask task -> - task.sourceSet.name == sourceSet + Utils.isAndroidProject(project) && task.isTestVariant } } } diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy index df85ec61..7a82e575 100644 --- a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy @@ -72,6 +72,7 @@ class ProtobufPlugin implements Plugin { private final FileResolver fileResolver private Project project + private ProtobufExtension protobufExtension private boolean wasApplied = false @Inject @@ -85,7 +86,9 @@ class ProtobufPlugin implements Plugin { "Gradle version is ${project.gradle.gradleVersion}. Minimum supported version is 5.6") } - this.project = project + this.protobufExtension = project.extensions.create("protobuf", ProtobufExtension, project) + + this.project = project // At least one of the prerequisite plugins must by applied before this plugin can be applied, so // we will use the PluginManager.withPlugin() callback mechanism to delay applying this plugin until // after that has been achieved. If project evaluation completes before one of the prerequisite plugins @@ -123,8 +126,6 @@ class ProtobufPlugin implements Plugin { // Provides the osdetector extension project.apply([plugin:com.google.gradle.osdetector.OsDetectorPlugin]) - project.convention.plugins.protobuf = new ProtobufConvention(project, fileResolver) - addSourceSetExtensions() getSourceSets().all { sourceSet -> createProtobufConfiguration(sourceSet.name) @@ -143,17 +144,17 @@ class ProtobufPlugin implements Plugin { } } addProtoTasks() - project.protobuf.runTaskConfigClosures() + this.protobufExtension.configureTasks() // Disallow user configuration outside the config closures, because // next in linkGenerateProtoTasksToSourceCompile() we add generated, // outputs to the inputs of javaCompile tasks, and any new codegen // plugin output added after this point won't be added to javaCompile // tasks. - project.protobuf.generateProtoTasks.all()*.doneConfig() + this.protobufExtension.generateProtoTasks.all()*.doneConfig() linkGenerateProtoTasksToSourceCompile() // protoc and codegen plugin configuration may change through the protobuf{} // block. Only at this point the configuration has been finalized. - project.protobuf.tools.registerTaskDependencies(project.protobuf.getGenerateProtoTasks().all()) + this.protobufExtension.tools.registerTaskDependencies(this.protobufExtension.getGenerateProtoTasks().all()) // Register proto and generated sources with IDE addSourcesToIde() @@ -290,7 +291,7 @@ class ProtobufPlugin implements Plugin { /** * Creates Protobuf tasks for a variant in an Android project. */ - private void addTasksForVariant(final Object variant, boolean isTestVariant) { + private void addTasksForVariant(final Object variant, final boolean isTestVariant) { // GenerateProto task, one per variant (compilation unit). Task generateProtoTask = addGenerateProtoTask(variant.name, variant.sourceSets) generateProtoTask.setVariant(variant, isTestVariant) @@ -351,17 +352,16 @@ class ProtobufPlugin implements Plugin { Utils.getSourceSetSubstringForTaskNames(sourceSetOrVariantName) + 'Proto' return project.tasks.create(generateProtoTaskName, GenerateProtoTask) { description = "Compiles Proto source for '${sourceSetOrVariantName}'" - outputBaseDir = "${project.protobuf.generatedFilesBaseDir}/${sourceSetOrVariantName}" + outputBaseDir = "${this.protobufExtension.generatedFilesBaseDir}/${sourceSetOrVariantName}" it.fileResolver = this.fileResolver sourceSets.each { sourceSet -> addSourceFiles(sourceSet.proto) SourceDirectorySet protoSrcDirSet = sourceSet.proto addIncludeDir(protoSrcDirSet.sourceDirectories) } - ProtobufConfigurator extension = project.protobuf - protocLocator.set(project.providers.provider { extension.tools.protoc }) + protocLocator.set(project.providers.provider { this.protobufExtension.tools.protoc }) pluginsExecutableLocators.set(project.providers.provider { - ((NamedDomainObjectContainer) extension.tools.plugins).asMap + ((NamedDomainObjectContainer) this.protobufExtension.tools.plugins).asMap }) } } @@ -374,8 +374,7 @@ class ProtobufPlugin implements Plugin { * variant may have multiple sourceSets, each of these sourceSets will have * its own extraction task. */ - private Task setupExtractProtosTask( - GenerateProtoTask generateProtoTask, String sourceSetName) { + private Task setupExtractProtosTask(final GenerateProtoTask generateProtoTask, final String sourceSetName) { String extractProtosTaskName = 'extract' + Utils.getSourceSetSubstringForTaskNames(sourceSetName) + 'Proto' Task task = project.tasks.findByName(extractProtosTaskName) @@ -466,7 +465,7 @@ class ProtobufPlugin implements Plugin { private void linkGenerateProtoTasksToSourceCompile() { if (Utils.isAndroidProject(project)) { (getNonTestVariants() + project.android.testVariants).each { variant -> - project.protobuf.generateProtoTasks.ofVariant(variant.name).each { GenerateProtoTask genProtoTask -> + this.protobufExtension.generateProtoTasks.ofVariant(variant.name).each { GenerateProtoTask genProtoTask -> SourceDirectorySet generatedSources = genProtoTask.getOutputSourceDirectorySet() // This cannot be called once task execution has started. variant.registerJavaGeneratingTask(genProtoTask, generatedSources.source) @@ -476,7 +475,7 @@ class ProtobufPlugin implements Plugin { } project.android.unitTestVariants.each { variant -> - project.protobuf.generateProtoTasks.ofVariant(variant.name).each { GenerateProtoTask genProtoTask -> + this.protobufExtension.generateProtoTasks.ofVariant(variant.name).each { GenerateProtoTask genProtoTask -> // unit test variants do not implement registerJavaGeneratingTask Task javaCompileTask = variant.javaCompileProvider.get() if (javaCompileTask != null) { @@ -490,7 +489,7 @@ class ProtobufPlugin implements Plugin { } } else { project.sourceSets.each { SourceSet sourceSet -> - project.protobuf.generateProtoTasks.ofSourceSet(sourceSet.name).each { GenerateProtoTask genProtoTask -> + this.protobufExtension.generateProtoTasks.ofSourceSet(sourceSet.name).each { GenerateProtoTask genProtoTask -> SUPPORTED_LANGUAGES.each { String lang -> linkGenerateProtoTasksToTaskName(sourceSet.getCompileTaskName(lang), genProtoTask) } diff --git a/src/main/kotlin/com/google/protobuf/gradle/ProtobufConfiguratorExts.kt b/src/main/kotlin/com/google/protobuf/gradle/ProtobufConfiguratorExts.kt index 7270b672..be679a2c 100644 --- a/src/main/kotlin/com/google/protobuf/gradle/ProtobufConfiguratorExts.kt +++ b/src/main/kotlin/com/google/protobuf/gradle/ProtobufConfiguratorExts.kt @@ -2,35 +2,10 @@ package com.google.protobuf.gradle import com.android.build.gradle.api.AndroidSourceSet import org.gradle.api.NamedDomainObjectContainer -import org.gradle.api.Project import org.gradle.api.file.SourceDirectorySet import org.gradle.api.plugins.ExtensionAware import org.gradle.api.tasks.SourceSet -import org.gradle.kotlin.dsl.NamedDomainObjectContainerScope -import org.gradle.kotlin.dsl.closureOf import org.gradle.kotlin.dsl.get -import org.gradle.kotlin.dsl.invoke - -/** - * Applies the supplied action to the project's instance of [ProtobufConfigurator]. - * - * @since 0.8.7 - * @usage - * ``` - * protobuf { - * ... - * generatedFilesBaseDir = files(...) - * } - * ``` - * - * @receiver [Project] The project for which the plugin configuration will be applied - * @param action A configuration lambda to apply on a receiver of type [ProtobufConfigurator] - * - * @return [Unit] - */ -fun Project.protobuf(action: ProtobufConfigurator.()->Unit) { - project.convention.getPlugin(ProtobufConvention::class.java).protobuf.apply(action) -} /** * Applies the supplied action to the "proto" [SourceDirectorySet] extension on @@ -58,7 +33,7 @@ fun SourceSet.proto(action: SourceDirectorySet.() -> Unit) { (this as? ExtensionAware) ?.extensions ?.getByName("proto") - ?.let { it as? SourceDirectorySet } + ?.let { it as? SourceDirectorySet } ?.apply(action) } @@ -90,61 +65,14 @@ fun AndroidSourceSet.proto(action: SourceDirectorySet.() -> Unit) { (this as? ExtensionAware) ?.extensions ?.getByName("proto") - ?.let { it as? SourceDirectorySet } + ?.let { it as? SourceDirectorySet } ?.apply(action) } -/** - * Uses the supplied action to configure the [ExecutableLocator] for protoc. - * - * @since 0.8.7 - * @usage - * ``` - * protobuf { - * protoc { - * artifact = "com.google.protobuf:protoc:3.6.1" - * } - * } - * ``` - * - * @receiver [ProtobufConfigurator] The protobuf plugin configuration instance - * for the project. - * - * @param action A lambda with receiver of type [ExecutableLocator] used - * for configuring the locator for protoc - * - * @return [Unit] - */ -fun ProtobufConfigurator.protoc(action: ExecutableLocator.() -> Unit) { - protoc(closureOf(action)) -} - -fun ProtobufConfigurator.plugins(action: NamedDomainObjectContainerScope.() -> Unit) { - plugins(closureOf> { - this.invoke(action) - }) -} - -fun ProtobufConfigurator.generateProtoTasks(action: ProtobufConfigurator.GenerateProtoTaskCollection.()->Unit) { - generateProtoTasks(closureOf(action)) -} - -fun GenerateProtoTask.builtins(action: NamedDomainObjectContainerScope.()->Unit) { - builtins(closureOf> { - this.invoke(action) - }) -} - -fun GenerateProtoTask.plugins(action: NamedDomainObjectContainerScope.()-> Unit) { - plugins(closureOf> { - this.invoke(action) - }) -} - /** * An extension for creating and configuring the elements of an instance of [NamedDomainObjectContainer]. * - * @since 0.8.7 + * @since 0.9.0 * @usage * ``` * protobuf { @@ -156,7 +84,7 @@ fun GenerateProtoTask.plugins(action: NamedDomainObjectContainerScope NamedDomainObjectContainerScope.id(id: String, action: (T.() -> Unit)? = null) { - action?.let { create(id, it) } - ?: create(id) +fun NamedDomainObjectContainer.id(id: String, action: (T.() -> Unit)? = null) { + action?.let { create(id, it) } ?: create(id) } - /** * An extension for removing an element by id on an instance of [NamedDomainObjectContainer]. * - * @since 0.8.7 + * @since 0.9.0 * @usage * ``` * protobuf { @@ -187,46 +113,13 @@ fun NamedDomainObjectContainerScope.id(id: String, action: (T.() -> * } * ``` * - * @receiver [NamedDomainObjectContainerScope] The scope of the [NamedDomainObjectContainer] + * @receiver [NamedDomainObjectContainer] The scope of the [NamedDomainObjectContainer] * on which to remove an element. * * @param id The string id of the element to remove. * * @return [Unit] */ -fun NamedDomainObjectContainerScope.remove(id: String) { +fun NamedDomainObjectContainer.remove(id: String) { remove(this[id]) } - -/** - * The method generatorProtoTasks applies the supplied closure to the - * instance of [ProtobufConfigurator.GenerateProtoTaskCollection]. - * - * Since [ProtobufConfigurator.JavaGenerateProtoTaskCollection] and [ProtobufConfigurator.AndroidGenerateProtoTaskCollection] - * each have unique methods, and only one instance is allocated per project, we need a way to statically resolve the - * available methods. This is a necessity since Kotlin does not have any dynamic method resolution capabilities. - */ - -fun ProtobufConfigurator.GenerateProtoTaskCollection.ofSourceSet(sourceSet: String): Collection = - if (this is ProtobufConfigurator.JavaGenerateProtoTaskCollection) - this.ofSourceSet(sourceSet) else emptyList() - -fun ProtobufConfigurator.GenerateProtoTaskCollection.ofFlavor(flavor: String): Collection = - if (this is ProtobufConfigurator.AndroidGenerateProtoTaskCollection) - this.ofFlavor(flavor) else emptyList() - -fun ProtobufConfigurator.GenerateProtoTaskCollection.ofBuildType(buildType: String): Collection = - if (this is ProtobufConfigurator.AndroidGenerateProtoTaskCollection) - this.ofBuildType(buildType) else emptyList() - -fun ProtobufConfigurator.GenerateProtoTaskCollection.ofVariant(variant: String): Collection = - if (this is ProtobufConfigurator.AndroidGenerateProtoTaskCollection) - this.ofVariant(variant) else emptyList() - -fun ProtobufConfigurator.GenerateProtoTaskCollection.ofNonTest(): Collection = - if (this is ProtobufConfigurator.AndroidGenerateProtoTaskCollection) - this.ofNonTest() else emptyList() - -fun ProtobufConfigurator.GenerateProtoTaskCollection.ofTest(): Collection = - if (this is ProtobufConfigurator.AndroidGenerateProtoTaskCollection) - this.ofTest() else emptyList() diff --git a/testProjectAndroidKotlinDsl/build.gradle.kts b/testProjectAndroidKotlinDsl/build.gradle.kts index 514388ab..c9b7ffc1 100644 --- a/testProjectAndroidKotlinDsl/build.gradle.kts +++ b/testProjectAndroidKotlinDsl/build.gradle.kts @@ -1,14 +1,6 @@ import com.android.build.gradle.api.BaseVariant -import com.google.protobuf.gradle.generateProtoTasks import com.google.protobuf.gradle.id -import com.google.protobuf.gradle.ofBuildType -import com.google.protobuf.gradle.ofFlavor -import com.google.protobuf.gradle.ofNonTest -import com.google.protobuf.gradle.ofVariant -import com.google.protobuf.gradle.plugins import com.google.protobuf.gradle.proto -import com.google.protobuf.gradle.protobuf -import com.google.protobuf.gradle.protoc plugins { id("com.android.application") @@ -160,7 +152,7 @@ afterEvaluate { } test { doLast { - val genProtoTasks = project.protobuf.protobuf.generateProtoTasks + val genProtoTasks = project.protobuf.generateProtoTasks val genProtoTaskNames = setOf( "generateArmFreeappDebugAndroidTestProto", diff --git a/testProjectBase/build_base.gradle b/testProjectBase/build_base.gradle index d29f5127..9b9fbe57 100644 --- a/testProjectBase/build_base.gradle +++ b/testProjectBase/build_base.gradle @@ -80,6 +80,11 @@ test.doLast { protobuf.generateProtoTasks.all().collect({ it.name }) as Set assert ['generateProto'] as Set == protobuf.generateProtoTasks.ofSourceSet('main').collect({ it.name }) as Set + assert [] as Set == protobuf.generateProtoTasks.ofTest().collect({ it.name }) as Set + assert [] as Set == protobuf.generateProtoTasks.ofNonTest().collect({ it.name }) as Set + assert [] as Set == protobuf.generateProtoTasks.ofFlavor('flavor-name').collect({ it.name }) as Set + assert [] as Set == protobuf.generateProtoTasks.ofBuildType('buildType-name').collect({ it.name }) as Set + assert [] as Set == protobuf.generateProtoTasks.ofVariant('variant-name').collect({ it.name }) as Set assertJavaCompileHasProtoGeneratedDir('main', ['java']) assertJavaCompileHasProtoGeneratedDir('test', ['java']) diff --git a/testProjectKotlinDslBase/build.gradle.kts b/testProjectKotlinDslBase/build.gradle.kts index 88c36452..badae357 100644 --- a/testProjectKotlinDslBase/build.gradle.kts +++ b/testProjectKotlinDslBase/build.gradle.kts @@ -8,11 +8,6 @@ plugins { id("com.google.protobuf") } -// This extension is not auto generated when we apply the plugin using -// apply(plugin = "com.google.protobuf") -val Project.protobuf: ProtobufConvention get() = - this.convention.getPlugin(ProtobufConvention::class) - repositories { maven("https://plugins.gradle.org/m2/") } @@ -84,7 +79,7 @@ tasks { "test"{ doLast{ - val generateProtoTasks = project.protobuf.protobuf.generateProtoTasks + val generateProtoTasks = project.protobuf.generateProtoTasks val generateProtoTaskNames = generateProtoTasks.all().map { it.name }.toSet() val generateProtoTaskNamesMain = generateProtoTasks.ofSourceSet("main").map { it.name }.toSet() diff --git a/testProjectKotlinDslCopySpec/build.gradle.kts b/testProjectKotlinDslCopySpec/build.gradle.kts index 887598aa..e63c9144 100644 --- a/testProjectKotlinDslCopySpec/build.gradle.kts +++ b/testProjectKotlinDslCopySpec/build.gradle.kts @@ -1,9 +1,4 @@ -import com.google.protobuf.gradle.generateProtoTasks import com.google.protobuf.gradle.id -import com.google.protobuf.gradle.ofSourceSet -import com.google.protobuf.gradle.plugins -import com.google.protobuf.gradle.protobuf -import com.google.protobuf.gradle.protoc buildscript { repositories {