stevesaliman / gradle-cobertura-plugin Goto Github PK
View Code? Open in Web Editor NEWGradle Cobertura Plugin
Gradle Cobertura Plugin
A have a multi project with a lot of sub projects. I apply the cobertura plugin only to my production projects (since I don't want to generate report for my mock projects). It sees not to work.
Execute:
./gradlew clean cobertura build
Gradle reports:
* What went wrong:
Extension with name 'cobertura' does not exist. Currently registered extension names: [ext, defaultArtifacts, reporting]
If I apply the plugin to all sub projects then it works as expected.
I need xml reports so that Jenkins can use them for reports
Using recent snapshot I've got NPE when cobertura plugin is applied after groovy plugin (it works fine when applied before).
Applying cobertura plugin to gradle-pitest-plugin
creating extension
FAILURE: Build failed with an exception.
* Where:
Build file '/home/foo/gradle-pitest-plugin/build.gradle' line: 5
* What went wrong:
A problem occurred evaluating root project 'gradle-pitest-plugin'.
> Could not create an instance of type net.saliman.gradle.plugin.cobertura.CoberturaExtension_Decorated.
with root cause:
Caused by: java.lang.NullPointerException
at net.saliman.gradle.plugin.cobertura.CoberturaExtension_Decorated.getProperty(Unknown Source)
at net.saliman.gradle.plugin.cobertura.CoberturaExtension$_closure3.doCall(CoberturaExtension.groovy:220)
at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:58)
at org.gradle.api.internal.Actions$FilteredAction.execute(Actions.java:203)
at org.gradle.api.internal.DefaultDomainObjectCollection.all(DefaultDomainObjectCollection.java:110)
at org.gradle.api.internal.DefaultDomainObjectCollection.all(DefaultDomainObjectCollection.java:115)
at org.gradle.api.internal.DefaultDomainObjectCollection.withType(DefaultDomainObjectCollection.java:126)
at org.gradle.api.DomainObjectCollection$withType.call(Unknown Source)
at net.saliman.gradle.plugin.cobertura.CoberturaExtension.<init>(CoberturaExtension.groovy:219)
at net.saliman.gradle.plugin.cobertura.CoberturaExtension_Decorated.<init>(Unknown Source)
at org.gradle.internal.reflect.DirectInstantiator.newInstance(DirectInstantiator.java:39)
... 70 more
Under JDK 1.7.0_09 on Windows 7 with Cygwin, I see the following with many (all?) of my test classes:
java.lang.VerifyError: Instruction type does not match stack map in method package.ClassName.method(signature) at offset NNN
at package.ClassNameTest.testMethod(ClassNameTest.java:NNN)
Running the same build under Linux Mint 12, JDK 1.6.0_26 does not exhibit the same problems.
I'll see if I can put together a minimal test case for this when I can catch a spare moment.
Cobertura plugin for Mockito build generates in XML report file:
<sources>
<source>/home/foo/mockito/src/main/java</source>
</sources>
while the source files are placed directly in /home/foo/mockito/src/
(which can mislead some other plugins parsing XML report - like Coveralls plugin).
Given revision uses gradle-cobertura-plugin 2.0.0, but 2.2.4 tested locally works the same way.
:[project]:instrument
Cobertura 2.0.3 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
log4j:ERROR A "org.apache.log4j.ConsoleAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
log4j:ERROR [java.net.URLClassLoader@234d5408] whereas object of type
log4j:ERROR "org.apache.log4j.ConsoleAppender" was loaded by [org.gradle.util.MutableURLClassLoader@398b0a62].
log4j:ERROR Could not instantiate appender named "console".
All of a sudden, I have started seeing an issue where not matter what I do, Gradle appears to be skipping the instrument
, copyCoberturaDatafile
, generateCoberturaReport
and performCoverageCheck
tasks when building a Gradle project. The project in question uses the following plugins:
I am pretty sure that this was working not too long ago. The only thing that I believe that might have changed is an update from Gradle 1.10 to 1.11. The project in question uses Spock for the unit tests and is using the following test
and cobertura
configuration in the build.gradle
script:
test {
filter {
includeTestsMatching "*Test"
includeTestsMatching "*Spec"
}
}
cobertura {
coverageFormats = ['html', 'xml']
coverageIgnoreTrivial = true
coverageIgnores = ['org.slf4j.Logger.*']
coverageReportDir = new File("$buildDir/reports/cobertura")
}
I have tried versions 2.2.2, 2.2.3 and 2.2.4 of the plugin, all with the same results. Removing the build
directory and/or modifying source files does not appear to have any affect, as the tasks are always skipped. I also tried providing explicitly the tasks to trigger the instrumentation (per the configuration options), but no luck. My suspicion is that perhaps a subtle API change between Gradle 1.10 and 1.11 has affected the tasks. I am going to try to downgrade to Gradle 1.10 and see if the coverage works.
It seems that the instrumentation and coberturaReport task are skipped if only Groovy-Code changes (Task compileGroovy) and no Java-Code changes (Task compileJava).
Due to the source code, instrumentation is based on compileJava and ignores compileGroovy. May be it would besser to depend on Task classes.
I would like to run only instrument task (without running tests and generating report), but I always get 'SKIPPED'. Is it possible with your plugin?
EDIT: ok, it is possible. It must be run coberturaReport task before
Instrumentation fails on Windows boxes because the Auxiliary classpath given to Cobertura is specific to Unix environments.
Unable to instrument file /Users/brianhuddleston/Dropbox/sbi-api/build/instrumented_classes/com/dg/api/CacheModule$1.class
java.lang.IllegalArgumentException: Invalid inner class name (must be a valid Java identifier): 1
The code snippet in question looks like this:
private static LoadingCache<String, String> leaderCache =
CacheBuilder.newBuilder().maximumSize(10000).expireAfterWrite(3, TimeUnit.HOURS).recordStats()
.build(new CacheLoader<String, String>() {
@Override
String load(String key) throws Exception {
log.info("Fetching leaderBoard $key from source")
def (boardId, fieldList) = key.split(/\|/)
BrandList.getLeaderListJson(Long.parseLong(boardId.toString()), fieldList.toString())
}
})
Full stacktrace is:
Unable to instrument file /Users/brianhuddleston/Dropbox/sbi-api/build/instrumented_classes/com/dg/api/CacheModule$1.class
java.lang.IllegalArgumentException: Invalid inner class name (must be a valid Java identifier): 1
at org.objectweb.asm.util.CheckMethodAdapter.checkIdentifier(Unknown Source)
at org.objectweb.asm.util.CheckMethodAdapter.checkIdentifier(Unknown Source)
at org.objectweb.asm.util.CheckClassAdapter.visitInnerClass(Unknown Source)
at org.objectweb.asm.ClassVisitor.visitInnerClass(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.instrumentClass(CoberturaInstrumenter.java:153)
at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.instrumentClass(CoberturaInstrumenter.java:121)
at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.addInstrumentationToSingleClass(CoberturaInstrumenter.java:234)
at net.sourceforge.cobertura.instrument.Main.addInstrumentationToSingleClass(Main.java:298)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:307)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:316)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:316)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:316)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:316)
at net.sourceforge.cobertura.instrument.Main.parseArguments(Main.java:399)
at net.sourceforge.cobertura.instrument.Main.main(Main.java:421)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSite.invoke(PojoMetaMethodSite.java:189)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
at net.saliman.gradle.plugin.cobertura.CoberturaRunner.executeCobertura(CoberturaRunner.groovy:199)
at net.saliman.gradle.plugin.cobertura.CoberturaRunner.this$2$executeCobertura(CoberturaRunner.groovy)
at net.saliman.gradle.plugin.cobertura.CoberturaRunner$this$2$executeCobertura.callCurrent(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:153)
at net.saliman.gradle.plugin.cobertura.CoberturaRunner.instrument(CoberturaRunner.groovy:86)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:226)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:64)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at net.saliman.gradle.plugin.cobertura.InstrumentTask.instrument(InstrumentTask.groovy:139)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.gradle.util.JavaMethod.invoke(JavaMethod.java:62)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:219)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:212)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:201)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:527)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:510)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:283)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$1.run(DefaultTaskPlanExecutor.java:33)
at org.gradle.internal.Factories$1.create(Factories.java:22)
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:214)
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:276)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:142)
at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:78)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:31)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:86)
at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
at org.gradle.api.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
at org.gradle.launcher.Main.doAction(Main.java:46)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at org.gradle.launcher.Main.main(Main.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
In version 1.x of the plugin, failures in test tasks were intercepted and delayed until after the coverage reports ran. This had the side effect of making sure all test tasks would run before generating the coverage report.
In version 2.0.0 of the plugin, I switched to the much simpler `finalizedBy`` mechanism of making sure reports would be generated after failed tests. When a test failure happens, Gradle won't run any new tasks, except for tasks needed to finalize tasks that have already run. This has the side effect of generating reports that exclude tests run from tasks downstream of the failed one.
I don't want to restore the old behavior as a default because I don't want to inject myself into Gradle's sense of what should run and what shouldn't, but I do want to restore the old behavior as an option for those who:
Currently it is possible to add only one format of Cobertura. In reality it is sometimes necessary to generate e.g. two types of reports from same Cobertura run. For example when using Sonar in project you should provide *.xml file with coverage report. But in the same time it is also necessary to generate html report for humans. It's not easy to overcome this problem, but implementing it in plugin code is very simple (at least in the simplest version). I had to implement it myself to use reports in Sonar.
My changes:
In file: CoberturaExtension.groovy
/**
* Formats of cobertura report. Default is only 'html'
*/
Set<String> coverageFormat = ['html']
In file: CoberturaPlugin.groovy insert in line no. 102:
Set<String> formats = task.project.extensions.cobertura.coverageFormat
for(format in formats) {
task.project.coberturaRunner.generateCoverageReport
task.project.extensions.cobertura.coverageDatafile.path,
task.project.extensions.cobertura.coverageReportDir.path, format,
task.project.files(task.project.extensions.cobertura.coverageSourceDirs).files.collect { it.path }
}
It is very simplistic implementation but works very well.
Possible extension would be to define format and report output directories in pairs, so that every report can be generated do different directory.
apply plugin: 'java' ... buildscript { repositories { mavenCentral() } dependencies { classpath "net.saliman:gradle-cobertura-plugin:1.1.2" } } apply plugin: 'cobertura'
Gradle 1.6 output:
The ConfigurationContainer.add() method has been deprecated and is scheduled to be removed in Gradle 2.0. Please use the create() method instead.
The TaskContainer.add() method has been deprecated and is scheduled to be removed in Gradle 2.0. Please use the create() method instead.
It would be great if the gradle-cobertura-plugin
participated in the report hooks used by the build-dashboard
plugin.
I am trying to incorporate the cobertura plugin. I am getting the following exception when I run any task like build or test.
Where:
Build file '/Users/msinghi/Dev/service-registry/build.gradle' line: 46
What went wrong:
A problem occurred evaluating root project 'service-registry'.
Could not find method create() for arguments [{name=instrument, type=class net.saliman.gradle.plugin.cobertura.InstrumentTask}, net.saliman.gradle.plugin.cobertura.CoberturaPlugin$_apply_closure3@21ad125b] on task set.
Caused by: org.gradle.api.internal.MissingMethodException: Could not find method create() for arguments [{name=instrument, type=class net.saliman.gradle.plugin.cobertura.InstrumentTask}, net.saliman.gradle.plugin.cobertura.CoberturaPlugin$_apply_closure3@1ad46fd4] on task set.
at org.gradle.api.internal.AbstractDynamicObject.methodMissingException(AbstractDynamicObject.java:68)
at org.gradle.api.internal.AbstractDynamicObject.invokeMethod(AbstractDynamicObject.java:56)
I am using Java 7 and My build.gradle looks like this -
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
repositories {
mavenCentral()
maven {
url "http://files.couchbase.com/maven2/"
}
}
dependencies {
compile "javax.ws.rs:jsr311-api:1.1.1"
compile 'couchbase:couchbase-client:1.1.9'
compile 'org.glassfish.jersey.ext:jersey-spring3:2.2'
compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.2'
compile 'org.glassfish.jersey.ext:jersey-bean-validation:2.2'
compile 'ch.qos.logback:logback-classic:1.0.13'
compile 'ch.qos.logback:logback-access:1.0.13'
testCompile "junit:junit-dep:4.11"
testCompile "org.mockito:mockito-core:1.9.5"
}
task wrapper(type: Wrapper) {
gradleVersion = '1.7'
}
apply plugin: 'checkstyle'
checkstyle {
ignoreFailures = false
configFile = rootProject.file('codequality/checkstyle.xml')
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "net.saliman:gradle-cobertura-plugin:2.0.0"
}
}
apply plugin: 'cobertura'
I was playing with 2.2.0-SNAPSHOT and in the report instead of code listing with the coverage I see:
Unable to locate info/solidsoft/gradle/pitest/PitestPlugin.groovy. Have you specified the source directory?
It worked fine with 2.1.0. Is it required to configure any additional parameter in build.gradle?
Gradle 1.9. The plain Groovy project. I can provide a small project to reproduce this issue if needed.
The top of my build.gradle
looks like this:
apply plugin: 'grails'
apply plugin: 'cobertura'
When I run "gradlew tasks" (or anything else), it fails like this:
> Cannot add task ':check' as a task with that name already exists.
So these two are stepping on each others' toes. How can I fix this?
The cobertura-plugin can generate coverage reports for projects that have Groovy code, but the details of Groovy classes are missing from the reports because only Java source code is included in the cobertura's source directory set.
Hello,
I am using the 2.2.0 version of the plugin and have found that all of my tasks of type Test are dependencies of the cobertura task regardless of the coverageTestTasks setting. I have the following:
task integration(type: Test) {
testClassesDir = sourceSets.integration.output.classesDir
classpath += sourceSets.integration.runtimeClasspath
}
cobertura {
coverageFormats = ["xml", "html"]
coverageTestTasks {
project.tasks.withType(Test).matching {
it.name.contains("test")
}
}
}
println cobertura.getCoverageTestTasks()
This prints out "[task ':my-project:test']". I would expect that only "test" should be run prior to cobertura but when I list the task dependencies using gradle tasks --all I see the following:
Other tasks
-----------
cobertura - Run tests and generate Cobertura coverage reports. [classes, integrationClasses, test, testClasses,
coberturaReport - Generate Cobertura reports after tests finish.
integration
Is this a bug? I can get around it by doing the following:
project.tasks.getByName("cobertura").dependsOn -= integration
Thanks.
When the cobertura plugin is applied, certain task dependencies are set up, but it only uses tasks in the graph at that moment, which means that tasks added later, such as in child projects may not be added properly.
For example, if a project uses Groovy, but not Java, and if the cobertura plugin is added ahead of the groovy plugin, the groovy test task my not be set up properly.
I was using the gradle-cobertura-plugin for a while without issues. However, today it started failing with the following error
FAILURE: Build failed with an exception.
Module version misc:myproject:1.0-SNAPSHOT, configuration 'testRuntime' declares a dependency on configuration 'default' which is not declared in the module descriptor for net.sourceforge.cobertura:cobertura:2.0.3
and the snippet of configuration which I use is the following
buildscript { repositories { mavenCentral() } dependencies { classpath "net.saliman:gradle-cobertura-plugin:1.2.0" } }
apply plugin: 'java' apply plugin: 'cobertura' cobertura { cobertura.coverageIgnoreTrivial = true coverageFormats = ['xml', 'html'] cobertura.coverageExcludes = ['.*DTO.*'] } dependencies { testCompile group: 'junit', name: 'junit', version: '4.11' testCompile 'com.h2database:h2:1.3.164' testCompile group: 'org', name: 'mockachino', version: '0.6.1', configuration: 'runtime' }
The closest issue which came up from web is this http://play.lighthouseapp.com/projects/82401-play-20/tickets/779-publish-local-creates-invalid-ivy-file which seem to indicate that the dependency inside the plugin needs to be changed, which I am not sure.
Can you please advise on how to fix this?
Hi,
please add the coverageFormats option to the README file.
Maybe there are more options missing in the documentation.
Thanks.
Best regards
Roland
I am having problems getting the plugin to work. The Jacoco plugin works fine, but I can't get Cobertura to work.
Here is what I added in build.gradle (using the 2.0 version of the Gradle wrapper and running under Java 8):
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'net.saliman:gradle-cobertura-plugin:2.2.4'
classpath 'org.gradle.api.plugins:gradle-nexus-plugin:0.7'
}
}
apply plugin: 'cobertura'
and here is the error I get. It is repeated for every file it tries to instrument.
C:\Prj\seerapi-client-java>gradlew clean cobertura
:clean
:coberturaReport UP-TO-DATE
:compileJava
:processResources UP-TO-DATE
:classes
:instrument
Cobertura 2.0.3 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
Unable to instrument file C:\Prj\seerapi-client-java\build\instrumented_classes\com\imsweb\seerapi\client\cs\CsCodeValidity.class
java.lang.IllegalArgumentException
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.instrumentClass(CoberturaInstrumenter.java:147)
at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.instrumentClass(CoberturaInstrumenter.java:121)
at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.addInstrumentationToSingleClass(CoberturaInstrumenter.java:234)
at net.sourceforge.cobertura.instrument.Main.addInstrumentationToSingleClass(Main.java:298)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:307)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:316)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:316)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:316)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:316)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:316)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:316)
at net.sourceforge.cobertura.instrument.Main.parseArguments(Main.java:399)
I am trying to run cobertura through ant, using jdk 7. but getting exception while instrumentation.
it was working fine with previous version of cobertura 1.5, with jdk 6.
currently i just upgraded jdk and cobertura.
exception is -
[cobertura-instrument] WARN instrumentClass, Unable to instrument file C:\MyCodeBase\Sample.class
[cobertura-instrument] java.lang.IncompatibleClassChangeError: net/sourceforge/c
obertura/instrument/pass1/DetectIgnoredCodeClassVisitor
[cobertura-instrument] at net.sourceforge.cobertura.instrument.CoberturaInstrum
enter.instrumentClass(CoberturaInstrumenter.java:149)
[cobertura-instrument] at net.sourceforge.cobertura.instrument.CoberturaInstrum
enter.instrumentClass(CoberturaInstrumenter.java:121)
[cobertura-instrument] at net.sourceforge.cobertura.instrument.CoberturaInstrum
enter.addInstrumentationToSingleClass(CoberturaInstrumenter.java:234)
[cobertura-instrument] at net.sourceforge.cobertura.instrument.Main.addInstrume
ntationToSingleClass(Main.java:298)
[cobertura-instrument] at net.sourceforge.cobertura.instrument.Main.addInstrume
ntation(Main.java:307)
[cobertura-instrument] at net.sourceforge.cobertura.instrument.Main.parseArgume
nts(Main.java:399)
[cobertura-instrument] at net.sourceforge.cobertura.instrument.Main.main(Main.j
ava:421)
I'm searching for a gradle cobertura plugin that supports my scenario: I have a multiproject where several projects contains some logically related contents and a single project that provides tests for all other projects.
The tests have been moved to a dedicate project cause I every project is backed by an eclipse project, and eclipse doesn't support separating tests from sources (within a single project). See http://tech.groups.yahoo.com/group/junit/message/22398
So launching gradle clean cobertura on a gradle multiproject structure like the following
. //the multi-project
|-- build.gradle
|-- prj1 //the 'real' project
| |-- build.gradle
| `-- src
| `-- main
| `-- groovy
| `-- Foo.groovy
|-- settings.gradle
`-- testprj //the test project
|-- build.gradle
`-- src
`-- test
`-- groovy
`-- FooTest.groovy //tests for Foo.groovy
I have the following problems:
I've uploaded an archive with the complete multiproject test case.
UPDATE: I've filed a similar issue to other gradle-cobertura plugins... is there any change to join your forces and provide a unified, comprehensive plugin that supports even my scenario?
I want change cobertura.coverageDirs in project configuration to point to another project like
cobertura.coverageDirs = [ project(':xxxxx').sourceSets.main.output.classesDir.path ]
You don't use getClassesDirs or cobertura.coverageDirs in the task InstrumentTask.
Maybe this can fix my problem.
I find a tempory solution
instrument.doFirst {
project.copy {
project.files(project(':xxxxx').sourceSets.main.output.classesDir.path).each {
File f -> from f
}
into "${project.buildDir}/instrumented_classes"
}
}
Thanks.
Instructions are laid out at http://plugins.gradle.org/submit
Suggested values for the gradle-plugin attribute parts:
The shadow
plugin uses the com.jfrog.bintray
plugin to automate the upload, as shown in https://github.com/johnrengelman/shadow/blob/master/gradle/publish.gradle
You can sync with Sonatype's repo once a package has been published to Bintray.
See USERCLASS in this jstack trace.
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:605)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:333)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:307)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:645)
at USERCLASS.<clinit>(USERCLASS.java:39)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at net.sourceforge.cobertura.instrument.CoberturaClassWriter.getCommonSuperClass(CoberturaClassWriter.java:32)
at org.objectweb.asm.ClassWriter.a(Unknown Source)
at org.objectweb.asm.Frame.a(Unknown Source)
at org.objectweb.asm.Frame.a(Unknown Source)
at org.objectweb.asm.MethodWriter.visitMaxs(Unknown Source)
at org.objectweb.asm.MethodVisitor.visitMaxs(Unknown Source)
at org.objectweb.asm.util.CheckMethodAdapter.visitMaxs(Unknown Source)
at org.objectweb.asm.MethodVisitor.visitMaxs(Unknown Source)
at org.objectweb.asm.MethodVisitor.visitMaxs(Unknown Source)
at org.objectweb.asm.commons.LocalVariablesSorter.visitMaxs(Unknown Source)
at org.objectweb.asm.tree.MethodNode.accept(Unknown Source)
at org.objectweb.asm.util.CheckMethodAdapter$1.visitEnd(Unknown Source)
at org.objectweb.asm.MethodVisitor.visitEnd(Unknown Source)
at org.objectweb.asm.util.CheckMethodAdapter.visitEnd(Unknown Source)
at org.objectweb.asm.ClassReader.b(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.instrumentClass(CoberturaInstrumenter.java:205)
at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.instrumentClass(CoberturaInstrumenter.java:121)
at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.addInstrumentationToSingleClass(CoberturaInstrumenter.java:234)
at net.sourceforge.cobertura.instrument.Main.addInstrumentationToSingleClass(Main.java:298)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:307)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:316)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:316)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:316)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:316)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:316)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:316)
at net.sourceforge.cobertura.instrument.Main.parseArguments(Main.java:399)
at net.sourceforge.cobertura.instrument.Main.main(Main.java:421)
Hi,
I'm in the process of writing a load of unit tests for this project (I just love writing UTs, and it's a good way to learn).
I'd written a complete set of tests for most classes, and today I pulled the latest changes to my repo. After merging, I'm encountering a failure, which is indicating odd behaviour - it might be correct, but I wanted to check before re-doing the tests.
The test is as follows:
Define a project
Pass it into the constructor of CoberturaExtension
test the correct coverageSourceDirs are set, based on the language plugin
Before the change, a plain project had 1 coverageSourceDir, for java, which is correct.
A project with groovy applied had 2, while a project with groovy and scala applied had 3
after the change the extra coverageSourceDirs are not set - only the java one is present.
Is this intended behaviour, or have I mis-understood the purpose of the class?
Thanks
Jim
In a multi-project build, gradle cobertura
only causes tests in projects that have the plugin applied to run. We want run the same tests with gradle cobertura
as would run if we ran gradle test
.
Note that if the soruce and test code non-cobertura project are unchanged, gradle would not normally run the tests again.
Hi,
When we use power mock with gradle, gradle-cobetura-plugin does not generate the coverage report for the tests with power mock. However tests with out power mock is shown in the coverage report properly even-though they are in the same project.
Please check the following sample code I have written to recreate the issue.
https://github.com/lpambagoda/cobertura-gradle-powermock-issue
I have tested this with gradle 1.7 to 1.10 with gradle-cobetura-plugin 2.2.2.
There was a similar issue reported for maven as well. However that issue is fixed now.
http://www.jsfblog.info/2010/02/cobertura-code-coverage-with-maven-and-powermock/
Best Regards
Lasantha
The instrumentation task currently only does work when the coberturaReport task is in the task graph, but when it is, the plugin instruments every time, regardless of whether or not the source code actually changed.
I'm using jettyRun to execute my webapp on a container to execute some integration test on it.
But the instrumented classes are not used by jetty.
SO the cobertura report doesn't include execution made using integration tests
Hi,
we have some projects with non-UTF-8 source encoding.
It would be great if you could provide an option to specify the character encoding of files.
Thanks.
Best regards
Roland
I've working on a project using gradle 2.0 and java8. The current gradle-cobertur-plugin does not work with gradle 2.0 as its using alot of gradle methods deprecated as of gradle-1.12 and removed in gradle-2.0.
I switched to gradle 1.8 but Cobertura is unable to cover the unit tests as its failing due to instrumentation errors I'm guessing -> java.lang.VerifyError: Expecting a stackmap frame at branch target 185.
configurations {
cobertura.exclude group: 'xalan'
cobertura.exclude group: 'xerces'
}
Getting the following error using just the vanilla build.gradle file:
=== build.gradle ===
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "net.saliman:gradle-cobertura-plugin:1.1.2"
}
}
apply plugin: 'cobertura'
=== build.gradle ===
==== ERROR: =====
Could not find net.sourceforge.cobertura:cobertura:1.9.4.1.
Required by:
:cover-code:unspecified
Any ideas why this is happening?
Using version of plugin resolved to: net.saliman:gradle-cobertura-plugin:2.0.0
With gradle --verson outputing:
Build time: 2013-08-06 11:19:56 UTC
Build number: none
Revision: 9a7199efaf72c620b33f9767874f0ebced135d83
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.8.4 compiled on May 22 2012
Ivy: 2.2.0
JVM: 1.6.0_21 (Sun Microsystems Inc. 17.0-b17)
OS: Windows 7 6.1 amd64
Every time I run the cobertura task gradle prints out the following stacktrace during instrument. Cobertura seems to successfully generate a code coverage report, so perhaps this is just noise bubbling up form cobertura, but it might have something to do with the inability to link to groovy source. It claims that while instrumenting class A it cannot find class B. My code is such that class A imports class B and uses it as an input to a method.
Note: I've redacted the package and class name of my classes involved here as I'm using this plugin in a build for a tool I'm writing for my employer.
java.lang.RuntimeException: java.lang.ClassNotFoundException: [CLASSNAME REDATCED: depended on object]
at net.sourceforge.cobertura.instrument.CoberturaClassWriter.getCommonSuperClass(CoberturaClassWriter.java:35)
at org.objectweb.asm.ClassWriter.a(Unknown Source)
at org.objectweb.asm.Frame.a(Unknown Source)
at org.objectweb.asm.Frame.a(Unknown Source)
at org.objectweb.asm.MethodWriter.visitMaxs(Unknown Source)
at org.objectweb.asm.MethodVisitor.visitMaxs(Unknown Source)
at org.objectweb.asm.util.CheckMethodAdapter.visitMaxs(Unknown Source)
at org.objectweb.asm.MethodVisitor.visitMaxs(Unknown Source)
at org.objectweb.asm.commons.LocalVariablesSorter.visitMaxs(Unknown Source)
at org.objectweb.asm.tree.MethodNode.accept(Unknown Source)
at org.objectweb.asm.util.CheckMethodAdapter$1.visitEnd(Unknown Source)
at org.objectweb.asm.MethodVisitor.visitEnd(Unknown Source)
at org.objectweb.asm.util.CheckMethodAdapter.visitEnd(Unknown Source)
at org.objectweb.asm.ClassReader.b(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.instrumentClass(CoberturaInstrumenter.java:205)
at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.instrumentClass(CoberturaInstrumenter.java:121)
at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.addInstrumentationToSingleClass(CoberturaInstrumenter.java:234)
at net.sourceforge.cobertura.instrument.Main.addInstrumentationToSingleClass(Main.java:298)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:307)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:316)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:316)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:316)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:316)
at net.sourceforge.cobertura.instrument.Main.parseArguments(Main.java:399)
at net.sourceforge.cobertura.instrument.Main.main(Main.java:421)
at net.saliman.gradle.plugin.cobertura.CoberturaRunner.instrument(CoberturaRunner.java:79)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSite.invoke(PojoMetaMethodSite.java:189)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at net.saliman.gradle.plugin.cobertura.InstrumentTask.instrument(InstrumentTask.groovy:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1047)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:877)
at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:248)
at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:136)
at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147)
at net.saliman.gradle.plugin.cobertura.InstrumentTask_Decorated.invokeMethod(Unknown Source)
at sun.reflect.GeneratedMethodAccessor22.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1047)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:877)
at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:248)
at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:136)
at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147)
at net.saliman.gradle.plugin.cobertura.InstrumentTask_Decorated.invokeMethod(Unknown Source)
at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
at org.gradle.util.ReflectionUtil.invoke(ReflectionUtil.groovy:23)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:220)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:213)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:202)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:530)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:513)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:286)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:80)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:66)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTaskWithCacheLock(AbstractTaskPlanExecutor.java:58)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:47)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$1.run(DefaultTaskPlanExecutor.java:33)
at org.gradle.internal.Factories$1.create(Factories.java:22)
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:214)
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:276)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:142)
at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:78)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:31)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:89)
at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
at org.gradle.api.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
at org.gradle.launcher.Main.doAction(Main.java:48)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at org.gradle.launcher.Main.main(Main.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
at org.gradle.launcher.GradleMain.main(GradleMain.java:26)
Caused by: java.lang.ClassNotFoundException: [CLASSNAME REDATCED: depended on object]
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at net.sourceforge.cobertura.instrument.CoberturaClassWriter.getCommonSuperClass(CoberturaClassWriter.java:32)
... 123 more
The up to date checking needs to account for changes in the input ser file (which is re-generated when source changes or the cobertura version changes)
I have a codebase that we recently migrated from maven to gradle. One of the things we noticed is that a file which should have 90%+ coverage now has 20% coverage. Not only that, but the covered lines were nonsensical (in the middle of the a method with no other coverage, etc).
I trimmed it down to the smallest test case I could. I don't think this is the only issue in that file, but it's a start:
public class TestClass {
// comment out this method to fix coverage
public BigDecimal unusedMethod() {
return usedMethod()
}
public BigDecimal usedMethod() {
println 'Definitely reached!'
1.0
}
public void unrelatedMethod() {
println 'Unrelated method also reached'
}
}
Please check out the repo https://github.com/syncsynchalt/cobertura-groovy-gradle-testcase and build with ./gradlew cobertura
. You should see 0% coverage of the file, which should be 75% instead. If you comment out unusedMethod
then it climbs to 100%.
We recently encountered an issue after taking the following steps:
You'll end up with the following issue: cobertura/cobertura#171
As pointed out in this issue's discussion, removing and re-generating the instrumented classes solves the issue.
In order not to use different cobertura versions for instrumentation and at runtime, the instrument task's inputs should include the coberturaVersion
property so that it's not considered up-to-date anymore and re-runs the instrumentation when the cobertura version changes.
Hi, I didn't find a mailing list so I had to raise an issue... sorry.
I am using this but I don't know how to exclude some package from being instrumented.
Please let me know how can I do that.
By the way I tried this and it din't work:
cobertura {
coverageExcludes = ['com.others.*']
}
Thank you.
When users request a report, we start with a fresh .ser file every time to get an accurate report. But tests may be up to date, which means they won't run, and Cobertura will report coverage incorrectly.
If users want a coverage report, we need to force all the tests to no longer be up to date so they will be forced to run so that reports and coverage checks will be accurate.
The plugin should have no effect on a test's up-to-date status when coverage reports are not requested by the user.
I've got a situation where Cobertura seems to be working, but a bunch of errors are generated about not being able to find some classes. Google suggests that the solution is setting the auxiliary classpath to point to the locations of the class files in question. I had hoped that I would set the auxClasspath or auxiliaryClasspath value like so:
cobertura {
coverageFormats = [ "xml" ]
auxiliaryClasspath = project.sourceSets.main.output.classesDir.path + ":" + project.sourceSets.main.compileClasspath.getAsPath()
}
But I've had no luck so far.
Deprecated dynamic property: "auxClasspath" on "net.saliman.gradle.plugin.cobertura.CoberturaExtension_Decorated@65941543"
Deprecated dynamic property: "auxiliaryClasspath" on "net.saliman.gradle.plugin.cobertura.CoberturaExtension_Decorated@2961ae44"
Am I going down the wrong road here?
Thanks.
Put on buildscript classpath.
Using mavenCentral() only.
Could not resolve all dependencies for configuration ':classpath'.
Could not download artifact 'xalan:xalan:2.6.0@jar'
> Artifact 'xalan:xalan:2.6.0@jar' not found.
Hi. I have src/test and src/intTest (integration tests) in the same project. The default test task runs tests in src/test, of course. And I have an intTest task of Type Test that runs on demand integration tests, which happen to be in src/intTest.
Does cobertura run all tasks of Type Test? It appears that way. Is there a way to disable that an specify which tasks it should run in?
Thank you.
code:
buildscript { repositories { mavenCentral() } dependencies { classpath "net.saliman:gradle-cobertura-plugin:1.2.0" } }
error that I get:
Could not resolve all dependencies for configuration ':classpath' Could not find net.saliman:gradle-cobertura-plugin:1.2.0.
The way registerTaskFixupListener at https://github.com/stevesaliman/gradle-cobertura-plugin/blob/master/src/main/groovy/net/saliman/gradle/plugin/cobertura/CoberturaPlugin.groovy#L118 is implemented prevents us from using this plugin as we would like.
First: A sub-module's "test" task DEPENDS on the test tasks of all other modules. This is weird, and should not be. I don't need to test any other module in order to generate a coverage report for one.
Second: I want to be able to generate a coverage report by just making a test depend on the instrumentation setup. The fixup code here means I can ONLY ever generate coverage if I invoke "cobertura", so I cannot do my standard trick of generating coverage for a run of a single test class using -Dtest.single
The plugin setup at https://github.com/eriwen/gradle-cobertura-plugin/blob/master/src/main/groovy/org/gradle/api/plugins/cobertura/CoberturaPlugin.groovy is much better in terms of setup:
The cobertura-configure task modifies the classpath and system properties. This means that if a test task depends on a cobertura task (a decision I can make on the fly), then the setup is performed for that one instance.
The cobertura task has an input serFile and an output serFile, which allows the gradle dependency/skip mechanism to be intelligent about whether cobertura needs rerunning or not.
Unfortunately there's a bug in that serFile handling, else I'd use that plugin. However, the essentially hardcoded task setup in this plugin pretty much prevents me from using it either. The sucky HTML report in JaCoCo annoys me enough that I'm not going to use that.
Of them all, I think your plugin has the greatest potential, and I'd strongly encourage you to look at this issue. Do we send you beers, pizzas or similar?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.