Skip to content

Commit

Permalink
Pass agp version to android gradle runner in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rougsig committed Jun 26, 2022
1 parent f01ce9c commit fa34f3c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -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,12 +28,22 @@ 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()
Expand All @@ -42,7 +52,7 @@ final class ProtobufPluginTestHelper {
// set android build cache to avoid using home directory on CI.
// More details about that if can be found here:
// https://developer.android.com/studio/releases/gradle-plugin.html#build-cache-removed
if (gradleVersion.take(1) == "7") { // TODO: improve version comparison
if (agpVersion.take(1).toInteger() >= 4) { // TODO: improve version comparison
args.add("-PbuildCache.local.directory=$localBuildCache".toString())
args.add("-PbuildCache.local.removeUnusedEntriesAfterDays=7")
} else {
Expand Down

0 comments on commit fa34f3c

Please sign in to comment.