-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix and centralize publishing logic (#169)
- Loading branch information
Showing
7 changed files
with
112 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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"]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ tasks { | |
|
||
include("LICENSE") | ||
include("NOTICE") | ||
include("licenses/**") | ||
} | ||
} | ||
|
||
|
96 changes: 96 additions & 0 deletions
96
buildSrc/src/main/kotlin/elastic-otel.sign-and-publish-conventions.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
@@ -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"]) | ||
} |