Skip to content

Fix various Gradle warnings #7164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ fun FirebaseLibraryExtension.resolveProjectLevelDependencies() =
.allDependencies
.mapNotNull { it as? ProjectDependency }
.map {
it.dependencyProject.extensions.findByType<FirebaseLibraryExtension>()
project.project(it.dependencyProject.path).extensions.findByType<FirebaseLibraryExtension>()
?: throw RuntimeException(
"Project level dependencies must have the firebaseLibrary plugin. The following dependency does not: ${it.artifactName}"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ data class Change(val type: ChangeType, val message: String) {
fun fromString(string: String): Change {
val (type, description) = REGEX.findOrThrow(string).destructured

return Change(ChangeType.valueOf(type.toUpperCase()), description.trim())
return Change(ChangeType.valueOf(type.uppercase()), description.trim())
}
}
}
Expand All @@ -384,5 +384,5 @@ enum class ChangeType {
REMOVED,
DEPRECATED;

override fun toString(): String = name.toLowerCase()
override fun toString(): String = name.lowercase()
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ import org.gradle.workers.WorkQueue
*
* Syntax sugar for:
* ```
* project.file("${project.buildDir}/$path)
* project.file("${project.layout.buildDirectory.get().asFile}/$path)
* ```
*/
fun Project.fileFromBuildDir(path: String) = file("$buildDir/$path")
fun Project.fileFromBuildDir(path: String) = file("${layout.buildDirectory.get().asFile}/$path")

/**
* Maps a file provider to another file provider as a sub directory.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fun computeLibraryGroups(project: Project): Map<String, List<FirebaseLibraryExte
}

fun fixLibraryGroupVersions(libraryGroups: Map<String, List<FirebaseLibraryExtension>>) {
for ((name, libraryGroup) in libraryGroups) {
for ((_, libraryGroup) in libraryGroups) {
val maxVersion =
libraryGroup.mapNotNull { it.moduleVersion }.maxOrNull()?.toString() ?: continue
for (firebaseExtension in libraryGroup) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ abstract class MakeReleaseNotesTask : DefaultTask() {
"GitHub [#$id](//github.com/firebase/firebase-android-sdk/issues/$id){: .external}"
}

return "* {{${type.name.toLowerCase()}}} $fixedMessage"
return "* {{${type.name.lowercase()}}} $fixedMessage"
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.google.firebase.gradle.plugins
import java.io.File
import java.io.FileOutputStream
import java.io.OutputStream
import javax.inject.Inject
import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
Expand All @@ -33,6 +34,7 @@ import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
import org.gradle.process.ExecOperations

val Project.metalavaConfig: Configuration
get() =
Expand All @@ -46,9 +48,10 @@ val Project.metalavaConfig: Configuration
}

val Project.docStubs: File?
get() = project.file("${buildDir.path}/doc-stubs")
get() = project.file("${project.layout.buildDirectory.get().asFile.path}/doc-stubs")

fun Project.runMetalavaWithArgs(
execOperations: ExecOperations,
arguments: List<String>,
ignoreFailure: Boolean = false,
stdOut: OutputStream? = null,
Expand All @@ -61,23 +64,25 @@ fun Project.runMetalavaWithArgs(
"HiddenAbstractMethod",
) + arguments

project.javaexec {
execOperations.javaexec {
mainClass.set("com.android.tools.metalava.Driver")
classpath = project.metalavaConfig
classpath = metalavaConfig
args = allArgs
isIgnoreExitValue = ignoreFailure
if (stdOut != null) errorOutput = stdOut
}
}

abstract class GenerateStubsTask : DefaultTask() {
abstract class GenerateStubsTask @Inject constructor(private val execOperations: ExecOperations) :
DefaultTask() {
/** Source files against which API signatures will be validated. */
@get:InputFiles abstract val sources: ConfigurableFileCollection

@get:[InputFiles Classpath]
lateinit var classPath: FileCollection

@get:OutputDirectory val outputDir: File = File(project.buildDir, "doc-stubs")
@get:OutputDirectory
val outputDir: File = File(project.layout.buildDirectory.get().asFile, "doc-stubs")

@TaskAction
fun run() {
Expand All @@ -87,6 +92,7 @@ abstract class GenerateStubsTask : DefaultTask() {
project.androidJar?.let { classPath += listOf(it.absolutePath) }

project.runMetalavaWithArgs(
execOperations,
listOf(
"--source-path",
sourcePath,
Expand All @@ -95,12 +101,13 @@ abstract class GenerateStubsTask : DefaultTask() {
"--include-annotations",
"--doc-stubs",
outputDir.absolutePath,
)
),
)
}
}

abstract class GenerateApiTxtTask : DefaultTask() {
abstract class GenerateApiTxtTask @Inject constructor(private val execOperations: ExecOperations) :
DefaultTask() {
/** Source files against which API signatures will be validated. */
@get:InputFiles abstract val sources: ConfigurableFileCollection

Expand All @@ -120,6 +127,7 @@ abstract class GenerateApiTxtTask : DefaultTask() {
project.androidJar?.let { classPath += listOf(it.absolutePath) }

project.runMetalavaWithArgs(
execOperations,
listOf(
"--source-path",
sourcePath,
Expand All @@ -138,7 +146,8 @@ abstract class GenerateApiTxtTask : DefaultTask() {
}
}

abstract class ApiInformationTask : DefaultTask() {
abstract class ApiInformationTask @Inject constructor(private val execOperations: ExecOperations) :
DefaultTask() {
/** Source files against which API signatures will be validated. */
@get:InputFiles abstract val sources: ConfigurableFileCollection

Expand All @@ -162,6 +171,7 @@ abstract class ApiInformationTask : DefaultTask() {
project.androidJar?.let { classPath += listOf(it.absolutePath) }

project.runMetalavaWithArgs(
execOperations,
listOf(
"--source-path",
sourcePath,
Expand All @@ -175,6 +185,7 @@ abstract class ApiInformationTask : DefaultTask() {
)

project.runMetalavaWithArgs(
execOperations,
listOf(
"--source-files",
outputApiFile.get().asFile.absolutePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fun Project.isAndroid(): Boolean =
}

fun toBoolean(value: Any?): Boolean {
val trimmed = value?.toString()?.trim()?.toLowerCase()
val trimmed = value?.toString()?.trim()?.lowercase()
return "true" == trimmed || "y" == trimmed || "1" == trimmed
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ abstract class PublishingPlugin : Plugin<Project> {
val generateBom = registerGenerateBomTask(project)
val generateBomReleaseNotes = registerGenerateBomReleaseNotesTask(project, generateBom)
val generateTutorialBundle = registerGenerateTutorialBundleTask(project)
val validatePomForRelease = registerValidatePomForReleaseTask(project, releasingProjects)
registerValidatePomForReleaseTask(project, releasingProjects)
val checkHeadDependencies =
registerCheckHeadDependenciesTask(project, releasingFirebaseLibraries)
val validateProjectsToPublish =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ package com.google.firebase.gradle.plugins

import com.google.firebase.gradle.plugins.semver.VersionDelta
import java.io.ByteArrayOutputStream
import javax.inject.Inject
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.TaskAction
import org.gradle.process.ExecOperations

abstract class SemVerTask : DefaultTask() {
abstract class SemVerTask @Inject constructor(private val execOperations: ExecOperations) :
DefaultTask() {
@get:InputFile abstract val apiTxtFile: RegularFileProperty
@get:InputFile abstract val otherApiFile: RegularFileProperty
@get:Input abstract val currentVersionString: Property<String>
Expand All @@ -47,6 +50,7 @@ abstract class SemVerTask : DefaultTask() {
}
val stream = ByteArrayOutputStream()
project.runMetalavaWithArgs(
execOperations,
listOf(
"--source-files",
apiTxtFile.get().asFile.absolutePath,
Expand All @@ -66,7 +70,6 @@ abstract class SemVerTask : DefaultTask() {
val minorChanges = mutableListOf<String>()
val majorChanges = mutableListOf<String>()
for (match in reg.findAll(string)) {
val loc = match.groups[1]!!.value
val message = match.groups[2]!!.value
val type = match.groups[3]!!.value
if (IGNORED.contains(type)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ abstract class ChangedModulesTask : DefaultTask() {
AffectedProjectFinder(project, changedGitPaths.toSet(), listOf())
.find()
.filter {
val ext = it.extensions.findByType(FirebaseLibraryExtension::class.java)
!onlyFirebaseSDKs || it.extensions.findByType<FirebaseLibraryExtension>() != null
}
.map { it.path }
Expand All @@ -62,12 +61,13 @@ abstract class ChangedModulesTask : DefaultTask() {
project.rootProject.subprojects.forEach { p ->
p.configurations.forEach { c ->
c.dependencies.filterIsInstance<ProjectDependency>().forEach {
val dependencyProject = project.project(it.dependencyProject.path)
if (
!onlyFirebaseSDKs ||
it.dependencyProject.extensions.findByType<FirebaseLibraryExtension>() != null
dependencyProject.extensions.findByType<FirebaseLibraryExtension>() != null
) {
if (!onlyFirebaseSDKs || p.extensions.findByType<FirebaseLibraryExtension>() != null) {
result[it.dependencyProject.path]?.add(p.path)
result[dependencyProject.path]?.add(p.path)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ abstract class ApiDiffer : DefaultTask() {
val classes: MutableMap<String, ClassNode> = LinkedHashMap()
val inputStream = Files.newInputStream(jar)
val jis = JarInputStream(inputStream)
var je: JarEntry? = null
var je: JarEntry?
while (true) {
je = jis.nextJarEntry
if (je == null) {
Expand Down
Loading
Loading