diff-coverage-maven-plugin icon indicating copy to clipboard operation
diff-coverage-maven-plugin copied to clipboard

Build failing

Open slice-imran opened this issue 2 years ago • 7 comments

Hi, this is quite useful plugin but it lacks the documentation. In below lines please specify what does minLines, minBranches and minInstructions means so that we can configure proper values. If I just remove few lines from my code(no new line added) currently build is failing not sure which parameter to adjust to make it work.

<violations> 
    <!-- Default 'false'. Fail build if violation rules weren't met  -->
    <failOnViolation>true</failOnViolation>

    <!-- Sets min coverage rule for: instructions, lines, branches -->
    <minCoverage>0.7</minCoverage>
    
    <!-- Each rule could be configured separately -->
    <!-- Default '0.0'. If value is '0.0' then the rule is disabled -->
    <minLines>0.1</minLines>
    <minBranches>0.7</minBranches>
    <minInstructions>1.0</minInstructions>
</violations>

slice-imran avatar Sep 14 '22 09:09 slice-imran

Hi @slice-imran

The plugin checks only new and modified code.

minLines - lines of code coverage ratio minBranches - branching coverage ratio(e.g. if-else, ?:) minInstructions - java bytecode coverage

Usually, all properties are set to the same value. I don't recommend to set coverage ratio to 1.0 because there are some cases when impossible to cover all code. See https://github.com/jacoco/jacoco/issues/1211

I suggest to set a coverage ration equal to 0.9. Just use:

    <minCoverage>0.9</minCoverage>

instead of

    <minLines>0.9</minLines>
    <minBranches>0.9</minBranches>
    <minInstructions>0.9</minInstructions>

Note: both configurations do the same.

To solve your issue I need more info about the build failure. But first of all you should check by yourself:

  • target/site/diff.patch - the diff that was generated by the plugin. Does it correspond to your code changes?
  • target/site/diffCoverage/html/index.html - diff coverage report in html format

if the html report contains a highlited code that wasn't changed then try mvn clean verify. If it doesn't help then provide please more detailed info please.

SurpSG avatar Sep 14 '22 13:09 SurpSG

Here is the pull plugin setting.

<plugin>
    <groupId>com.github.surpsg</groupId>
    <artifactId>diff-coverage-maven-plugin</artifactId>
    <version>0.3.1</version>
    <configuration>
        <!-- Required. diff content source. only one of file, URL or Git is allowed -->
        <diffSource>
            <git>main</git> <!-- compares current HEAD and all uncommited with this <git> -->
        </diffSource>
        <violations>
            <!-- Default 'false'. Fail build if violation rules weren't met  -->
            <failOnViolation>true</failOnViolation>

            <!-- Sets min coverage rule for: instructions, lines, branches -->
            <minCoverage>0.8</minCoverage>
        </violations>
        <excludes>
            <exclude>**/entity/**</exclude>
            <exclude>src/main/resources</exclude>
        </excludes>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>diffCoverage</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Please note that if I just change the version to 0.2.1 it works like a charm, since I want to exclude some directories I just upgraded to version 0.3.1 and it's failing now. I have made no other changes with it, just version number change and added excludes config.

slice-imran avatar Sep 19 '22 07:09 slice-imran

@slice-imran I still need to know what error you get. Please, provide build log

SurpSG avatar Sep 19 '22 07:09 SurpSG

@slice-imran I still need to know what error you get. Please, provide build log

Getting missing commit, however, this commit is present in main(master) and in my branch also. I can see this commit by doing git show 5eca615ecf561d02daa4e88f4fe0e80a87c672f5 in both the branches.

Missing commit 5eca615ecf561d02daa4e88f4fe0e80a87c672f5 -> [Help 1]
--
81 | org.eclipse.jgit.errors.MissingObjectException: Missing commit 5eca615ecf561d02daa4e88f4fe0e80a87c672f5
82 | at org.eclipse.jgit.internal.storage.file.WindowCursor.open (WindowCursor.java:137)
83 | at org.eclipse.jgit.revwalk.RevWalk.getCachedBytes (RevWalk.java:1130)
84 | at org.eclipse.jgit.revwalk.RevCommit.parseHeaders (RevCommit.java:126)
85 | at org.eclipse.jgit.revwalk.MergeBaseGenerator._next (MergeBaseGenerator.java:121)
86 | at org.eclipse.jgit.revwalk.MergeBaseGenerator.init (MergeBaseGenerator.java:76)
87 | at org.eclipse.jgit.revwalk.StartGenerator.next (StartGenerator.java:72)
88 | at org.eclipse.jgit.revwalk.RevWalk.next (RevWalk.java:612)
89 | at com.form.coverage.diff.git.JgitDiff.obtainDiffEntries (JgitDiff.kt:79)
90 | at com.form.coverage.diff.git.JgitDiff.obtain (JgitDiff.kt:43)
91 | at com.form.coverage.diff.GitDiffSource$diffContent$2.invoke (DiffSource.kt:59)
92 | at com.form.coverage.diff.GitDiffSource$diffContent$2.invoke (DiffSource.kt:53)
93 | at kotlin.SynchronizedLazyImpl.getValue (LazyJVM.kt:74)
94 | at com.form.coverage.diff.GitDiffSource.getDiffContent (DiffSource.kt)
95 | at com.form.coverage.diff.GitDiffSource.saveDiffTo (DiffSource.kt:68)
96 | at com.form.coverage.report.ReportGenerator.saveDiffToDir (ReportGenerator.kt:31)
97 | at com.github.surpsg.DiffCoverageMojo.execute (DiffCoverageMojo.kt:58)
98 | at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
99 | at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
100 | at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
101 | at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
102 | at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
103 | at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
104 | at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
105 | at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
106 | at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
107 | at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
108 | at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
109 | at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
110 | at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
111 | at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
112 | at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
113 | at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
114 | at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
115 | at java.lang.reflect.Method.invoke (Method.java:566)
116 | at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
117 | at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
118 | at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
119 | at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)

slice-imran avatar Sep 19 '22 09:09 slice-imran

I believe the above error is nothing to do with that particular commit id rather the existing report is missing this commit id.

slice-imran avatar Sep 19 '22 13:09 slice-imran

Seems, you don't have main branch locally.

Try refs/remotes/origin/main instead of main.

SurpSG avatar Sep 19 '22 16:09 SurpSG

I tried with refs/remotes/origin/main instead of main and failed again, however, This should not be possible, I just changed the version number and added exclude config. It should not give me the error.

slice-imran avatar Sep 21 '22 07:09 slice-imran