Skip to content

Commit

Permalink
Update AGP version to 7.4 (#353)
Browse files Browse the repository at this point in the history
* AGP Update

* Update build files

* Update more buildscripts

* Fix formatting
  • Loading branch information
runningcode authored Jun 13, 2024
1 parent 62651d9 commit b75b3c9
Show file tree
Hide file tree
Showing 67 changed files with 2,357 additions and 2,050 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
root = true

[*.{kt,kts}]
indent_size = 2
5 changes: 3 additions & 2 deletions .github/workflows/gradle-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: gradle/actions/wrapper-validation@v3
- uses: actions/setup-java@v4
- name: "Set up JDK 11"
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '8'
java-version: '11'
- uses: gradle/actions/setup-gradle@v3
name: Setup Gradle
- name: Check Fladle
Expand Down
16 changes: 13 additions & 3 deletions android-library-no-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@ plugins {
}

android {
compileSdkVersion(29)
compileSdk = 33
namespace = "com.osacky.flank.gradle.sample.library"
defaultConfig {
minSdkVersion(23)
targetSdkVersion(29)
minSdk = 23
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}

fulladleModuleConfig {
Expand Down
2 changes: 1 addition & 1 deletion android-library-no-tests/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.osacky.flank.gradle.sample.library"/>
<manifest />
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
Expand Down
12 changes: 2 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,16 @@ plugins {
alias(libs.plugins.kotlinter)
}

kotlinter {
indentSize = 2
}

allprojects {
apply plugin: "org.jmailen.kotlinter"

kotlinter {
indentSize = 2
}
}

fladle {
serviceAccountCredentials = project.layout.projectDirectory.file("sample/flank-gradle-5cf02dc90531.json")
}

tasks.named('wrapper').configure {
gradleVersion = '7.6.3'
tasks.wrapper.configure {
gradleVersion = '8.4'
}

def isNonStable = { String version ->
Expand Down
14 changes: 5 additions & 9 deletions fladle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ dependencies {
testImplementation(libs.truth)
}

kotlinter {
indentSize = 2
}

gradlePlugin {
website.set("https://github.com/runningcode/fladle")
vcsUrl.set("https://github.com/runningcode/fladle")
Expand Down Expand Up @@ -136,17 +132,17 @@ tasks.withType(ValidatePlugins::class.java).configureEach {
enableStricterValidation.set(true)
}

// Ensure Java 8 Compatibility. See https://github.com/runningcode/fladle/issues/246
// Ensure Java 11 Compatibility. See https://github.com/runningcode/fladle/issues/246
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java).configureEach {
kotlinOptions {
jvmTarget = "1.8"
languageVersion = "1.4"
apiVersion = "1.4"
jvmTarget = "11"
languageVersion = "1.7"
apiVersion = "1.7"
}
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
languageVersion.set(JavaLanguageVersion.of(11))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ interface FladleConfig {

@Deprecated(
message = "testShards is deprecated. Use maxTestShards instead",
replaceWith = ReplaceWith("maxTestShards")
replaceWith = ReplaceWith("maxTestShards"),
)
/**
* The maximum number of shards. Value will be overwritten by [maxTestShards] if both used in configuration
Expand Down Expand Up @@ -472,13 +472,14 @@ interface FladleConfig {
val additionalGcloudOptions: Property<String>

@Internal
fun getPresentProperties() = this::class.memberProperties
.filter {
when (val prop = it.call(this)) {
is Property<*> -> prop.isPresent
is MapProperty<*, *> -> prop.isPresent && prop.get().isNotEmpty()
is ListProperty<*> -> prop.isPresent && prop.get().isNotEmpty()
else -> false
fun getPresentProperties() =
this::class.memberProperties
.filter {
when (val prop = it.call(this)) {
is Property<*> -> prop.isPresent
is MapProperty<*, *> -> prop.isPresent && prop.get().isNotEmpty()
is ListProperty<*> -> prop.isPresent && prop.get().isNotEmpty()
else -> false
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ data class FladleConfigImpl(
override val additionalFlankOptions: Property<String>,
override val additionalGcloudOptions: Property<String>,
override val dependOnAssemble: Property<Boolean>,
override val async: Property<Boolean>
override val async: Property<Boolean>,
) : FladleConfig {
/**
* Prepare config to run sanity robo.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import org.gradle.kotlin.dsl.create
import org.gradle.util.GradleVersion

class FladlePluginDelegate {

fun apply(target: Project) {
checkMinimumGradleVersion()

Expand All @@ -41,7 +40,10 @@ class FladlePluginDelegate {
}
}

private fun configureTasks(project: Project, base: FlankGradleExtension) {
private fun configureTasks(
project: Project,
base: FlankGradleExtension,
) {
if (GradleVersion.current() > GradleVersion.version("6.1")) {
base.flankVersion.finalizeValueOnRead()
base.flankCoordinates.finalizeValueOnRead()
Expand Down Expand Up @@ -70,21 +72,26 @@ class FladlePluginDelegate {
}
}

private fun TaskContainer.createTasksForConfig(base: FlankGradleExtension, config: FladleConfig, project: Project, name: String) {

private fun TaskContainer.createTasksForConfig(
base: FlankGradleExtension,
config: FladleConfig,
project: Project,
name: String,
) {
val configName = name.toLowerCase()
// we want to use default dir only if user did not set own `localResultsDir`
val useDefaultDir = config.localResultsDir.isPresent.not()

val validateFladle = register("validateFladleConfig$name") {
description = "Perform validation actions"
group = TASK_GROUP
doLast {
checkIfSanityAndValidateConfigs(config)
validateOptionsUsed(config = config, flank = base.flankVersion.get())
checkForExclusionUsage(config)
val validateFladle =
register("validateFladleConfig$name") {
description = "Perform validation actions"
group = TASK_GROUP
doLast {
checkIfSanityAndValidateConfigs(config)
validateOptionsUsed(config = config, flank = base.flankVersion.get())
checkForExclusionUsage(config)
}
}
}

val writeConfigProps = register("writeConfigProps$name", YamlConfigWriterTask::class.java, base, config, name)

Expand Down Expand Up @@ -112,17 +119,25 @@ class FladlePluginDelegate {
if (useDefaultDir) setUpWorkingDir(configName)
description = "Runs instrumentation tests using flank on firebase test lab."
classpath = project.fladleConfig
args = if (project.hasProperty("dumpShards")) {
listOf("firebase", "test", "android", "run", "-c", writeConfigProps.get().fladleConfigFile.get().asFile.absolutePath, "--dump-shards")
} else {
listOf("firebase", "test", "android", "run", "-c", writeConfigProps.get().fladleConfigFile.get().asFile.absolutePath)
}
args =
if (project.hasProperty("dumpShards")) {
listOf(
"firebase", "test", "android", "run", "-c",
writeConfigProps.get().fladleConfigFile.get().asFile.absolutePath, "--dump-shards",
)
} else {
listOf(
"firebase", "test", "android", "run", "-c",
writeConfigProps.get().fladleConfigFile.get().asFile.absolutePath,
)
}
if (config.serviceAccountCredentials.isPresent) {
environment(mapOf("GOOGLE_APPLICATION_CREDENTIALS" to config.serviceAccountCredentials.get()))
}
dependsOn(writeConfigProps)
if (config.dependOnAssemble.isPresent && config.dependOnAssemble.get()) {
val testedExtension = requireNotNull(project.extensions.findByType(TestedExtension::class.java)) { "Could not find TestedExtension in ${project.name}" }
val testedExtension =
requireNotNull(project.extensions.findByType(TestedExtension::class.java)) { "Could not find TestedExtension in ${project.name}" }
testedExtension.testVariants.configureEach {
if (testedVariant.isExpectedVariant(config)) {
if (testedVariant.assembleProvider.isPresent) {
Expand Down Expand Up @@ -154,19 +169,28 @@ class FladlePluginDelegate {
}
}

private fun automaticallyConfigureTestOrchestrator(project: Project, config: FladleConfig, androidExtension: AppExtension) {
private fun automaticallyConfigureTestOrchestrator(
project: Project,
config: FladleConfig,
androidExtension: AppExtension,
) {
project.afterEvaluate {
val useOrchestrator = androidExtension.testOptions.getExecutionEnum() == TestOptions.Execution.ANDROIDX_TEST_ORCHESTRATOR ||
androidExtension.testOptions.getExecutionEnum() == TestOptions.Execution.ANDROID_TEST_ORCHESTRATOR
val useOrchestrator =
androidExtension.testOptions.getExecutionEnum() == TestOptions.Execution.ANDROIDX_TEST_ORCHESTRATOR ||
androidExtension.testOptions.getExecutionEnum() == TestOptions.Execution.ANDROID_TEST_ORCHESTRATOR
if (useOrchestrator) {
log("Automatically detected the use of Android Test Orchestrator")
}
config.useOrchestrator.set(useOrchestrator)
}
}

private fun findDebugAndInstrumentationApk(project: Project, config: FladleConfig) {
val baseExtension = requireNotNull(project.extensions.findByType(AppExtension::class.java)) { "Could not find AppExtension in ${project.name}" }
private fun findDebugAndInstrumentationApk(
project: Project,
config: FladleConfig,
) {
val baseExtension =
requireNotNull(project.extensions.findByType(AppExtension::class.java)) { "Could not find AppExtension in ${project.name}" }
automaticallyConfigureTestOrchestrator(project, config, baseExtension)
baseExtension.testVariants.configureEach {
val appVariant = testedVariant
Expand Down Expand Up @@ -195,9 +219,10 @@ class FladlePluginDelegate {
get() = configurations.getByName(FLADLE_CONFIG)

companion object {
val GRADLE_MIN_VERSION: GradleVersion = GradleVersion.version("5.5")
val GRADLE_MIN_VERSION: GradleVersion = GradleVersion.version("6.5")
const val TASK_GROUP = "fladle"
const val FLADLE_CONFIG = "fladle"

fun Project.log(message: String) {
logger.info("Fladle: $message")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,26 @@ import org.gradle.api.tasks.Nested
import org.gradle.work.DisableCachingByDefault
import javax.inject.Inject

@DisableCachingByDefault(because = "Flank executions are dependent on resources such as network connection and server and therefore cannot be cached.")
open class FlankExecutionTask @Inject constructor(projectLayout: ProjectLayout, @get:Nested val config: FladleConfig) : FlankJavaExec(projectLayout) {

init {
doFirst {
checkFilesExist(config)
@DisableCachingByDefault(
because = "Flank executions are dependent on resources such as network connection and server and therefore cannot be cached.",
)
open class FlankExecutionTask
@Inject
constructor(
projectLayout: ProjectLayout,
@get:Nested val config: FladleConfig,
) : FlankJavaExec(projectLayout) {
init {
doFirst {
checkFilesExist(config)
}
}
}

private fun checkFilesExist(base: FladleConfig) {
if (base.serviceAccountCredentials.isPresent) {
check(base.serviceAccountCredentials.get().asFile.exists()) { "serviceAccountCredential file doesn't exist ${base.serviceAccountCredentials.get()}" }
private fun checkFilesExist(base: FladleConfig) {
if (base.serviceAccountCredentials.isPresent) {
check(base.serviceAccountCredentials.get().asFile.exists()) {
"serviceAccountCredential file doesn't exist ${base.serviceAccountCredentials.get()}"
}
}
}
}
}
Loading

0 comments on commit b75b3c9

Please sign in to comment.