jacoco-android-gradle-plugin
jacoco-android-gradle-plugin copied to clipboard
Jacoco Problem with Gradle Transform Task
Hi, I use jacoco and ScopedArtifacts.Scope.ALL to do some transform work in my project. The gradle tool version is 8.0 My project structure is as follows: app module a module b app includes module a and module b in app I use ScopedArtifacts.Scope.ALL to write a gradle plugin there is the code :
and I use jacoco in module A and module B too
there is the jacoco code:
now there comes the problem the jacoco task is execute before transform task After the jacoco task is finished, the transform task will get the input dir and input jar( module A class.jar module B class.jar) but when I print the path of input jar , I found that the input jar is still the original jar file without jacoco Instrumentation code.
example:
after jacoco task
the input jar @get:InputFiles abstract val allJars: ListProperty<RegularFile>
class path in the plugin is
Module A/build/intermediates/runtime_library_class_jar/class.jar(without jacoco Instrumentation code)
Module B /build/intermediates/runtime_library_class_jar/class.jar(without jacoco Instrumentation code)
That means jacoco didn't work in my project due to the using of transform task by code mentioned above, because the transform task still use the original class jar ( module A class.jar without jacoco Instrumentation code and module B class.jar without jacoco Instrumentation code) to general the final class.jar that will finally saved in app/build/intermediates/classes/all/class.jar. So how can I do to get the right class.jar of module A and module B that include jacoco Instrumentation code and in gradle 7.0 I found that Module A/build/intermediates/runtime_library_class_jar/class.jar Module B /build/intermediates/runtime_library_class_jar/class.jar include the jacoco Instrumentation code but in gradle 8.0 it's not
transform plugin code: class RcAJXPlugin : Plugin<Project> { override fun apply(project: Project) { project.repositories.mavenLocal() project.dependencies.add("implementation", "org.aspectj:aspectjrt:1.9.6") project.extensions.create("aspectjx", RcAJXExtension::class.java) val extensions = project.extensions extensions.configure( ApplicationAndroidComponentsExtension::class.java ) { extension: ApplicationAndroidComponentsExtension -> extension.onVariants() { variant -> val transformTask = project.tasks.register( "transform${variant.name.capitalized()}", RcAJXTransformTask::class.java ) { task -> task.mappingFile.set(project.buildDir.resolve("outputs/transform/mapping.txt")) } variant.artifacts .forScope(ScopedArtifacts.Scope.ALL) .use(transformTask) .toTransform( ScopedArtifact.CLASSES, RcAJXTransformTask::allJars, RcAJXTransformTask::allDirectories, RcAJXTransformTask::output )
}
}
}
}
jacoco code:
apply plugin: 'jacoco'
android { testOptions { unitTests.all { jacoco { includeNoLocationClasses = true output = JacocoTaskExtension.Output.FILE jacoco.excludes = ['jdk.internal.*'] jvmArgs '-noverify' } } } }
task jacocoVideoCoverageReport(type: JacocoReport) { group = "Reporting" description = "Generate Jacoco coverage reports" reports { xml { setEnabled(true) } html { setEnabled(true) } }
// exclude auto-generated classes and tests
def fileFilter = [
'**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/databinding/**',
'**/viewcomponent/**',
'**/listener/**',
'**/dialog/**',
'**/foundation/debug/**',
'**/*Activity.*',
'**/*Dialog.*',
'**/*Layout.*',
'**/*Widget.*',
'**/*Menu.*',
'**/*Notification.*',
'**/*NotificationHandler.*',
'**/*Button.*',
'**/*Fragment.*',
'**/*View.*',
'**/*Drawable.*',
'**/*Animator.*',
'**/*Const.*',
'**/*Listener.*',
'**/*Callback.*',
'**/*Receiver.*',
'**/*LayoutManager.*',
'**/*PageAdapter.*',
'**/*PagerAdapter.*',
'**/*SectionAdapter.*',
'**/*Analytics.*',
'**/*AnalyticsHelper.*',
'**/*EventReporter.*',
'**/*Tracer.*',
'**/*Tracker.*',
'**/*Performances.*',
'**/*LogInsight.*',
'**/*Service.*',
'**/*DelegateHelper.*',
'**/*ControllerFactory.*',
'**/*ControllerHelper.*',
'**/*CallbackHelper.*',
'**/*ListenerHelper.*',
'**/*Module.*',
'**/*ViewAdapter.*',
'**/*ViewContainer.*',
'**/*ViewpagerAdapter.*',
'**/*SettingsViewDelegate.*',
'**/*Preference.*',
'**/*dialog.*',
'**/*DelegateWrapper.*',
'**/*CallbackWrapper.*',
'**/*ListenerWrapper.*',
'**/*ViewHelper.*',
'**/loginsight/**',
'**/zoom/**',
'**/preferences/**',
'**/VideoCoreDelegateHelper.*',
'**/*Test.*',
'**/E**Type.*',
'android/**/*.*',
'**/*ViewHolder.*',
'**/*Fragment$*.*',
'**/*Activity$*.*',
'**/*View$*.*',
'**/*ViewDelegate.*']
def javaClasses = fileTree(dir: "$project.buildDir/intermediates/javac/debug", excludes: fileFilter)
def kotlinClasses = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/debug", excludes: fileFilter)
print "source file ===============${android.sourceSets.main.java.srcDirs}"
sourceDirectories.setFrom(files(android.sourceSets.main.java.srcDirs))
classDirectories.setFrom(files([javaClasses, kotlinClasses]))
executionData.setFrom(fileTree(dir: project.buildDir, includes: [
"**/*.exec", '**/*.ec'
]))
}