Skip to content

Commit

Permalink
Bump AGP and Gradle versions (#428)
Browse files Browse the repository at this point in the history
Co-authored-by: Markus Hintersteiner <markus.hintersteiner@sentry.io>
  • Loading branch information
romtsn and markushi committed Mar 20, 2023
1 parent 40bc0e8 commit c31a657
Show file tree
Hide file tree
Showing 24 changed files with 224 additions and 54 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ jobs:
- name: Set up Java
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '11'
distribution: 'temurin'
java-version: '17'

- name: Build distribution artifacts
run: |
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/integration-tests-sentry-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ jobs:
with:
python-version: '3.10.5'

- name: Set up Java
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '17'

- name: Start server and run integration test for sentry-cli commands
run: |
test/integration-test-server-start.sh &
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pre-merge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
- name: Setup Java Version
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '11'
distribution: 'temurin'
java-version: '17'

- name: Run Gradle tasks
if: runner.os != 'Windows'
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/test-publish-dry-run.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ jobs:
- agp: "7.2.1"
gradle: "7.4"
java: "11"
- agp: "7.2.1"
gradle: "7.5"
java: "11"
- agp: "7.3.0"
gradle: "7.5"
java: "11"
- agp: "7.3.0"
gradle: "7.6"
java: "11"
- agp: "7.4.0-rc01"
- agp: "7.4.0"
gradle: "7.5"
java: "11"
- agp: "8.0.0-alpha09"
gradle: "7.5"
- agp: "7.4.0"
gradle: "7.6"
java: "11"
- agp: "8.0.0-beta05"
gradle: "8.0.2"
java: "17"
- agp: "8.1.0-alpha08"
gradle: "8.0.2"
java: "17"

name: Publish Dry Run - AGP ${{ matrix.agp }} - Gradle ${{ matrix.gradle }}
env:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

### Fixes

- Make plugin Gradle 8 compatible ([#428](https://github.com/getsentry/sentry-android-gradle-plugin/pull/428))
- Fix `uploadSentryNativeSymbols` task for Gradle 8 ([#447](https://github.com/getsentry/sentry-android-gradle-plugin/pull/447))

### Dependencies

- Bump Android SDK from v6.13.0 to v6.15.0 ([#442](https://github.com/getsentry/sentry-android-gradle-plugin/pull/442))
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ We suggest opening an issue to discuss bigger changes before investing on a big

# Requirements

The project currently requires you run JDK version `11` and the Android SDK.
The project currently requires you run JDK version `17` and the Android SDK.

# CI

Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ object Libs {
// this allows us to develop against a fixed version of Gradle, as opposed to depending on the
// locally available version. kotlin-gradle-plugin follows the same approach.
// More info: https://docs.nokee.dev/manual/gradle-plugin-development-plugin.html
const val GRADLE_API = "dev.gradleplugins:gradle-api:7.5"
const val GRADLE_API = "dev.gradleplugins:gradle-api:7.6"

// bytecode instrumentation
const val ASM = "org.ow2.asm:asm-util:${LibsVersion.ASM}"
Expand Down
1 change: 1 addition & 0 deletions examples/android-instrumentation-sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ android {
}

flavorDimensions += "environment"
// just a random product flavor for compatibility testing against AGP
productFlavors {
create("staging") {
dimension = "environment"
Expand Down
1 change: 1 addition & 0 deletions examples/spring-boot-sample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ktlint-disable max-line-length
import org.jetbrains.kotlin.config.KotlinCompilerVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1536m -XX:MaxPermSize=1g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1536m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC
org.gradle.parallel=true

android.useAndroidX=true
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions plugin-build/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ plugins {
id("com.vanniktech.maven.publish") version BuildPluginsVersion.MAVEN_PUBLISH apply false
id("org.jlleitschuh.gradle.ktlint") version BuildPluginsVersion.KTLINT
// we need this plugin in order to include .aar dependencies into a pure java project, which the gradle plugin is
id("com.stepango.aar2jar") version BuildPluginsVersion.AAR_2_JAR
id("io.sentry.android.gradle.aar2jar")
id("com.github.johnrengelman.shadow") version BuildPluginsVersion.SHADOW
}

Expand Down Expand Up @@ -86,7 +86,7 @@ dependencies {
testImplementationAar(Libs.SQLITE)
testImplementationAar(Libs.SQLITE_FRAMEWORK)
testRuntimeOnly(files(androidSdkPath))
testImplementationAar(Libs.SENTRY_ANDROID)
testRuntimeOnlyAar(Libs.SENTRY_ANDROID)

testRuntimeOnly(
files(
Expand Down
18 changes: 18 additions & 0 deletions plugin-build/buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
plugins {
`kotlin-dsl`
id("java-gradle-plugin")
kotlin("jvm") version "1.6.10"
}

repositories {
Expand All @@ -11,3 +13,19 @@ sourceSets {
java.srcDir("../../buildSrc/src/main/java")
}
}


// we cannot use the version from Dependencies.kt because it's not available at this moment, the
// proper way to share the dependency notation is to use libs.versions.toml, but that's for later
dependencies {
compileOnly("dev.gradleplugins:gradle-api:7.6")
}

gradlePlugin {
plugins {
register("aar2jarPlugin") {
id = "io.sentry.android.gradle.aar2jar"
implementationClass = "io.sentry.android.gradle.internal.Aar2JarPlugin"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package io.sentry.android.gradle.internal

import java.io.FileOutputStream
import java.util.zip.ZipFile
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.transform.InputArtifact
import org.gradle.api.artifacts.transform.TransformAction
import org.gradle.api.artifacts.transform.TransformOutputs
import org.gradle.api.artifacts.transform.TransformParameters
import org.gradle.api.artifacts.type.ArtifactTypeDefinition
import org.gradle.api.attributes.Attribute
import org.gradle.api.file.FileSystemLocation
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.the
import org.gradle.plugins.ide.idea.model.IdeaModel

/**
* A port of https://github.com/stepango/aar2jar, which adds support for 2 things:
* - runtimeOnlyAar configuration
* - Gradle 8.0+ registerTransform API
*/
class Aar2JarPlugin : Plugin<Project> {

override fun apply(project: Project) {

val compileOnlyAar = project.configurations.register("compileOnlyAar")
val runtimeOnlyAar = project.configurations.register("runtimeOnlyAar")
val implementationAar = project.configurations.register("implementationAar")

// Assume all modules have test configuration
val testCompileOnlyAar = project.configurations.register("testCompileOnlyAar")
val testRuntimeOnlyAar = project.configurations.register("testRuntimeOnlyAar")
val testImplementationAar = project.configurations.register("testImplementationAar")

project.pluginManager.withPlugin("idea") {
val scopes = project.extensions
.getByType<IdeaModel>()
.module
.scopes

scopes["TEST"]
?.get("plus")
?.apply {
add(testImplementationAar.get())
add(testCompileOnlyAar.get())
add(testRuntimeOnlyAar.get())
}

scopes.forEach {
it.value["plus"]?.apply {
add(implementationAar.get())
add(compileOnlyAar.get())
add(runtimeOnlyAar.get())
}
}
}

project.dependencies.registerTransform(AarToJarTransform::class.java) {
from.attribute(ARTIFACT_ATTR, "aar")
to.attribute(ARTIFACT_ATTR, ArtifactTypeDefinition.JAR_TYPE)
}

compileOnlyAar.configure {
baseConfiguration(project, "main") {
compileClasspath += this@configure
}
}

runtimeOnlyAar.configure {
baseConfiguration(project, "main") {
runtimeClasspath += this@configure
}
}

implementationAar.configure {
baseConfiguration(project, "main") {
compileClasspath += this@configure
runtimeClasspath += this@configure
}
}

testCompileOnlyAar.configure {
baseConfiguration(project, "test") {
compileClasspath += this@configure
}
}

testRuntimeOnlyAar.configure {
baseConfiguration(project, "test") {
runtimeClasspath += this@configure
}
}

testImplementationAar.configure {
baseConfiguration(project, "test") {
compileClasspath += this@configure
runtimeClasspath += this@configure
}
}
}

companion object {
internal val ARTIFACT_ATTR = Attribute.of("artifactType", String::class.java)
}
}

fun Configuration.baseConfiguration(project: Project, name: String, f: SourceSet.() -> Unit) {
isTransitive = false
attributes {
attribute(Aar2JarPlugin.ARTIFACT_ATTR, ArtifactTypeDefinition.JAR_TYPE)
}
project.pluginManager.withPlugin("java") {
val sourceSets = project.the<JavaPluginExtension>().sourceSets
sourceSets.withName(name, f)
}
}

fun SourceSetContainer.withName(name: String, f: SourceSet.() -> Unit) {
this[name]?.apply { f(this) } ?: whenObjectAdded { if (this.name == name) f(this) }
}

abstract class AarToJarTransform : TransformAction<TransformParameters.None> {

@get:InputArtifact
@get:PathSensitive(PathSensitivity.NAME_ONLY)
abstract val input: Provider<FileSystemLocation>

override fun transform(outputs: TransformOutputs) {
val inputFile = input.get().asFile
val outputFile = outputs.file(inputFile.name.replace(".aar", ".jar"))
ZipFile(inputFile).use { zipFile ->
zipFile.entries()
.toList()
.first { it.name == "classes.jar" }
.let(zipFile::getInputStream)
.use { input ->
FileOutputStream(outputFile).use { output ->
input.copyTo(output)
}
}
}
}
}
2 changes: 1 addition & 1 deletion plugin-build/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1536m -XX:MaxPermSize=1g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1536m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC
org.gradle.daemon=false

# for debugging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ private fun ApplicationVariant.configureNativeSymbolsTask(
SentryUploadNativeSymbolsTask::class.java
) {
it.workingDir(project.rootDir)
it.buildDir.set(project.buildDir)
it.autoUploadNativeSymbol.set(extension.autoUploadNativeSymbols)
it.cliExecutable.set(cliExecutable)
it.sentryProperties.set(sentryProps?.let { file -> project.file(file) })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import io.sentry.android.gradle.util.info
import java.io.File
import org.apache.tools.ant.taskdefs.condition.Os
import org.apache.tools.ant.taskdefs.condition.Os.FAMILY_WINDOWS
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Exec
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Optional
Expand All @@ -20,9 +18,6 @@ abstract class SentryUploadNativeSymbolsTask : Exec() {
description = "Uploads native symbols to Sentry"
}

@get:InputDirectory
abstract val buildDir: DirectoryProperty

@get:Input
abstract val cliExecutable: Property<String>

Expand Down Expand Up @@ -91,7 +86,7 @@ abstract class SentryUploadNativeSymbolsTask : Exec() {
// where {variantName} could be debug/release...
args.add(
File(
buildDir.asFile.get(),
project.buildDir,
"intermediates${sep}merged_native_libs${sep}${variantName.get()}"
).absolutePath
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,20 @@ import java.util.UUID
import org.gradle.api.provider.Provider
import org.gradle.api.services.BuildService
import org.gradle.api.services.BuildServiceParameters
import org.gradle.api.services.BuildServiceRegistration
import org.gradle.api.services.BuildServiceRegistry

/*
* Adapted from https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:build-system/gradle-core/src/main/java/com/android/build/gradle/internal/services/buildServices.k
*/

fun <ServiceT : BuildService<out BuildServiceParameters>> getBuildService(
fun <ServiceT : BuildService<ParamsT>, ParamsT : BuildServiceParameters> getBuildService(
buildServiceRegistry: BuildServiceRegistry,
buildServiceClass: Class<ServiceT>
): Provider<ServiceT> {
@Suppress("UNCHECKED_CAST")
return (
buildServiceRegistry.registrations.getByName(
getBuildServiceName(buildServiceClass)
) as BuildServiceRegistration<ServiceT, *>
).getService()
val serviceName = getBuildServiceName(buildServiceClass)
return buildServiceRegistry.registerIfAbsent(serviceName, buildServiceClass) {
throw IllegalStateException("Service $serviceName is not registered.")
}
}

/*
Expand Down

0 comments on commit c31a657

Please sign in to comment.