Skip to content
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

Building animal sniffer signatures directly from android corelib #5973

Merged
merged 8 commits into from
Nov 20, 2023
54 changes: 54 additions & 0 deletions animal-sniffer/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import ru.vyarus.gradle.plugin.animalsniffer.info.SignatureInfoTask
import ru.vyarus.gradle.plugin.animalsniffer.signature.BuildSignatureTask

plugins {
id("otel.java-conventions")
id("ru.vyarus.animalsniffer")
}

val signatureJar = configurations.create("signatureJar") {
isCanBeConsumed = false
isCanBeResolved = false
}
val signatureJarClasspath = configurations.create("signatureJarClasspath") {
isCanBeConsumed = false
isCanBeResolved = true
extendsFrom(signatureJar)
}
val generatedSignature = configurations.create("generatedSignature") {
isCanBeConsumed = true
isCanBeResolved = false
}
configurations.add(signatureJar)
configurations.add(signatureJarClasspath)
configurations.add(generatedSignature)

repositories {
mavenCentral()
google()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move google() to the repositories section of settings.gradle.kts, and delete mavenCentral() since its redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, it's updated now.

}

dependencies {
signature("com.toasttab.android:gummy-bears-api-21:0.6.1@signature")
signatureJar("com.android.tools:desugar_jdk_libs:2.0.4")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested that it works by adding some code that uses java.util.Base64 and then running the task animalsnifferMain which completed without any issues (since Base64 was added in version 2.0.4). Then I changed this version to 2.0.3 and re-run the animal sniffer task which then failed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to define these in dependencyManagement/build.gradle.kts and omit the versions here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried with both but it only worked for com.android.tools:desugar_jdk_libs so that's the only one I moved over to dependencyManagement. I'm guessing the @signature part of gummy-bears makes it difficult for Gradle to resolve the artifact when the version is defined elsewhere.

}

val signatureSimpleName = "android.signature"
val signatureBuilderTask = tasks.register("buildSignature", BuildSignatureTask::class.java) {
files(signatureJarClasspath) // All the jar files here will be added to the signature file.
signatures(configurations.signature) // We'll extend from the existing signatures added to this config.
outputName = signatureSimpleName // Name for the generated signature file.
}

// Exposing the "generatedSignature" consumable config to be used in other subprojects
artifacts {
add("generatedSignature", project.provider { File(signatureBuilderTask.get().outputs.files.singleFile, signatureSimpleName) }) {
builtBy(signatureBuilderTask)
}
}

// Utility task to show what's in the signature file
tasks.register( "printSignature", SignatureInfoTask::class.java) {
signature = signatureBuilderTask.get().outputFiles
depth = 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

dependencies {
add("signature", "com.toasttab.android:gummy-bears-api-21:0.3.0:coreLib@signature")
signature(project(path = ":animal-sniffer", configuration = "generatedSignature"))
}

animalsniffer {
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ include(":sdk-extensions:autoconfigure-spi")
include(":sdk-extensions:incubator")
include(":sdk-extensions:jaeger-remote-sampler")
include(":testing-internal")
include(":animal-sniffer")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about animal-sniffer-signature?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure no problem, I've made the changes.


val gradleEnterpriseServer = "https://ge.opentelemetry.io"
val isCI = System.getenv("CI") != null
Expand Down
Loading