Search code examples
buildcode-coveragegradleemma

Exclude classes from EMMA in Gradle build


I build my project with Gradle 1.0 and I use the EMMA plugin for code coverage info. I would like to exclude certain files from the coverage report.

How can I achieve that?


Solution

  • Are you including this Gradle script? I think you can exclude classes within your instrumentation definition (see example below). However, it doesn't look like you can set the exclude pattern by using a convention property.

    ant.emma(enabled: 'true', verbosity:'info'){
        instr(merge:"true", destdir: emmaInstDir.absolutePath, instrpathref:"run.classpath",
              metadatafile: new File(emmaInstDir, '/metadata.emma').absolutePath) {
            instrpath {
                fileset(dir:sourceSets.main.output.classesDir.absolutePath, includes:"**/*.class", excludes:"**/Some*.class")
            }
        }
    }
    

    If I were you I'd try to fork the plugin, add a new field to EmmaPluginConvention that lets you set the exclude pattern and then use that variable in the instrpath definition. After changing the code and verifying that it works send a pull request to the author. I am sure he will incorporate your change.