Skip to content

Commit

Permalink
Upgrade to Gradle 8.2.1 and Android Gradle Plugin 8.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
badboy committed Aug 2, 2023
1 parent 5d97ed8 commit d9cc507
Show file tree
Hide file tree
Showing 14 changed files with 342 additions and 297 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

[Full changelog](https://github.com/mozilla/glean/compare/v53.2.0...main)

* Kotlin
* Update to Gradle v8.2.1 ([#2516](https://github.com/mozilla/glean/pull/2516))

# v53.2.0 (2023-08-02)

[Full changelog](https://github.com/mozilla/glean/compare/v53.1.0...v53.2.0)
Expand All @@ -11,7 +14,7 @@
* Rust
* The Ping Rate Limit type is now accessible in the Rust Language Binding ([#2528](https://github.com/mozilla/glean/pull/2528))
* Gracefully handle a failure when starting the upload thread. Glean no longer crashes in that case. ([#2545](https://github.com/mozilla/glean/pull/2545))
* `locale` now exposed through the RLB so it can be set by consumers ([2531](https://github.com/mozilla/glean/pull/2531))
* `locale` now exposed through the RLB so it can be set by consumers ([#2531](https://github.com/mozilla/glean/pull/2531))
* Python
* Added the shutdown API for Python to ensure orderly shutdown and waiting for uploader processes ([#2538](https://github.com/mozilla/glean/pull/2538))
* Kotlin
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
// changing them. Please note that, for using in Android-Components, the
// versions below must match the ones in that repository.
ext.versions = [
android_gradle_plugin: '7.4.2',
android_gradle_plugin: '8.0.2',
coroutines: '1.7.2',
jna: '5.13.0',
junit: '4.13.2',
Expand Down
12 changes: 12 additions & 0 deletions glean-core/android-native/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ apply plugin: 'com.android.library'
apply plugin: 'org.mozilla.rust-android-gradle.rust-android'

android {
namespace "mozilla.telemetry.glean_native"

ndkVersion rootProject.ext.build.ndkVersion
compileSdkVersion rootProject.ext.build.compileSdkVersion

Expand All @@ -36,10 +38,20 @@ android {
}
}

buildFeatures {
buildConfig true
}

sourceSets {
test.jniLibs.srcDirs += "$buildDir/rustJniLibs/desktop"
}

publishing {
singleVariant('release') {
withSourcesJar()
}
}

// Uncomment to include debug symbols in native library builds.
// packagingOptions { doNotStrip "**/*.so" }
}
Expand Down
18 changes: 0 additions & 18 deletions glean-core/android-native/publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,12 @@ ext.configurePublish = { jnaForTestConfiguration = null ->
forUnitTestsJarTask.dependsOn(tasks["cargoBuild"])
}

task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}

task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

publishing {
publications {
aar(MavenPublication) {
project.afterEvaluate {
from components.release
}
artifact sourcesJar
// Can't publish Javadoc yet: Glean isn't well behaved.
// artifact javadocJar

// If this goes haywire with
// 'Cannot configure the 'publishing' extension after it has been accessed.',
Expand Down
3 changes: 1 addition & 2 deletions glean-core/android-native/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mozilla.telemetry.glean_native" >
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>
</application>
</manifest>
63 changes: 38 additions & 25 deletions glean-core/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ext.gleanNamespace = "mozilla.telemetry.glean"

android {
compileSdkVersion rootProject.ext.build.compileSdkVersion
namespace "mozilla.telemetry.glean"

defaultConfig {
minSdkVersion rootProject.ext.build['minSdkVersion']
Expand Down Expand Up @@ -58,6 +59,10 @@ android {
}
}

buildFeatures {
buildConfig true
}

sourceSets {
test.resources.srcDirs += "$buildDir/rustJniLibs/desktop"
// Add glean-native's build directory to our resource path so that
Expand All @@ -66,6 +71,12 @@ android {
test.resources.srcDirs += "${project(':glean-native').buildDir}/rustJniLibs/desktop"
}

publishing {
singleVariant('release') {
withSourcesJar()
}
}

// Uncomment to include debug symbols in native library builds.
// packagingOptions { doNotStrip "**/*.so" }

Expand All @@ -85,35 +96,37 @@ android {
}

afterEvaluate {
jacoco {
toolVersion = "0.8.7"
}

task jacocoTestReport(type: JacocoReport) {
reports {
xml.enabled = true
html.enabled = true
if (project.hasProperty("coverage")) {
jacoco {
toolVersion = "0.8.10"
}

def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*',
'**/*Test*.*', 'android/**/*.*', '**/*$[0-9].*']
def kotlinDebugTree = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/debug", excludes: fileFilter)
def javaDebugTree = fileTree(dir: "$project.buildDir/intermediates/classes/debug", excludes: fileFilter)
def mainSrc = "$project.projectDir/src/main/java"

sourceDirectories.from = files([mainSrc])
classDirectories.from = files([kotlinDebugTree, javaDebugTree])
executionData.from = fileTree(dir: project.buildDir, includes: [
'jacoco/testDebugUnitTest.exec', 'outputs/code-coverage/connected/*coverage.ec'
])
}
task jacocoTestReport(type: JacocoReport) {
reports {
xml.required = true
html.required = true
}

tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
// See https://github.com/gradle/gradle/issues/5184#issuecomment-457865951
jacoco.excludes = ['jdk.internal.*']
def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*',
'**/*Test*.*', 'android/**/*.*', '**/*$[0-9].*']
def kotlinDebugTree = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/debug", excludes: fileFilter)
def javaDebugTree = fileTree(dir: "$project.buildDir/intermediates/classes/debug", excludes: fileFilter)
def mainSrc = "$project.projectDir/src/main/java"

sourceDirectories.from = files([mainSrc])
classDirectories.from = files([kotlinDebugTree, javaDebugTree])
executionData.from = fileTree(dir: project.buildDir, includes: [
'jacoco/testDebugUnitTest.exec', 'outputs/code-coverage/connected/*coverage.ec'
])
}

tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
// See https://github.com/gradle/gradle/issues/5184#issuecomment-457865951
jacoco.excludes = ['jdk.internal.*']

finalizedBy jacocoTestReport
finalizedBy jacocoTestReport
}
}
}

Expand Down
18 changes: 0 additions & 18 deletions glean-core/android/publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,12 @@ ext.configurePublish = {
def theArtifactId = project.ext.artifactId
def theDescription = project.ext.description

task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}

task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

publishing {
publications {
aar(MavenPublication) {
project.afterEvaluate {
from components.release
}
artifact sourcesJar
// Can't publish Javadoc yet: Glean isn't well behaved.
// artifact javadocJar

// If this goes haywire with
// 'Cannot configure the 'publishing' extension after it has been accessed.',
Expand Down
3 changes: 1 addition & 2 deletions glean-core/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mozilla.telemetry.glean" >
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>
<activity android:name=".debug.GleanDebugActivity"
android:launchMode="singleInstance"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.artifacts.transform.ArtifactTransform
import org.gradle.api.artifacts.transform.TransformAction
import org.gradle.api.artifacts.transform.TransformParameters
import org.gradle.api.artifacts.transform.TransformOutputs
import org.gradle.api.artifacts.transform.InputArtifact
import org.gradle.api.provider.Provider
import org.gradle.api.file.FileSystemLocation
import org.gradle.api.artifacts.ComponentMetadataRule
import org.gradle.api.artifacts.ComponentMetadataContext
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
Expand All @@ -28,13 +33,17 @@ import java.util.concurrent.Semaphore
* A helper class to extract metrics.yaml files from AAR files.
*/
@SuppressWarnings("GrPackage")
class GleanMetricsYamlTransform extends ArtifactTransform {
List<File> transform(File file) {
abstract class GleanMetricsYamlTransform implements TransformAction<TransformParameters.None> {
@InputArtifact
abstract Provider<FileSystemLocation> getInputArtifact()

@Override
void transform(TransformOutputs outputs) {
def file = inputArtifact.get().asFile
def f = new File(file, "metrics.yaml")
if (f.exists()) {
return [f]
outputs.file(f)
}
return []
}
}

Expand Down Expand Up @@ -243,7 +252,7 @@ except:
TaskProvider buildConfigProvider = variant.getGenerateBuildConfigProvider()
def configProvider = buildConfigProvider.get()
def originalPackageName
// In Gradle 6.x `getBuildConfigPackageName` was reaplced by `namespace`.
// In Gradle 6.x `getBuildConfigPackageName` was repalced by `namespace`.
// We want to be forward compatible, so we check that first or fallback to the old method.
if (configProvider.hasProperty("namespace")) {
originalPackageName = configProvider.namespace.get()
Expand All @@ -267,7 +276,7 @@ except:
standardOutput = new ByteArrayOutputStream()
errorOutput = standardOutput
doLast {
if (execResult.exitValue != 0) {
if (executionResult.get().exitValue != 0) {
throw new GradleException("Glean code generation failed.\n\n${standardOutput.toString()}")
}
}
Expand Down Expand Up @@ -341,7 +350,7 @@ except:
standardOutput = new ByteArrayOutputStream()
errorOutput = standardOutput
doLast {
if (execResult.exitValue != 0) {
if (executionResult.get().exitValue != 0) {
throw new GradleException("Glean documentation generation failed.\n\n${standardOutput.toString()}")
}
}
Expand Down Expand Up @@ -525,19 +534,14 @@ except:
// Gradle composite build.
if (project.ext.has("allowMetricsFromAAR")) {
project.dependencies {
registerTransform { reg ->
registerTransform(GleanMetricsYamlTransform) {
// The type here should be
// `com.android.build.gradle.internal.publishing.AndroidArtifacts.ArtifactType.EXPLODED_AAR.getType())`,
// but there's no good way to access the including script's classpath from `apply from:`
// scripts. See https://stackoverflow.com/a/37060550. The 'android-exploded-aar' string is
// very unlikely to change, so it's just hard-coded.
reg.getFrom().attribute(
ArtifactAttributes.ARTIFACT_FORMAT,
'android-exploded-aar')
reg.getTo().attribute(
ArtifactAttributes.ARTIFACT_FORMAT,
'glean-metrics-yaml')
reg.artifactTransform(GleanMetricsYamlTransform.class)
from.attribute(ArtifactAttributes.ARTIFACT_FORMAT, "android-exploded-aar")
to.attribute(ArtifactAttributes.ARTIFACT_FORMAT, "glean-metrics-yaml")
}
}
}
Expand All @@ -561,7 +565,7 @@ except:
// Print the required glean_parser version to the console. This is
// offline builds, and is mentioned in the documentation for offline
// builds.
println("Requires ${parserVersion}")
println("Requires glean_parser ${parserVersion}")

File envDir = setupPythonEnvironmentTasks(project, parserVersion)
// Store in both gleanCondaDir (for backward compatibility reasons) and
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Jun 24 17:01:45 CEST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit d9cc507

Please sign in to comment.