On Tuesday, March 12, 2019 at 5:57:05 PM UTC+1, [email protected] wrote: > > I currently have a Maven project with /src/main/java which includes all of > my project source and /src/test/java with my tests. > > My POM uses jacoco-maven-plugin and is currently setup with prepare-agent > and report goals. > > Right now Jacoco works perfect giving me all detail line numbers and > source code highlighting where code was not covered. > > I'm curious can Jacoco do code coverage at all and do it at this level of > detail if /src/main/java did not exist and only the built files(eg JAR and > classes) existed in /target? > > Appreciate any insight. Reading the below link seems to indicate this is > possible just not seeing how everything should be setup and configured at > the project level. > https://www.eclemma.org/jacoco/trunk/doc/maven.html >
"report" goal of jacoco-maven-plugin stricly requires only exec file ( https://www.jacoco.org/jacoco/trunk/doc/report-mojo.html#dataFile ) and class files ( "project.build.outputDirectory" which is typically "target/classes" ) and doesn't strictly require presence of source files As a proof consider following example given src/main/java/Example.java class Example { } given src/test/java/ExampleTest.java public class ExampleTest { @org.junit.Test public void test() { new Example(); } } and given pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.example</groupId> <artifactId>example</artifactId> <version>1.0-SNAPSHOT</version> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.3</version> </plugin> </plugins> </build> </project> Execution of mvn jacoco:prepare-agent test without creation of report, will compile classes, execute tests and create exec-file target/jacoco.exec After removal of sources rm -rf src Execution of mvn jacoco:report will generate following report even in absence of source files [image: report.png] If maven plugin is not flexible enough for your use case, please consider usage of JaCoCo Ant Tasks ( https://www.jacoco.org/jacoco/trunk/doc/ant.html ) , e.g. via maven-antrun-plugin or JaCoCo Command Line Interface ( https://www.jacoco.org/jacoco/trunk/doc/cli.html ) Regards, Evgeny -- You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/fc6cae32-1222-4ef3-8722-125edffeeec8%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
