Skip to content

Commit

Permalink
Add gradle 7.4.2 to tests and agp 7.2.1 support (#565)
Browse files Browse the repository at this point in the history
Also bump java version to 11. agp 7.2.1 requires java 11.

Add AndroidSourceSet.proto extension for agp 7+. More details can be
found here:
#540

Set pipelines 30mins timeout since builds can hang when they run out
of memory. Increase memory limit from 512m to 1024m for android gradle
test runner
  • Loading branch information
rougsig authored Jul 7, 2022
1 parent bbba8c1 commit 6a71480
Show file tree
Hide file tree
Showing 22 changed files with 150 additions and 64 deletions.
1 change: 1 addition & 0 deletions .github/workflows/gradle-wrapper-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ jobs:
validation:
name: "Validation"
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- uses: gradle/wrapper-validation-action@v1
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ permissions:
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
with:
java-version: '8'
java-version: '11'
distribution: 'temurin'
- uses: gradle/gradle-build-action@v2
with:
Expand All @@ -28,11 +29,12 @@ jobs:
matrix:
tests: [ProtobufJavaPluginTest, ProtobufKotlinDslCopySpecTest, ProtobufKotlinDslPluginTest, ProtobufAndroidPluginTest, ProtobufAndroidPluginKotlinTest, AndroidProjectDetectionTest]
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
with:
java-version: '8'
java-version: '11'
distribution: 'temurin'
- uses: gradle/gradle-build-action@v2
with:
Expand All @@ -41,11 +43,12 @@ jobs:
codenarc:
needs: build
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
with:
java-version: '8'
java-version: '11'
distribution: 'temurin'
- uses: gradle/gradle-build-action@v2
with:
Expand Down
22 changes: 9 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ configurations {
}

dependencies {
compileOnly "com.android.tools.build:gradle:3.5.0"
compileOnly "com.android.tools.build:gradle:4.1.0"

implementation 'com.google.guava:guava:27.0.1-jre'
implementation 'com.google.gradle:osdetector-gradle-plugin:1.7.0'
Expand Down Expand Up @@ -92,8 +92,8 @@ codenarc {
toolVersion = "1.4"
}

sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

tasks.withType(GenerateModuleMetadata) {
enabled = false
Expand Down Expand Up @@ -170,16 +170,6 @@ pluginBundle {
}
}

// Releases must be built on Java 1.8.
tasks.create("checkJavaVersion").doLast {
JavaVersion javaVersion = JavaVersion.current()
if (!javaVersion.isJava8()) {
throw new GradleException(
"The plugin must be published under Java 1.8 but ${javaVersion} is found")
}
}
[uploadArchives, publishPlugins]*.dependsOn checkJavaVersion

if (System.env.CI == 'true') {
// Normally html output is more user friendly,
// but we want a console printable file for CI logs
Expand All @@ -196,3 +186,9 @@ tasks.named('compileGroovy') {
tasks.named('compileKotlin') {
compileKotlin.classpath += files(compileGroovy.destinationDirectory)
}

test {
testLogging {
events = ["standard_out", "standard_error", "started", "passed", "failed", "skipped"]
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.google.protobuf.gradle

import com.android.build.gradle.api.AndroidSourceSet
import com.android.build.api.dsl.AndroidSourceSet
import com.android.build.gradle.api.AndroidSourceSet as DeprecatedAndroidSourceSet
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project
import org.gradle.api.file.SourceDirectorySet
Expand Down Expand Up @@ -64,7 +65,7 @@ fun SourceSet.proto(action: SourceDirectorySet.() -> Unit) {

/**
* Applies the supplied action to the "proto" [SourceDirectorySet] extension on
* a receiver of type [AndroidSourceSet] for Android builds.
* a receiver of type [DeprecatedAndroidSourceSet] for Android builds.
*
* @since 0.8.15
* @usage
Expand All @@ -80,6 +81,38 @@ fun SourceSet.proto(action: SourceDirectorySet.() -> Unit) {
* }
* ```
*
* @receiver [DeprecatedAndroidSourceSet] The Android source set for which the "proto"
* [SourceDirectorySet] extension will be configured
*
* @param action A configuration lambda to apply on a receiver of type [SourceDirectorySet]
* @return [Unit]
*/
fun DeprecatedAndroidSourceSet.proto(action: SourceDirectorySet.() -> Unit) {
(this as? ExtensionAware)
?.extensions
?.getByName("proto")
?.let { it as? SourceDirectorySet }
?.apply(action)
}

/**
* Applies the supplied action to the "proto" [SourceDirectorySet] extension on
* a receiver of type [AndroidSourceSet] for Android builds.
*
* @since 0.9.0
* @usage
* ```
* android {
* sourceSets {
* create("sample") {
* proto {
* srcDir("src/sample/protobuf")
* }
* }
* }
* }
* ```
*
* @receiver [AndroidSourceSet] The Android source set for which the "proto"
* [SourceDirectorySet] extension will be configured
*
Expand All @@ -90,7 +123,7 @@ fun AndroidSourceSet.proto(action: SourceDirectorySet.() -> Unit) {
(this as? ExtensionAware)
?.extensions
?.getByName("proto")
?.let { it as? SourceDirectorySet }
?.let { it as? SourceDirectorySet }
?.apply(action)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import spock.lang.Unroll
*/
@CompileDynamic
class AndroidProjectDetectionTest extends Specification {
private static final List<String> GRADLE_VERSION = ["5.6"]
private static final List<String> ANDROID_PLUGIN_VERSION = ["3.5.0"]
private static final List<String> GRADLE_VERSION = ["5.6", "7.4.2"]
private static final List<String> ANDROID_PLUGIN_VERSION = ["3.5.0", "7.2.1"]

static void appendUtilIsAndroidProjectCheckTask(File buildFile, boolean assertResult) {
buildFile << """
Expand All @@ -39,9 +39,10 @@ class AndroidProjectDetectionTest extends Specification {

when: "checkForAndroidPlugin task evaluates Utils.isAndroidProject"
BuildResult result = buildAndroidProject(
mainProjectDir,
gradleVersion,
"checkForAndroidPlugin"
mainProjectDir,
gradleVersion,
agpVersion,
"checkForAndroidPlugin"
)

then: "Utils.isAndroidProject evaluation matched assertion in task checkForAndroidPlugin"
Expand Down Expand Up @@ -73,6 +74,7 @@ class AndroidProjectDetectionTest extends Specification {
BuildResult result = buildAndroidProject(
mainProjectDir,
gradleVersion,
agpVersion,
"checkForAndroidPlugin"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import spock.lang.Unroll

@CompileDynamic
class ProtobufAndroidPluginKotlinTest extends Specification {
private static final List<String> GRADLE_VERSION = ["5.6", "6.5-milestone-1"]
private static final List<String> ANDROID_PLUGIN_VERSION = ["3.5.0", "4.1.0-alpha10"]
private static final List<String> KOTLIN_VERSION = ["1.3.20"]
private static final List<String> GRADLE_VERSION = ["5.6", "6.5-milestone-1", "7.4.2"]
private static final List<String> ANDROID_PLUGIN_VERSION = ["3.5.0", "4.1.0-alpha10", "7.2.1"]
private static final List<String> KOTLIN_VERSION = ["1.3.20", "1.3.20", "1.3.40"]

/**
* This test may take a significant amount of Gradle daemon Metaspace memory in some
Expand All @@ -37,9 +37,10 @@ class ProtobufAndroidPluginKotlinTest extends Specification {
.build()
when: "build is invoked"
BuildResult result = buildAndroidProject(
mainProjectDir,
gradleVersion,
"testProjectAndroid:build"
mainProjectDir,
gradleVersion,
agpVersion,
"testProjectAndroid:build"
)

then: "it succeed"
Expand All @@ -48,6 +49,6 @@ class ProtobufAndroidPluginKotlinTest extends Specification {
where:
agpVersion << ANDROID_PLUGIN_VERSION
gradleVersion << GRADLE_VERSION
kotlinVersion << KOTLIN_VERSION + KOTLIN_VERSION
kotlinVersion << KOTLIN_VERSION
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import spock.lang.Unroll
*/
@CompileDynamic
class ProtobufAndroidPluginTest extends Specification {
private static final List<String> GRADLE_VERSION = ["5.6", "6.5", "6.8"]
private static final List<String> ANDROID_PLUGIN_VERSION = ["3.5.0", "4.1.0", "4.2.0-alpha10"]
private static final List<String> GRADLE_VERSION = ["5.6", "6.5", "6.8", "7.4.2"]
private static final List<String> ANDROID_PLUGIN_VERSION = ["3.5.0", "4.1.0", "4.2.0-alpha10", "7.2.1"]

@Unroll
void "testProjectAndroid should be successfully executed [android #agpVersion, gradle #gradleVersion]"() {
Expand All @@ -36,9 +36,10 @@ class ProtobufAndroidPluginTest extends Specification {
.build()
when: "build is invoked"
BuildResult result = buildAndroidProject(
mainProjectDir,
gradleVersion,
"testProjectAndroid:build"
mainProjectDir,
gradleVersion,
agpVersion,
"testProjectAndroid:build"
)

then: "it succeed"
Expand Down Expand Up @@ -69,6 +70,7 @@ class ProtobufAndroidPluginTest extends Specification {
GradleRunner runner = getAndroidGradleRunner(
mainProjectDir,
gradleVersion,
agpVersion,
"testProjectAndroid:assembleDebug",
"-Dorg.gradle.unsafe.configuration-cache=true"
)
Expand All @@ -94,6 +96,7 @@ class ProtobufAndroidPluginTest extends Specification {
buildAndroidProject(
mainProjectDir,
gradleVersion,
agpVersion,
"testProjectAndroid:clean",
"-Dorg.gradle.unsafe.configuration-cache=true"
)
Expand Down Expand Up @@ -127,6 +130,7 @@ class ProtobufAndroidPluginTest extends Specification {
BuildResult result = buildAndroidProject(
mainProjectDir,
gradleVersion,
agpVersion,
"testProjectAndroid:build"
)

Expand Down Expand Up @@ -158,6 +162,7 @@ class ProtobufAndroidPluginTest extends Specification {
BuildResult result = buildAndroidProject(
mainProjectDir,
gradleVersion,
agpVersion,
"testProjectAndroid:assembleAndroidTest"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ 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.7.1"]
private static final List<String> KOTLIN_VERSIONS = ["1.3.20", "1.3.30"]
private static final List<String> GRADLE_VERSIONS = ["5.6", "6.0", "6.7.1", "7.4.2"]
private static final List<String> KOTLIN_VERSIONS = ["1.3.20", "1.3.31", "1.3.40"]

void "testApplying java and com.google.protobuf adds corresponding task to project"() {
given: "a basic project with java and com.google.protobuf"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import spock.lang.Unroll
*/
@CompileDynamic
class ProtobufKotlinDslCopySpecTest extends Specification {
private static final List<String> GRADLE_VERSIONS = ["5.6", "6.0", "6.7.1", "7.0"]
private static final List<String> GRADLE_VERSIONS = ["5.6", "6.0", "6.7.1", "7.0", "7.4.2"]

@Unroll
void "testProjectKotlinDslCopySpec should declare explicit copy spec [gradle #gradleVersion]"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import spock.lang.Unroll
*/
@CompileDynamic
class ProtobufKotlinDslPluginTest extends Specification {
private static final List<String> GRADLE_VERSIONS = ["5.6", "6.1.1", "6.5"]
private static final List<String> ANDROID_PLUGIN_VERSION = ["3.5.0", "4.0.0", "4.1.0"]
private static final List<String> GRADLE_VERSIONS = ["5.6", "6.1.1", "6.5", "7.4.2"]
private static final List<String> ANDROID_PLUGIN_VERSION = ["3.5.0", "4.0.0", "4.1.0", "7.2.1"]

@Unroll
void "testProjectKotlinDsl should be successfully executed (java-only project) [gradle #gradleVersion]"() {
Expand Down Expand Up @@ -61,9 +61,10 @@ class ProtobufKotlinDslPluginTest extends Specification {
when: "build is invoked"
BuildResult result = buildAndroidProject(
mainProjectDir,
gradleVersion,
"testProjectAndroidKotlinDsl:build"
mainProjectDir,
gradleVersion,
agpVersion,
"testProjectAndroidKotlinDsl:build"
)
then: "it succeed"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,43 @@ final class ProtobufPluginTestHelper {
}

static BuildResult buildAndroidProject(
File mainProjectDir, String gradleVersion, String fullPathTask, String... arguments) {
return getAndroidGradleRunner(mainProjectDir, gradleVersion, fullPathTask, arguments).build()
File mainProjectDir,
String gradleVersion,
String agpVersion,
String fullPathTask,
String... arguments
) {
return getAndroidGradleRunner(mainProjectDir, gradleVersion, agpVersion, fullPathTask, arguments).build()
}

static GradleRunner getAndroidGradleRunner(
File mainProjectDir, String gradleVersion, String fullPathTask, String... arguments) {
File mainProjectDir,
String gradleVersion,
String agpVersion,
String fullPathTask,
String... arguments
) {
File localBuildCache = new File(mainProjectDir, ".buildCache")
if (localBuildCache.exists()) {
localBuildCache.deleteDir()
}
List<String> args = arguments.toList()
// set android build cache to avoid using home directory on CI.
args.add("-Pandroid.buildCacheDir=$localBuildCache".toString())
// More details about that if can be found here:
// https://developer.android.com/studio/releases/gradle-plugin.html#build-cache-removed
args.add("-Dorg.gradle.caching=false")
if (agpVersion.take(1).toInteger() <= 4) { // TODO: improve version comparison
args.add("-Pandroid.buildCacheDir=$localBuildCache".toString())
}

args.add(fullPathTask)
args.add("--stacktrace")
// DSL element 'dexOptions' is obsolete and should be removed.
// It will be removed in version 8.0 of the Android Gradle plugin.
// Using it has no effect, and the AndroidGradle plugin optimizes dexing automatically.
//
// Set memory limit for all gradle build, not only for dexing
args.add("-Dorg.gradle.jvmargs=-Xmx1g")
return GradleRunner.create()
.withProjectDir(mainProjectDir)
.withArguments(args)
Expand Down
4 changes: 2 additions & 2 deletions testProjectAndroidBare/build_base.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
Loading

0 comments on commit 6a71480

Please sign in to comment.