I use maven-source-plugin to generated java-source. However doing "mvn clean ; mvn package" does not generate a project-sources.jar in the target directory.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
info:
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) # weibo4j ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # weibo4j ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # weibo4j ---
[INFO] Building jar: F:\step-by-step\weibo4j\target\weibo4j-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-source-plugin:2.3:jar-no-fork (attach-sources) # weibo4j ---
[INFO] No sources in project. Archive not created.
If you have your sources in a directory that maven does not consider a source directory -- such as webapp -- your files will not be put in your project-sources.jar.
Solution: signal to maven what your source directory is. Add:
<build>
<sourceDirectory>${basedir}/src/main/webapp</sourceDirectory>
</build>
Related
I'm trying to make my Discord bot to work on Heroku but I keep getting an error. The build process works fine but the bot doesn't go online. I went to Resources --> More --> View Logs and saw an error. I understood the error as some methods not getting recognized and I removed the error one. But another one would just pop up. The code and bot works on local using IntelliJ. Anyone can help me with this please?
The error/Resource logs:
2021-04-18T23:58:17.202220+00:00 app[Worker.1]: location: class Main
2021-04-18T23:58:17.226725+00:00 app[Worker.1]: src/main/java/Main.java:9: error: cannot find symbol
2021-04-18T23:58:17.226770+00:00 app[Worker.1]: jda.setActivity(Activity.listening("!help"));
2021-04-18T23:58:17.226835+00:00 app[Worker.1]: ^
2021-04-18T23:58:17.226906+00:00 app[Worker.1]: symbol: variable Activity
2021-04-18T23:58:17.226942+00:00 app[Worker.1]: location: class Main
2021-04-18T23:58:17.228071+00:00 app[Worker.1]: 5 errors
2021-04-18T23:58:17.230942+00:00 app[Worker.1]: error: compilation failed
2021-04-18T23:58:17.336252+00:00 heroku[Worker.1]: Process exited with status 1
2021-04-18T23:58:17.440163+00:00 heroku[Worker.1]: State changed from up to crashed
Build/Deploy logs:
-----> Building on the Heroku-20 stack
-----> Using buildpack: heroku/java
-----> Java app detected
-----> Installing JDK 15... done
-----> Installing Maven 3.6.2... done
-----> Executing Maven
$ mvn -DskipTests clean dependency:list install
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< org.example:CalciteDiscordBot >--------------------
[INFO] Building CalciteDiscordBot 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # CalciteDiscordBot ---
[INFO] Deleting /tmp/build_6a1072dc/target
[INFO]
[INFO] --- maven-dependency-plugin:2.8:list (default-cli) # CalciteDiscordBot ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # CalciteDiscordBot ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /tmp/build_6a1072dc/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # CalciteDiscordBot ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 21 source files to /tmp/build_6a1072dc/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # CalciteDiscordBot ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /tmp/build_6a1072dc/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # CalciteDiscordBot ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # CalciteDiscordBot ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # CalciteDiscordBot ---
[INFO] Building jar: /tmp/build_6a1072dc/target/CalciteDiscordBot-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # CalciteDiscordBot ---
[INFO] Installing /tmp/build_6a1072dc/target/CalciteDiscordBot-1.0-SNAPSHOT.jar to /tmp/codon/tmp/cache/.m2/repository/org/example/CalciteDiscordBot/1.0-SNAPSHOT/CalciteDiscordBot-1.0-SNAPSHOT.jar
[INFO] Installing /tmp/build_6a1072dc/pom.xml to /tmp/codon/tmp/cache/.m2/repository/org/example/CalciteDiscordBot/1.0-SNAPSHOT/CalciteDiscordBot-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.854 s
[INFO] Finished at: 2021-04-18T23:57:57Z
[INFO] ------------------------------------------------------------------------
-----> Discovering process types
Procfile declares types -> Worker
-----> Compressing...
Done: 76.7M
-----> Launching...
Released v23
https://calcitediscordbot.herokuapp.com/ deployed to Heroku
Main.java
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity;
import javax.security.auth.login.LoginException;
public class Main {
public static void main(String[] args) throws LoginException {
JDABuilder jda = JDABuilder.createDefault("I inserted token here");
jda.setActivity(Activity.listening("!help"));
jda.build();
}
}
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>CalciteDiscordBot</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.target>15</maven.compiler.target>
<maven.compiler.source>15</maven.compiler.source>
</properties>
<dependencies>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>4.2.0_246</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>jcenter</id>
<name>jcenter-bintray</name>
<url>https://jcenter.bintray.com</url>
</repository>
</repositories>
</project>
Procfile:
Worker: java src/main/java/Main.java
If you run locally with an IDE like IntelliJ, it will handle things like this to you, but you need add a plugin to create a jar with dependencies before deploying it.
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>CalciteDiscordBot</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>...</properties>
<dependencies>...</dependencies>
<repositories>...</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>
Main
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
To fix this problem, you'd have to change the pom.xml and Procfile.
Add this line to the pom.xml:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>2.1.0</version>
<configuration>
<assembleDirectory>target</assembleDirectory>
<programs>
<program>
<mainClass>MAIN_CLASS_PATH</mainClass>
<name>BOT_NAME</name>
</program>
</programs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
</plugin>
Add this inside of your plugins tag in your build tag. Change MAIN_CLASS_PATH to your own main class and change BOT_NAME to your project's/bot's name.
Change the Worker for the Procfile to this:
worker: sh target/bin/BOT_NAME
Same thing here ^, change BOT_NAME to your project's/bot's name.
Most credit goes to BooleanCube's Discord. And thank you #Kaneda for the help!
All my tests are located in src/test/java/... with java marked as a test source folder. They are also all named as ***Test so Surefire plugin should be finding them.
However my maven verify fails as all my test coverage is at 0%. I have 20 tests which should cover all of my non-excluded classes and they all pass when I do run them in my IntelliJ. When I run maven test or maven verify my tests aren't being run. I'm not sure why.
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>jacoco-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<excludes>
...
</excludes>
<rules>
<rule>
<element>CLASS</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>80%</minimum>
</limit>
<limit>
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>80%</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
----------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.6:prepare-agent (default-prepare-agent) # *-*-service ---
[INFO] surefireArgLine set to "-javaagent:C:\\Users\\*\\.m2\\repository\\org\\jacoco\\org.jacoco.agent\\0.8.6\\org.jacoco.agent-0.8.6-runtime.jar=destfile=C:\\Users\\*\\OneDrive\\Documents\\IntelliJ Projects\\*-*-service\\*-*-service\\target\\jacoco.exec,append=true"
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) # *-*-service ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # *-*-service ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) # *-*-service ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory C:\Users\*\OneDrive\Documents\IntelliJ Projects\*-*-service\*-*-service\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # *-*-service ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M5:test (default-test) # *-*-service ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[ERROR] Java HotSpot(TM) 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.6:report (report) # *-*-service ---
[INFO] Loading execution data file C:\Users\*\OneDrive\Documents\IntelliJ Projects\*-*-service\*-*-service\target\jacoco.exec
[INFO] Analyzed bundle '*-*-service' with 19 classes
[INFO]
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) # *-*-service ---
[INFO]
[INFO] --- spring-boot-maven-plugin:2.4.4:repackage (repackage) # *-*-service ---
[INFO] Replacing main artifact with repackaged archive
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.6:report (default-report) # *-*-service ---
[INFO] Loading execution data file C:\Users\*\OneDrive\Documents\IntelliJ Projects\*-*-service\*-*-service\target\jacoco.exec
[INFO] Analyzed bundle '*-*-service' with 19 classes
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.6:check (jacoco-check) # *-*-service ---
[INFO] Loading execution data file C:\Users\*\OneDrive\Documents\IntelliJ Projects\*-*-service\*-*-service\target\jacoco.exec
[INFO] Analyzed bundle '*-*-service' with 6 classes
[WARNING] Rule violated for class com.*.**.mapper.*Mapper: lines covered ratio is 0.00, but expected minimum is 0.80
[WARNING] Rule violated for class com.*.**.mapper.*Mapper: branches covered ratio is 0.00, but expected minimum is 0.80
[WARNING] Rule violated for class com.*.**.mapper.*Mapper: lines covered ratio is 0.00, but expected minimum is 0.80
[WARNING] Rule violated for class com.*.**.controller.*Controller: lines covered ratio is 0.00, but expected minimum is 0.80
[WARNING] Rule violated for class com.*.**.controller.*Controller: lines covered ratio is 0.00, but expected minimum is 0.80
[WARNING] Rule violated for class com.*.**.service.*Service: lines covered ratio is 0.00, but expected minimum is 0.80
[WARNING] Rule violated for class com.*.**.service.*Service: lines covered ratio is 0.00, but expected minimum is 0.80
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.388 s
[INFO] Finished at: 2021-04-11T19:48:54+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.6:check (jacoco-check) on project *-*-service: Coverage checks have not been met. See log for details. -> [Help 1]
I am using IntelliJ-IDEA ultimate version 2021.1 (Latest at post date )
Any help on getting my tests recognised in a full maven build would be greatly appreciated. Thanks
Please read the log, and check [ERROR].
You are using JDK 13 and some POM added -Xverify:none and -noverify in the configuration parameter argLine.
I am having trouble getting JUnit 5 tests to run on VSCODE. I believe my environment is set up properly. A clone of junit5-samples | junit5-jupiter-starter-maven builds and runs as expected. My project does not.
My project builds under maven but runs no tests. So this is probably a Maven or project configuration issue and not related to VSCODE.
I have tinkered with various ideas for a couple of hours to no avail. Something is different, probably a mistake and maybe additional pairs of eyes can find it. Any help you might provide will be greatly appreciated.
Here is some project information
'mvn clean package' runs without error, but no tests run. CodeLens is also not working.
Run Test|Debug Test is missing. No tests show up in test runner.
Here is my POM file with a few redactions:
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>com.redacted</groupId>
<artifactId>redacted</artifactId>
<packaging>jar</packaging>
<version>0.1.1</version>
<name>redacted</name>
<properties>
<skipTests>false</skipTests>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
<junit.jupiter.version>5.6.2</junit.jupiter.version>
</properties>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<!-- <skipTests>${skipTests}</skipTests> -->
</configuration>
</plugin>
<!-- <plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
</plugin> -->
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.3.6</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/WSDL/redacted.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Here is the output from the mvn command:
[INFO]
[INFO] ------------------------< com.redacted:redactedClient >-------------------------
[INFO] Building redactedClient 0.1.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # redactedClient ---
[INFO] Deleting D:\repos\redacted\redactedClient\target
[INFO]
[INFO] --- cxf-codegen-plugin:3.3.6:wsdl2java (generate-sources) # redactedClient ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # redactedClient ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\repos\redacted\redactedClient\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # redactedClient ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 6 source files to D:\repos\redacted\redactedClient\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # redactedClient ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\repos\redacted\redactedClient\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # redactedClient ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\repos\redacted\redactedClient\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) # redactedClient ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.444 s
[INFO] Finished at: 2020-04-26T09:55:55-07:00
[INFO] ------------------------------------------------------------------------
A test method should have the return type void whereas your test method GetModList() has Boolean.
In JUnit Jupiter you can remove public from the test class also from all test methods.
It's relativly simple:
I have a plugin goal tomcat7:run which i run directly in Eclipse m2e (the full command would be mvn tomcat7:run). But it runs too early (on process-classes it think), skipping the test phase. I want it to run after the test phase when invoked via cli.
I tried to simply change default-cli phase to be package instead of process-classes, but this doesn't work (phase does not change to package):
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
...
</configuration>
<executions>
<!-- Change phase, doesn't seem to change anything -->
<execution>
<id>default-cli</id>
<goals>
<goal>run</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
Running a default phase like mvn package and this execution
<execution>
<id>default-run</id>
<phase>package</phase>
</execution>
instead works but is not an option, because i don't want to execute this when creating a real package (this plugin starts up an embedded tomcat server). I'm considering profiles, but i think profiles where not made for this kind of problem.
Relevant log:
[INFO] >>> tomcat7-maven-plugin:2.3-SNAPSHOT:run (default-cli) > process-classes # gmm >>>
[INFO]
[INFO] --- frontend-maven-plugin:0.0.26:gulp (gulp build) # gmm ---
...
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # gmm ---
...
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # gmm ---
...
[INFO]
[INFO] <<< tomcat7-maven-plugin:2.3-SNAPSHOT:run (default-cli) < process-classes # gmm <<<
[INFO]
[INFO] --- tomcat7-maven-plugin:2.3-SNAPSHOT:run (default-cli) # gmm ---
... (tomcat7:run log output here) ...
I have to get the code coverage of a application while business test are executed from a different code base.
I use: Maven as my build
Jbehave as my testing framework.
The test are written in java.
My application is a set of war files deployed on tomcat.
The application code base is separate from test code base.
In getting the coverage I followed the below steps.
1 Compile the test code using maven.
2 Copy application classes from the place it was build (${app.code.dir}/target/classes) to ${test.code.dir}/target/classes
[3] Run the tests and jacoco report through maven
The mvn build: I have kept
<profile>
<id>coverage</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.3.201306030806</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<phase>process-resources</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<skip>false</skip>
<destFile>${basedir}/target/jacoco-coverage.exec</destFile>
</configuration>
</execution>
<execution>
<id>default-report</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- <skip>true</skip> -->
<excludes>
<exclude>com/mytest/bdt/**</exclude><!-- test classes -->
<exclude>com/mytest/bdd/**</exclude><!-- test classes -->
</excludes>
<dataFile>${basedir}/target/jacoco-coverage.exec</dataFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
The jbehave test are executed using :
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<version>${jbehave.core.version}</version>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>unpack-view-resources</id>
<phase>process-resources</phase>
<goals>
<goal>unpack-view-resources</goal>
</goals>
</execution>
<execution>
<id>embeddable-stories</id>
<phase>test</phase>
<configuration>
<includes>
<include>${embeddables5}</include><!-- TestSuite.java -->
</includes>
<excludes />
<ignoreFailureInStories>true</ignoreFailureInStories>
<ignoreFailureInView>true</ignoreFailureInView>
<threads>1</threads>
<metaFilters>
<metaFilter>${meta.filter}</metaFilter>
<metaFilter>-skip *</metaFilter>
<metaFilter>+run</metaFilter>
</metaFilters>
</configuration>
<goals>
<goal>run-stories-as-embeddables</goal>
</goals>
</execution>
</executions>
</plugin>
When I execute mvn mvn install -Pcoverage
The execution goes as follows.
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) # test-bdd-testsuite ---
[INFO] --- jbehave-maven-plugin:3.7.5:unpack-view-resources (unpack-view-resources) # test-bdd-testsuite ---
[INFO] --- jacoco-maven-plugin:0.6.3.201306030806:prepare-agent (default-prepare-agent) # test-bdd-testsuite ---
[INFO] argLine set to -javaagent:/home/testUser/.m2/repository/org/jacoco/org.jacoco.agent/0.6.3.201306030806/org.jacoco.agent-0.6.3.201306030806-runtime.jar=destfile=/home/testUser/testProj/trunk/target/jacoco-coverage.exec
[INFO]
[INFO] --- maven-compiler-plugin:2.1:compile (default-compile) # test-bdd-testsuite ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) # test-bdd-testsuite ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/testUser/testProj/trunk/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.1:testCompile (default-testCompile) # test-bdd-testsuite ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) # test-bdd-testsuite ---
[INFO] No tests to run.
[INFO] Surefire report directory: /home/testUser/testProj/trunk/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- jbehave-maven-plugin:3.7.5:run-stories-as-embeddables (embeddable-stories) # test-bdd-testsuite ---
[INFO] Running stories as embeddables using embedder Embedder[ .....
.....
.....
Test execution log comes here .......
.....
.....
[INFO] Reports view generated with 1 stories (of which 0 pending) containing 25 scenarios (of which 0 pending)
[INFO] Meta filters excluded 0 stories and 24 scenarios
[WARNING] Failures in reports view: 0 scenarios failed
[INFO]
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) # test-bdd-testsuite ---
[INFO] Building jar: /home/testUser/testProj/trunk/target/test-bdd-testsuite-1.0.jar
[INFO]
[INFO] --- jacoco-maven-plugin:0.6.3.201306030806:report (default-report) # test-bdd-testsuite ---
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install (default-install) # test-bdd-testsuite ---
[INFO] Installing /home/testUser/testProj/trunk/target/test-bdd-testsuite-1.0.jar to /home/testUser/.m2/repository/com/testCode/bdd/test-bdd-testsuite/1.0/test-bdd-testsuite-1.0.jar
[INFO] Installing /home/testUser/testProj/trunk/pom.xml to /home/testUser/.m2/repository/com/testCode/bdd/test-bdd-testsuite/1.0/test-bdd-testsuite-1.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21.134s
[INFO] Finished at: Tue Nov 26 19:18:28 IST 2013
[INFO] Final Memory: 14M/309M
[INFO] ------------------------------------------------------------------------
With this I get a coverage report generated with the application packages. But the coverage is shown as 0%
In the session link the application classes are not loaded.
Screenshots:
Can some one help me here?
I was able to resolve this as follows
Copy the application classes in to a instrumentation folder.
Start the app server (tomcat in mycase) with Java arguments
-javaagent:$WORKSPACE/target/lib/jacoco-agent-0.6.3.2.jar=includes=*,destfile=$TOMCAT_HOME/jacoco-coverage.exec,append=false
(I had the jacoco-agent jar copied in to my project at the layout)
Execute the tests (this can be automated or manual)
Stop the tomcat server (jacoco-coverage.exec is updated at this point)
Execute ant report target. pointing the updated jacoco-coverage.exec and copied application class folder.
Reference: http://car-online.fr/en/blog/fabien_duchene/2013-05-03-Java%20Code%20Coverage%20in%20Tomcat%20JSP%20applications,%20e.g.,%20WebGoat%20with%20Jacoco/
Thanks #jens-schauder for pointing me to post this as the answer.