Setup jacoco (#60)
This commit is contained in:
		
							parent
							
								
									ed31fbaac9
								
							
						
					
					
						commit
						2332851f38
					
				| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
This is a utility project which depends on all other projects in this repository. We use it for global checks, for example collecting all coverage reports from all modules for uploading to codecov.
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,68 @@
 | 
			
		|||
plugins {
 | 
			
		||||
    id("otel.java-conventions")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
description = "OpenTelemetry Contrib Testing"
 | 
			
		||||
 | 
			
		||||
dependencies {
 | 
			
		||||
    rootProject.subprojects.forEach { subproject ->
 | 
			
		||||
        // Generate aggregate coverage report for published modules that enable jacoco.
 | 
			
		||||
        subproject.plugins.withId("jacoco") {
 | 
			
		||||
            subproject.plugins.withId("maven-publish") {
 | 
			
		||||
                implementation(project(subproject.path)) {
 | 
			
		||||
                    isTransitive = false
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// https://docs.gradle.org/current/samples/sample_jvm_multi_project_with_code_coverage.html
 | 
			
		||||
 | 
			
		||||
val sourcesPath by configurations.creating {
 | 
			
		||||
    isVisible = false
 | 
			
		||||
    isCanBeResolved = true
 | 
			
		||||
    isCanBeConsumed = false
 | 
			
		||||
    extendsFrom(configurations.implementation.get())
 | 
			
		||||
    attributes {
 | 
			
		||||
        attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
 | 
			
		||||
        attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION))
 | 
			
		||||
        attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("source-folders"))
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
val coverageDataPath by configurations.creating {
 | 
			
		||||
    isVisible = false
 | 
			
		||||
    isCanBeResolved = true
 | 
			
		||||
    isCanBeConsumed = false
 | 
			
		||||
    extendsFrom(configurations.implementation.get())
 | 
			
		||||
    attributes {
 | 
			
		||||
        attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
 | 
			
		||||
        attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION))
 | 
			
		||||
        attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("jacoco-coverage-data"))
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
tasks.named<JacocoReport>("jacocoTestReport") {
 | 
			
		||||
    enabled = true
 | 
			
		||||
 | 
			
		||||
    configurations.runtimeClasspath.get().forEach {
 | 
			
		||||
        additionalClassDirs(zipTree(it).filter {
 | 
			
		||||
            // Exclude mrjar (jacoco complains), shaded, and generated code
 | 
			
		||||
            !it.absolutePath.contains("META-INF/versions/") &&
 | 
			
		||||
                    !it.absolutePath.contains("AutoValue_")
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
    additionalSourceDirs(sourcesPath.incoming.artifactView { lenient(true) }.files)
 | 
			
		||||
    executionData(coverageDataPath.incoming.artifactView { lenient(true) }.files.filter { it.exists() })
 | 
			
		||||
 | 
			
		||||
    reports {
 | 
			
		||||
        // xml is usually used to integrate code coverage with
 | 
			
		||||
        // other tools like SonarQube, Coveralls or Codecov
 | 
			
		||||
        xml.required.set(true)
 | 
			
		||||
 | 
			
		||||
        // HTML reports can be used to see code coverage
 | 
			
		||||
        // without any external tools
 | 
			
		||||
        html.required.set(true)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,49 @@
 | 
			
		|||
plugins {
 | 
			
		||||
    `java-library`
 | 
			
		||||
 | 
			
		||||
    jacoco
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// https://docs.gradle.org/current/samples/sample_jvm_multi_project_with_code_coverage.html
 | 
			
		||||
 | 
			
		||||
// Do not generate reports for individual projects
 | 
			
		||||
tasks.named("jacocoTestReport") {
 | 
			
		||||
    enabled = false
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
configurations {
 | 
			
		||||
    val implementation by getting
 | 
			
		||||
 | 
			
		||||
    create("transitiveSourceElements") {
 | 
			
		||||
        isVisible = false
 | 
			
		||||
        isCanBeResolved = false
 | 
			
		||||
        isCanBeConsumed = true
 | 
			
		||||
        extendsFrom(implementation)
 | 
			
		||||
        attributes {
 | 
			
		||||
            attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
 | 
			
		||||
            attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION))
 | 
			
		||||
            attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("source-folders"))
 | 
			
		||||
        }
 | 
			
		||||
        sourceSets.main.get().java.srcDirs.forEach {
 | 
			
		||||
            outgoing.artifact(it)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    create("coverageDataElements") {
 | 
			
		||||
        isVisible = false
 | 
			
		||||
        isCanBeResolved = false
 | 
			
		||||
        isCanBeConsumed = true
 | 
			
		||||
        extendsFrom(implementation)
 | 
			
		||||
        attributes {
 | 
			
		||||
            attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
 | 
			
		||||
            attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION))
 | 
			
		||||
            attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("jacoco-coverage-data"))
 | 
			
		||||
        }
 | 
			
		||||
        // This will cause the test task to run if the coverage data is requested by the aggregation task
 | 
			
		||||
        // The tasks must be eagerly evaluated (no configureEach) to ensure jacoco is wired up
 | 
			
		||||
        // correctly.
 | 
			
		||||
        tasks.withType<Test>() {
 | 
			
		||||
            outgoing.artifact(the<JacocoTaskExtension>().destinationFile!!)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -3,6 +3,7 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat
 | 
			
		|||
plugins {
 | 
			
		||||
    `java-library`
 | 
			
		||||
 | 
			
		||||
    id("otel.jacoco-conventions")
 | 
			
		||||
    id("otel.spotless-conventions")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,6 +16,7 @@ dependencyResolutionManagement {
 | 
			
		|||
 | 
			
		||||
rootProject.name = "opentelemetry-java-contrib"
 | 
			
		||||
 | 
			
		||||
include(":all")
 | 
			
		||||
include(":aws-xray")
 | 
			
		||||
include(":dependencyManagement")
 | 
			
		||||
include(":example")
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue