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

Set conventions for java libs #63

Merged
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ plugins {
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
}

extra["java_version"] = JavaVersion.VERSION_1_8

allprojects {
repositories {
google()
Expand Down
1 change: 1 addition & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ dependencies {
implementation("com.diffplug.spotless:spotless-plugin-gradle:6.21.0")
implementation("net.ltgt.gradle:gradle-errorprone-plugin:3.1.0")
implementation("net.ltgt.gradle:gradle-nullaway-plugin:1.6.0")
implementation("ru.vyarus:gradle-animalsniffer-plugin:1.7.1")
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,24 @@ import org.gradle.api.publish.maven.MavenPublication

plugins {
id("com.android.library")
id("maven-publish")
id("signing")
id("otel.errorprone-conventions")
}

val isARelease = project.hasProperty("release") && project.property("release") == "true"

val variantToPublish = "release"
android {
defaultConfig {
minSdk = (project.property("android.minSdk") as String).toInt()
}

lint {
warningsAsErrors = true
// A newer version of androidx.appcompat:appcompat than 1.3.1 is available: 1.4.1 [GradleDependency]
// we rely on dependabot for dependency updates
disable.add("GradleDependency")
}

publishing {
singleVariant(variantToPublish) {

// Adding sources and javadoc artifacts only during a release.
if (isARelease) {
withJavadocJar()
withSourcesJar()
}
}
}
}

afterEvaluate {
publishing.publications {
val maven = create<MavenPublication>("maven") {
from(components.findByName(variantToPublish))
pom {
val repoUrl = "https://github.com/open-telemetry/opentelemetry-android"
name.set("OpenTelemetry Android")
description.set(project.description)
url.set(repoUrl)
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
scm {
val scmUrl = "scm:git:[email protected]:open-telemetry/opentelemetry-android.git"
connection.set(scmUrl)
developerConnection.set(scmUrl)
url.set(repoUrl)
tag.set("HEAD")
}
developers {
developer {
id.set("opentelemetry")
name.set("OpenTelemetry")
url.set("https://github.com/open-telemetry/community")
}
}
}
}

// Signing only during a release.
if (isARelease) {
signing {
useInMemoryPgpKeys(System.getenv("GPG_PRIVATE_KEY"), System.getenv("GPG_PASSWORD"))
sign(maven)
}
}
compileOptions {
val javaVersion = rootProject.extra["java_version"] as JavaVersion
sourceCompatibility(javaVersion)
targetCompatibility(javaVersion)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import ru.vyarus.gradle.plugin.animalsniffer.AnimalSniffer

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

java {
val javaVersion = rootProject.extra["java_version"] as JavaVersion
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}

dependencies {
signature("com.toasttab.android:gummy-bears-api-${project.property("android.minSdk")}:0.5.1@signature")
}

animalsniffer {
sourceSets = listOf(java.sourceSets.main.get())
}

// Always having declared output makes this task properly participate in tasks up-to-date checks
tasks.withType<AnimalSniffer> {
reports.text.required.set(true)
}

// Attaching animalsniffer check to the compilation process.
tasks.named("classes").configure {
finalizedBy("animalsnifferMain")
}
77 changes: 77 additions & 0 deletions buildSrc/src/main/kotlin/otel.publish-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import com.android.build.api.dsl.LibraryExtension

plugins {
id("maven-publish")
id("signing")
}

val isARelease = project.hasProperty("release") && project.property("release") == "true"

val android = extensions.findByType(LibraryExtension::class.java)

val androidVariantToRelease = "release"
if (android != null) {
android.publishing {
singleVariant(androidVariantToRelease) {

// Adding sources and javadoc artifacts only during a release.
if (isARelease) {
withJavadocJar()
withSourcesJar()
}
}
}
} else {
extensions.configure(JavaPluginExtension::class.java) {
if (isARelease) {
withJavadocJar()
withSourcesJar()
}
}
}

afterEvaluate {
publishing.publications {
val maven = create<MavenPublication>("maven") {
if (android != null) {
from(components.findByName(androidVariantToRelease))
} else {
from(components.findByName("java"))
}
pom {
val repoUrl = "https://github.com/open-telemetry/opentelemetry-android"
name.set("OpenTelemetry Android")
description.set(project.description)
url.set(repoUrl)
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
scm {
val scmUrl = "scm:git:[email protected]:open-telemetry/opentelemetry-android.git"
connection.set(scmUrl)
developerConnection.set(scmUrl)
url.set(repoUrl)
tag.set("HEAD")
}
developers {
developer {
id.set("opentelemetry")
name.set("OpenTelemetry")
url.set("https://github.com/open-telemetry/community")
}
}
}
}

// Signing only during a release.
if (isARelease) {
signing {
useInMemoryPgpKeys(System.getenv("GPG_PRIVATE_KEY"), System.getenv("GPG_PASSWORD"))
sign(maven)
}
}
}
}
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ android.useAndroidX=true

# generate the BuildConfig class that contains the app version
android.defaults.buildfeatures.buildconfig=true
android.minSdk=21
otel.sdk.version=1.28.0

version=0.1.0
group=io.opentelemetry.android
13 changes: 6 additions & 7 deletions instrumentation/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id("otel.android-library-conventions")
id("otel.errorprone-conventions")
id("otel.publish-conventions")
}

// This submodule is alpha and is not yet intended to be used by itself
Expand All @@ -13,7 +13,6 @@ android {
buildToolsVersion = "33.0.1"

defaultConfig {
minSdk = 21
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}
Expand All @@ -24,7 +23,10 @@ android {
}
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro",
)
}
}

Expand All @@ -48,9 +50,6 @@ android {

compileOptions {
isCoreLibraryDesugaringEnabled = true

sourceCompatibility(JavaVersion.VERSION_1_8)
targetCompatibility(JavaVersion.VERSION_1_8)
}

testOptions {
Expand All @@ -59,7 +58,7 @@ android {
}
}

val otelVersion = "1.28.0"
val otelVersion = project.property("otel.sdk.version")

dependencies {
implementation("androidx.appcompat:appcompat:1.6.1")
Expand Down