3

I have simply deleted the java class file which was of no use.After building the package in intellij, Jacoco test report showing deleted java class as well. For reference, I have attached sceenshot.

Is there any reference exists even after deleting java class file in intellij. How can I completely resolve this issue? enter image description here

Rony Singh
  • 147
  • 1
  • 10
  • 2
    have you deleted both `*.java` and `*.class` files? have you checked (file system) that **both** file were deleted? (deleting the `*.class` file but building the package will create it again, from `*.java`; but I don't know Jacoco, not sure what is cached) – user85421 Dec 15 '19 at 07:59

2 Answers2

3

Run the clean command for whatever build tool you are using (ant, maven, gradle).

If you only run the jacocoTestReport occasionally, you might want to add a dependency on clean for it, to ensure it always happens before generating the report.

I noticed this same problem when I changed a package name on a class and the old package was still in the report.

What is happening is the report that is created is simply a bunch of files that follow the naming and package convention of the files in your project. So files from a previous run of jacocoTestReport are still sitting in that report folder, even though you have deleted the java file, and rerun jacocoTestReport. If you look in the folder, you will find the timestamp is older on the report file for the deleted class than the others around it. It just needs the clean so that your next run will only contain files related to the current report.

I assume its possible to change where jacocoTestReport will write its report files and if you choose somewhere other than the build directory, you would need to update your clean task to clean up that area too.

Steve H
  • 31
  • 4
0

The same thing happened to me today. It was due to:

  • checking out to a git branch in which a maven module has been deleted
  • the corresponding folder was still here, but it was ignored by git since it only contained ignored files (e.g. .class files inside target/)
  • mvn clean did not clean those files, since the corresponding module was removed from pom.xml
  • Jacoco still found the old compiled classes because it looks for **/classes and **/**.exec, and it doesn't care about .gitignore or pom.xml.

After removing remove the old files, the coverage reported by Jacoco changed.

I used git clean -f -d --dry-run to look for old folders, and removed them with git clean -f -d. Please be careful with this command!

Eric Duminil
  • 52,989
  • 9
  • 71
  • 124