diff --git a/build.gradle b/build.gradle index fb6e6b92..8d7d4ecc 100644 --- a/build.gradle +++ b/build.gradle @@ -41,11 +41,7 @@ ext.isReleaseVersion = !version.endsWith("SNAPSHOT") repositories { maven { url "https://plugins.gradle.org/m2/" } - maven { url "https://repo.gradle.org/gradle/libs-releases-local/" } google() - // Needed for resolving 'kotlinx-metadata-jvm' - // A transitive dependency of gradle Kotlin DSL - maven { url "https://kotlin.bintray.com/kotlinx/" } } configurations { @@ -55,8 +51,9 @@ configurations { dependencies { compileOnly "com.android.tools.build:gradle:4.1.0" + compileOnly "org.jetbrains.kotlin.android:org.jetbrains.kotlin.android.gradle.plugin:1.7.22" - implementation 'com.google.gradle:osdetector-gradle-plugin:1.7.1' + implementation 'com.google.gradle:osdetector-gradle-plugin:1.7.3' testImplementation 'junit:junit:4.12' testImplementation('org.spockframework:spock-core:1.0-groovy-2.4') { diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy index 0de530f8..2e380022 100644 --- a/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy @@ -38,6 +38,7 @@ import org.gradle.api.Action import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.Project import org.gradle.api.provider.Property +import org.gradle.api.provider.Provider import org.gradle.api.tasks.TaskCollection /** @@ -54,14 +55,16 @@ abstract class ProtobufExtension { private final NamedDomainObjectContainer sourceSets @PackageScope - final String defaultGeneratedFilesBaseDir + final Provider defaultGeneratedFilesBaseDir public ProtobufExtension(final Project project) { this.project = project this.tasks = new GenerateProtoTaskCollection(project) this.tools = new ToolsLocator(project) this.taskConfigActions = [] - this.defaultGeneratedFilesBaseDir = "${project.buildDir}/generated/source/proto" + this.defaultGeneratedFilesBaseDir = project.layout.buildDirectory.dir("generated/source/proto").map { + it.asFile.path + } this.generatedFilesBaseDirProperty.convention(defaultGeneratedFilesBaseDir) this.sourceSets = project.objects.domainObjectContainer(ProtoSourceSet) { String name -> new DefaultProtoSourceSet(name, project.objects) diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy index 9853f0ee..fe2a5875 100644 --- a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy @@ -55,9 +55,9 @@ import org.gradle.api.internal.artifacts.ArtifactAttributes import org.gradle.api.plugins.AppliedPlugin import org.gradle.api.provider.Provider import org.gradle.api.tasks.SourceSet -import org.gradle.api.tasks.SourceTask import org.gradle.language.jvm.tasks.ProcessResources import org.gradle.util.GradleVersion +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile /** * The main class for the protobuf plugin. @@ -349,7 +349,7 @@ class ProtobufPlugin implements Plugin { project.plugins.withId("org.jetbrains.kotlin.android") { project.afterEvaluate { String compileKotlinTaskName = Utils.getKotlinAndroidCompileTaskName(project, variant.name) - project.tasks.named(compileKotlinTaskName, SourceTask) { SourceTask task -> + project.tasks.named(compileKotlinTaskName, KotlinCompile) { KotlinCompile task -> task.dependsOn(generateProtoTask) task.source(generateProtoTask.get().outputSourceDirectories) } @@ -374,20 +374,20 @@ class ProtobufPlugin implements Plugin { ) { String sourceSetName = protoSourceSet.name String taskName = 'generate' + Utils.getSourceSetSubstringForTaskNames(sourceSetName) + 'Proto' - String defaultGeneratedFilesBaseDir = protobufExtension.defaultGeneratedFilesBaseDir + Provider defaultGeneratedFilesBaseDir = protobufExtension.defaultGeneratedFilesBaseDir Provider generatedFilesBaseDirProvider = protobufExtension.generatedFilesBaseDirProperty Provider task = project.tasks.register(taskName, GenerateProtoTask) { CopyActionFacade copyActionFacade = CopyActionFacade.Loader.create(it.project, it.objectFactory) it.description = "Compiles Proto source for '${sourceSetName}'".toString() - it.outputBaseDir = project.providers.provider { - "${defaultGeneratedFilesBaseDir}/${sourceSetName}".toString() + it.outputBaseDir = defaultGeneratedFilesBaseDir.map { + "${it}/${sourceSetName}".toString() } it.addSourceDirs(protoSourceSet.proto) it.addIncludeDir(protoSourceSet.proto.sourceDirectories) it.addIncludeDir(protoSourceSet.includeProtoDirs) it.doLast { task -> String generatedFilesBaseDir = generatedFilesBaseDirProvider.get() - if (generatedFilesBaseDir == defaultGeneratedFilesBaseDir) { + if (generatedFilesBaseDir == defaultGeneratedFilesBaseDir.get()) { return } // Purposefully don't wire this up to outputs, as it can be mixed with other files. diff --git a/src/test/groovy/com/google/protobuf/gradle/ProtobufAndroidPluginKotlinTest.groovy b/src/test/groovy/com/google/protobuf/gradle/ProtobufAndroidPluginKotlinTest.groovy index 55075117..ea767e30 100644 --- a/src/test/groovy/com/google/protobuf/gradle/ProtobufAndroidPluginKotlinTest.groovy +++ b/src/test/groovy/com/google/protobuf/gradle/ProtobufAndroidPluginKotlinTest.groovy @@ -8,9 +8,9 @@ import spock.lang.Unroll @CompileDynamic class ProtobufAndroidPluginKotlinTest extends Specification { - private static final List GRADLE_VERSION = ["5.6", "6.5.1", "7.4.2"] - private static final List ANDROID_PLUGIN_VERSION = ["3.5.0", "4.1.0", "7.2.1"] - private static final List KOTLIN_VERSION = ["1.3.20", "1.3.20", "1.3.40"] + private static final List GRADLE_VERSION = ["5.6", "6.5.1", "7.4.2", "7.6"] + private static final List ANDROID_PLUGIN_VERSION = ["3.5.0", "4.1.0", "7.2.1", "7.3.1"] + private static final List KOTLIN_VERSION = ["1.3.20", "1.3.20", "1.3.40", "1.7.20"] /** * This test may take a significant amount of Gradle daemon Metaspace memory in some diff --git a/src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy b/src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy index 8798574e..ce58fabc 100644 --- a/src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy +++ b/src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy @@ -15,8 +15,8 @@ import spock.lang.Unroll @CompileDynamic class ProtobufJavaPluginTest extends Specification { // Current supported version is Gradle 5+. - private static final List GRADLE_VERSIONS = ["5.6", "6.0", "6.7.1", "7.4.2"] - private static final List KOTLIN_VERSIONS = ["1.3.20", "1.3.31", "1.3.40"] + private static final List GRADLE_VERSIONS = ["5.6", "6.0", "6.7.1", "7.4.2", "7.6"] + private static final List KOTLIN_VERSIONS = ["1.3.72", "1.4.32", "1.5.32", "1.6.21", "1.7.21"] void "testApplying java and com.google.protobuf adds corresponding task to project"() { given: "a basic project with java and com.google.protobuf" @@ -69,6 +69,18 @@ class ProtobufJavaPluginTest extends Specification { assert project.tasks.extractMain2Proto instanceof ProtobufExtract } + void "test buildDir is late bound"() { + given: "a basic project with java and com.google.protobuf" + Project project = setupBasicProject() + + when: "project evaluated" + project.evaluate() + project.buildDir = "expect-the-unexpected" + + then: "generate tasks added" + assert project.tasks.generateProto.outputBaseDir.contains("/expect-the-unexpected/") + } + @Unroll void "testProject should be successfully executed (java-only project) [gradle #gradleVersion]"() { given: "project from testProject" @@ -196,7 +208,8 @@ class ProtobufJavaPluginTest extends Specification { ProtobufPluginTestHelper.verifyProjectDir(projectDir) where: - [gradleVersion, kotlinVersion] << [GRADLE_VERSIONS, KOTLIN_VERSIONS].combinations() + gradleVersion << GRADLE_VERSIONS + kotlinVersion << KOTLIN_VERSIONS } @Unroll @@ -219,7 +232,8 @@ class ProtobufJavaPluginTest extends Specification { ProtobufPluginTestHelper.verifyProjectDir(projectDir) where: - [gradleVersion, kotlinVersion] << [GRADLE_VERSIONS, KOTLIN_VERSIONS].combinations() + gradleVersion << GRADLE_VERSIONS + kotlinVersion << KOTLIN_VERSIONS } @Unroll diff --git a/src/test/groovy/com/google/protobuf/gradle/ProtobufPluginTestHelper.groovy b/src/test/groovy/com/google/protobuf/gradle/ProtobufPluginTestHelper.groovy index 06f14721..2375dbfe 100644 --- a/src/test/groovy/com/google/protobuf/gradle/ProtobufPluginTestHelper.groovy +++ b/src/test/groovy/com/google/protobuf/gradle/ProtobufPluginTestHelper.groovy @@ -38,6 +38,7 @@ final class ProtobufPluginTestHelper { .withProjectDir(projectDir) .withArguments(args) .withGradleVersion(gradleVersion) + .withEnvironment(System.getenv()) // Enable forking .forwardStdOutput(new OutputStreamWriter(System.out)) .forwardStdError(new OutputStreamWriter(System.err)) }