Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,30 @@ val dependencyManagement by configurations.creating {
isVisible = false
}

// An optionalCompileOnly dependency is the same as a compileOnly dependency, except that it appears
// in published pom.xml like the following, where compileOnly dependencies don't appear in pom.xml at all:
// <dependency>
// <groupId>io.opentelemetry</groupId>
// <artifactId>opentelemetry-api-incubator</artifactId>
// <version>1.48.0-alpha-SNAPSHOT</version>
// <scope>runtime</scope>
// <optional>true</optional>
// </dependency>
val optionalCompileOnly by configurations.creating {
isCanBeConsumed = false
isCanBeResolved = false
// In otel.publish-conventions.gradle.kts we indicate that optionalCompileOnly dependencies should
// be added to the publication with scope=runtime, optional=true. For some reason, this fails if
// the configuration doesn't have at least 1 attribute associated with it. It's not clear from the
// docs (https://docs.gradle.org/current/userguide/variant_attributes.html) what the attribute is used for.
attributes {
attribute(Attribute.of("unused", String::class.java), "unused")
}
}
configurations.named("compileOnly") {
extendsFrom(optionalCompileOnly)
}

dependencies {
dependencyManagement(platform(project(":dependencyManagement")))
afterEvaluate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ publishing {
}
plugins.withId("java-library") {
from(components["java"])

val javaComponent = components.findByName("java") as AdhocComponentWithVariants
javaComponent.addVariantsFromConfiguration(configurations["optionalCompileOnly"]) {
mapToMavenScope("runtime")
mapToOptional()
}
}

versionMapping {
Expand Down
2 changes: 1 addition & 1 deletion sdk/trace/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies {
api(project(":api:all"))
api(project(":sdk:common"))

compileOnly(project(":api:incubator"))
optionalCompileOnly(project(":api:incubator"))
compileOnly(project(":sdk:trace-shaded-deps"))
Copy link
Member Author

Choose a reason for hiding this comment

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

If we go in this direction, we'll need to decide when its appropriate for a dependency to be compileOnly vs. optionalCompileOnly.

Originally, I just updated gradle maven publishing to include all compileOnly dependencies as optional dependencies in pom.xml, but that resulted in these standard compileOnly annotation dependencies being included in every pom.xml, which doesn't seem right.


annotationProcessor("com.google.auto.value:auto-value")
Expand Down
Loading