diff --git a/conventions/src/main/kotlin/otel.java-conventions.gradle.kts b/conventions/src/main/kotlin/otel.java-conventions.gradle.kts index 7f6a94bd8139..93a80434b5b8 100644 --- a/conventions/src/main/kotlin/otel.java-conventions.gradle.kts +++ b/conventions/src/main/kotlin/otel.java-conventions.gradle.kts @@ -194,6 +194,41 @@ testing { } } +var path = project.path +if (path.startsWith(":instrumentation:")) { + // remove segments that are a prefix of the next segment + // for example :instrumentation:log4j:log4j-context-data:log4j-context-data-2.17 is transformed to log4j-context-data-2.17 + var tmpPath = path + val suffix = tmpPath.substringAfterLast(':') + var prefix = ":instrumentation:" + if (suffix == "library") { + // strip ":library" suffix + tmpPath = tmpPath.substringBeforeLast(':') + } else if (suffix == "library-autoconfigure") { + // replace ":library-autoconfigure" with "-autoconfigure" + tmpPath = tmpPath.substringBeforeLast(':') + "-autoconfigure" + } else if (suffix == "javaagent") { + // strip ":javaagent" suffix and add it to prefix + prefix += "javaagent:" + tmpPath = tmpPath.substringBeforeLast(':') + } + val segments = tmpPath.substring(":instrumentation:".length).split(':') + var newPath = "" + var done = false + for (s in segments) { + if (!done && (newPath.isEmpty() || s.startsWith(newPath))) { + newPath = s + } else { + newPath += ":$s" + done = true + } + } + if (newPath.isNotEmpty()) { + path = prefix + newPath + } +} +var javaModuleName = "io.opentelemetry" + path.replace(".", "_").replace("-", "_").replace(":", ".") + tasks { named("jar") { // By default Gradle Jar task can put multiple files with the same name @@ -210,7 +245,8 @@ tasks { "Implementation-Title" to project.name, "Implementation-Version" to project.version, "Implementation-Vendor" to "OpenTelemetry", - "Implementation-URL" to "https://github.com/open-telemetry/opentelemetry-java-instrumentation" + "Implementation-URL" to "https://github.com/open-telemetry/opentelemetry-java-instrumentation", + "Automatic-Module-Name" to javaModuleName ) } }