Skip to content

Commit

Permalink
Fix and centralize publishing logic (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKunz authored Mar 14, 2024
1 parent 04b2124 commit 9ffb076
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 114 deletions.
1 change: 1 addition & 0 deletions .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
vaultRoleId: ${{ secrets.VAULT_ROLE_ID }}
vaultSecretId: ${{ secrets.VAULT_SECRET_ID }}
pipeline: elastic-otel-java-snapshot
pipelineCommit: ${{ github.ref_name }}
waitFor: false
printBuildLogs: false
buildEnvVars: |
Expand Down
57 changes: 8 additions & 49 deletions agent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@ import java.util.stream.Collectors
import kotlin.collections.ArrayList

plugins {
id("maven-publish")
id("signing")
id("elastic-otel.agent-packaging-conventions")
id("elastic-otel.sign-and-publish-conventions")
alias(catalog.plugins.taskinfo)
alias(catalog.plugins.licenseReport)
}

description = rootProject.description + " agent"
description = "Elastic OpenTelemetry java distribution agent"

base.archivesName.set("elastic-otel-javaagent")

publishingConventions {
artifactTasks.add(tasks.shadowJar)
artifactTasks.add(tasks.javadocJar)
artifactTasks.add(tasks.sourcesJar)
}

dependencies {
// required to access OpenTelemetryAgent
compileOnly(catalog.opentelemetryJavaagentBootstrap)
Expand Down Expand Up @@ -118,51 +123,5 @@ tasks {
Files.write(licenseReport, newLicenseLines)
}
}

}

publishing {
publications {
register("agentJar", MavenPublication::class) {
artifactId = "elastic-otel-javaagent"

artifact(tasks.shadowJar.get())
artifact(tasks.sourcesJar.get())
artifact(tasks.javadocJar.get())

pom {
name.set(project.description)
description.set(project.description)
url.set("https://github.com/elastic/elastic-otel-java")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
name.set("Elastic Inc.")
url.set("https://www.elastic.co")
}
}
scm {
connection.set("scm:git:[email protected]:elastic/elastic-otel-java.git")
developerConnection.set("scm:git:[email protected]:elastic/elastic-otel-java.git")
url.set("https://github.com/elastic/elastic-otel-java")
}
}
}
}
}


signing {
setRequired({
// only sign in CI
System.getenv("CI") == "true"
})
// use in-memory ascii-armored key in environment variables
useInMemoryPgpKeys(System.getenv("KEY_ID_SECRET"), System.getenv("SECRING_ASC"), System.getenv("KEYPASS_SECRET"))
sign(publishing.publications["agentJar"])
}
10 changes: 0 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
plugins {
id "idea"
id "maven-publish"
id "base" // required to get 'clean' task
alias(catalog.plugins.nexusPublish)
}
Expand Down Expand Up @@ -85,15 +84,6 @@ subprojects {
}
}

publishing {
repositories {
// dry-run repository will be wiped on 'clean' task
maven {
name = 'dryRun'
url = rootProject.layout.buildDirectory.dir("dry-run-maven-repo")
}
}
}
}

nexusPublishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ tasks {

include("LICENSE")
include("NOTICE")
include("licenses/**")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
plugins {
`maven-publish`
publishing
signing
}

interface PublishingConventionsPluginExtension {
/**
* By default the convention will publish the artifacts and pom as libraries.
* To override the behaviour provide the tasks producing the artifacts as this property.
* This should only be required when publishing fat-jars with custom packaging.
*/
val artifactTasks: ListProperty<Task>
}

val publishingConventions = project.extensions.create<PublishingConventionsPluginExtension>("publishingConventions")
publishingConventions.artifactTasks.convention(listOf())


afterEvaluate {

if (project.description == null || project.description!!.isBlank()) {
throw GradleException("Project description must be set to publish the project to maven central!")
}

publishing {

repositories {
// dry-run repository will be wiped on 'clean' task
maven {
name = "dryRun"
url = rootProject.layout.buildDirectory.dir("dry-run-maven-repo").get().asFile.toURI()
}
}

publications {
register("maven", MavenPublication::class) {
artifactId = base.archivesName.get()

val artifactTasks = publishingConventions.artifactTasks.get()
if (artifactTasks.isEmpty()) {
//publish as library with dependencies
from(components["java"])
versionMapping {
usage("java-api") {
fromResolutionOf("runtimeClasspath")
}
usage("java-runtime") {
fromResolutionResult()
}
}
} else {
//publish just the artifacts (fat-jars).
for (task in artifactTasks) {
artifact(task)
}
}

pom {

name.set(project.description)
description.set(project.description)
url.set("https://github.com/elastic/elastic-otel-java")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
name.set("Elastic Inc.")
url.set("https://www.elastic.co")
}
}
scm {
connection.set("scm:git:[email protected]:elastic/elastic-otel-java.git")
developerConnection.set("scm:git:[email protected]:elastic/elastic-otel-java.git")
url.set("https://github.com/elastic/elastic-otel-java")
}
}
}
}
}

signing {
setRequired({
// only sign in CI
System.getenv("CI") == "true"
})
// use in-memory ascii-armored key in environment variables
useInMemoryPgpKeys(System.getenv("KEY_ID_SECRET"), System.getenv("SECRING_ASC"), System.getenv("KEYPASS_SECRET"))
sign(publishing.publications["maven"])
}

}
6 changes: 5 additions & 1 deletion common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
plugins {
id("java-library")
id("java-library")
id("elastic-otel.library-packaging-conventions")
id("elastic-otel.sign-and-publish-conventions")
}

description = "Elastic OpenTelemetry common utilities"

dependencies {
annotationProcessor(libs.autoservice.processor)
api("com.blogspot.mydailyjava:weak-lock-free:0.18")
Expand Down
55 changes: 2 additions & 53 deletions inferred-spans/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
plugins {
`java-library`
id("signing")
id("elastic-otel.library-packaging-conventions")
id("elastic-otel.sign-and-publish-conventions")
}

description = rootProject.description + " inferred-spans"
description = "Elastic OpenTelemetry Inferred Spans extension"

dependencies {
annotationProcessor(libs.autoservice.processor)
Expand Down Expand Up @@ -48,54 +48,3 @@ tasks.processResources {
tasks.withType<Test>().all {
jvmArgs("-Djava.util.logging.config.file="+sourceSets.test.get().output.resourcesDir+"/logging.properties")
}

publishing {
publications {
create<MavenPublication>("maven") {

from(components["java"])

versionMapping {
usage("java-api") {
fromResolutionOf("runtimeClasspath")
}
usage("java-runtime") {
fromResolutionResult()
}
}

pom {
name.set(project.description)
description.set(project.description)
url.set("https://github.com/elastic/elastic-otel-java")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
name.set("Elastic Inc.")
url.set("https://www.elastic.co")
}
}
scm {
connection.set("scm:git:[email protected]:elastic/elastic-otel-java.git")
developerConnection.set("scm:git:[email protected]:elastic/elastic-otel-java.git")
url.set("https://github.com/elastic/elastic-otel-java")
}
}
}
}
}

signing {
setRequired({
// only sign in CI
System.getenv("CI") == "true"
})
// use in-memory ascii-armored key in environment variables
useInMemoryPgpKeys(System.getenv("KEY_ID_SECRET"), System.getenv("SECRING_ASC"), System.getenv("KEYPASS_SECRET"))
sign(publishing.publications["maven"])
}

0 comments on commit 9ffb076

Please sign in to comment.