Fix Resource version properties lookup and extract version file gener… (#3467)
* Fix Resource version properties lookup and extract version file generation. * Only published * Cleanup * Better merge * Fix merge
This commit is contained in:
		
							parent
							
								
									7fb6061af7
								
							
						
					
					
						commit
						2844471335
					
				| 
						 | 
				
			
			@ -136,6 +136,29 @@ tasks {
 | 
			
		|||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Add version information to published artifacts.
 | 
			
		||||
plugins.withId("otel.publish-conventions") {
 | 
			
		||||
  tasks {
 | 
			
		||||
    register("generateVersionResource") {
 | 
			
		||||
      val moduleName = otelJava.moduleName
 | 
			
		||||
      val propertiesDir = moduleName.map { File(buildDir, "generated/properties/${it.replace('.', '/')}") }
 | 
			
		||||
 | 
			
		||||
      inputs.property("project.version", project.version.toString())
 | 
			
		||||
      outputs.dir(propertiesDir)
 | 
			
		||||
 | 
			
		||||
      doLast {
 | 
			
		||||
        File(propertiesDir.get(), "version.properties").writeText("sdk.version=${project.version}")
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  sourceSets {
 | 
			
		||||
    main {
 | 
			
		||||
      output.dir("$buildDir/generated/properties", "builtBy" to "generateVersionResource")
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
configurations.configureEach {
 | 
			
		||||
  resolutionStrategy {
 | 
			
		||||
    failOnVersionConflict()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,23 +22,6 @@ dependencies {
 | 
			
		|||
  testImplementation("org.junit-pioneer:junit-pioneer")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sourceSets {
 | 
			
		||||
  main {
 | 
			
		||||
    output.dir("build/generated/properties", "builtBy" to "generateVersionResource")
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
tasks {
 | 
			
		||||
  register("generateVersionResource") {
 | 
			
		||||
    val propertiesDir = file("build/generated/properties/io/opentelemetry/sdk/extension/resources")
 | 
			
		||||
    outputs.dir(propertiesDir)
 | 
			
		||||
 | 
			
		||||
    doLast {
 | 
			
		||||
      File(propertiesDir, "version.properties").writeText("sdk.version=${project.version}")
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
for (version in mrJarVersions) {
 | 
			
		||||
  sourceSets {
 | 
			
		||||
    create("java${version}") {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,7 +8,7 @@ plugins {
 | 
			
		|||
 | 
			
		||||
description = "OpenTelemetry SDK"
 | 
			
		||||
otelJava.moduleName.set("io.opentelemetry.sdk")
 | 
			
		||||
base.archivesBaseName = "opentelemetry-sdk"
 | 
			
		||||
base.archivesName.set("opentelemetry-sdk")
 | 
			
		||||
 | 
			
		||||
dependencies {
 | 
			
		||||
  api(project(":api:all"))
 | 
			
		||||
| 
						 | 
				
			
			@ -21,20 +21,3 @@ dependencies {
 | 
			
		|||
 | 
			
		||||
  testImplementation(project(":sdk:testing"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sourceSets {
 | 
			
		||||
  main {
 | 
			
		||||
    output.dir("build/generated/properties", "builtBy" to "generateVersionResource")
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
tasks {
 | 
			
		||||
  register("generateVersionResource") {
 | 
			
		||||
    val propertiesDir = file("build/generated/properties/io/opentelemetry/sdk")
 | 
			
		||||
    outputs.dir(propertiesDir)
 | 
			
		||||
 | 
			
		||||
    doLast {
 | 
			
		||||
      File(propertiesDir, "version.properties").writeText("sdk.version=${project.version}")
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -30,23 +30,6 @@ dependencies {
 | 
			
		|||
  testImplementation("com.google.guava:guava-testlib")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sourceSets {
 | 
			
		||||
  main {
 | 
			
		||||
    output.dir("build/generated/properties", "builtBy" to "generateVersionResource")
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
tasks {
 | 
			
		||||
  register("generateVersionResource") {
 | 
			
		||||
    val propertiesDir = file("build/generated/properties/io/opentelemetry/sdk/common")
 | 
			
		||||
    outputs.dir(propertiesDir)
 | 
			
		||||
 | 
			
		||||
    doLast {
 | 
			
		||||
      File(propertiesDir, "version.properties").writeText("sdk.version=${project.version}")
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
for (version in mrJarVersions) {
 | 
			
		||||
  sourceSets {
 | 
			
		||||
    create("java${version}") {
 | 
			
		||||
| 
						 | 
				
			
			@ -87,4 +70,9 @@ tasks {
 | 
			
		|||
      "Multi-Release" to "true"
 | 
			
		||||
    )
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  test {
 | 
			
		||||
    // For checking version number included in Resource.
 | 
			
		||||
    systemProperty("otel.test.project-version", project.version.toString())
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -115,7 +115,7 @@ public abstract class Resource {
 | 
			
		|||
    Properties properties = new Properties();
 | 
			
		||||
    try {
 | 
			
		||||
      properties.load(
 | 
			
		||||
          Resource.class.getResourceAsStream("/io/opentelemetry/sdk/version.properties"));
 | 
			
		||||
          Resource.class.getResourceAsStream("/io/opentelemetry/sdk/common/version.properties"));
 | 
			
		||||
    } catch (Exception e) {
 | 
			
		||||
      // we left the attribute empty
 | 
			
		||||
      return "unknown";
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -212,7 +212,8 @@ class ResourceTest {
 | 
			
		|||
    assertThat(resource.getAttribute(ResourceAttributes.TELEMETRY_SDK_NAME))
 | 
			
		||||
        .isEqualTo("opentelemetry");
 | 
			
		||||
    assertThat(resource.getAttribute(ResourceAttributes.TELEMETRY_SDK_LANGUAGE)).isEqualTo("java");
 | 
			
		||||
    assertThat(resource.getAttribute(ResourceAttributes.TELEMETRY_SDK_VERSION)).isNotNull();
 | 
			
		||||
    assertThat(resource.getAttribute(ResourceAttributes.TELEMETRY_SDK_VERSION))
 | 
			
		||||
        .isEqualTo(System.getProperty("otel.test.project-version"));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,24 +26,3 @@ dependencies {
 | 
			
		|||
  testImplementation(project(":sdk:testing"))
 | 
			
		||||
  testImplementation("com.google.guava:guava")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sourceSets {
 | 
			
		||||
  main {
 | 
			
		||||
    output.dir("build/generated/properties", "builtBy" to "generateVersionResource")
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
tasks {
 | 
			
		||||
  register("generateVersionResource") {
 | 
			
		||||
    val propertiesDir = file("build/generated/properties/io/opentelemetry/sdk/metrics")
 | 
			
		||||
    outputs.dir(propertiesDir)
 | 
			
		||||
 | 
			
		||||
    doLast {
 | 
			
		||||
      File(propertiesDir, "version.properties").writeText("sdk.version=${project.version}")
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  withType(JavaCompile::class) {
 | 
			
		||||
    // Ignore deprecation warnings that AutoValue creates for now.
 | 
			
		||||
    options.compilerArgs.add("-Xlint:-deprecation")
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,7 +11,6 @@ plugins {
 | 
			
		|||
description = "OpenTelemetry SDK For Tracing"
 | 
			
		||||
otelJava.moduleName.set("io.opentelemetry.sdk.trace")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
sourceSets {
 | 
			
		||||
  main {
 | 
			
		||||
    val traceShadedDeps = project(":sdk:trace-shaded-deps")
 | 
			
		||||
| 
						 | 
				
			
			@ -60,22 +59,7 @@ dependencies {
 | 
			
		|||
  jmh("org.testcontainers:testcontainers") // testContainer for OTLP collector
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sourceSets {
 | 
			
		||||
  main {
 | 
			
		||||
    output.dir("build/generated/properties", "builtBy" to "generateVersionResource")
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
tasks {
 | 
			
		||||
  register("generateVersionResource") {
 | 
			
		||||
    val propertiesDir = file("build/generated/properties/io/opentelemetry/sdk/trace")
 | 
			
		||||
    outputs.dir(propertiesDir)
 | 
			
		||||
 | 
			
		||||
    doLast {
 | 
			
		||||
      File(propertiesDir, "version.properties").writeText("sdk.version=${project.version}")
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  withType<AnimalSniffer>().configureEach {
 | 
			
		||||
    // We catch NoClassDefFoundError to fallback to non-jctools queues.
 | 
			
		||||
    exclude("**/internal/shaded/jctools/**")
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue