I'm using this in my pom in the reporting section:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.7.1</version>
<configuration>
<rulesets>
<ruleset>http://serverxxx/pmd-java.xml</ruleset>
</rulesets>
<targetJdk>1.6</targetJdk>
</configuration>
</plugin>
somehow it doesn't work. When I use the rules directly instead of a custom ruleset via http it work fine. I use pmd:pmd and the section is also in the build section of the pom...
Logs:
16:11:05 [INFO] --- maven-pmd-plugin:2.7.1:cpd (default-cli) # online-news ---
16:11:05 mojoSucceeded org.apache.maven.plugins:maven-pmd-plugin:2.7.1(default-cli)
16:11:05 [DRY] Finding all files that match the pattern cpd.xml
16:11:05 [DRY] Parsing 1 files in D:\build\hudson\jobs\xxx migration-maven-3 CI\workspace\migration-maven-3\application\online-modules\online-news\target
16:11:06 [DRY] Successfully parsed file D:\build\hudson\jobs\xxx migration-maven-3 CI\workspace\migration-maven-3\application\online-modules\online-news\target\cpd.xml of module News with 31 warnings.
16:11:06 [DRY] Computing warning deltas based on reference build #13
16:11:06 mojoStarted org.codehaus.mojo:findbugs-maven-plugin:2.5.2(default-cli)
Related
I have a scala project configured with maven surefire plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
When I run all the tests and generates the test report, I found the following information on the index page:
Surefire Report
Summary
[Summary] [Package List] [Test Cases]
Tests Errors Failures Skipped Success Rate Time
0 0 0 0 0% 0
It appears that all scalatest result under test-results/scalatest are ignored! How could this happen? This will never happen to gradle test report.
I just found out that scalatest was not designed to work with either maven-surefire-plugin or maven-surefire-report-plugin, it has to generate its own test report in html format:
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<reportsDirectory>${project.build.directory}/test-results/scalatest</reportsDirectory>
<junitxml>.</junitxml>
<htmlreporters>${project.build.directory}/site/scalatest</htmlreporters>
...
case closed.
My requirement is that I have to generate the springboot server code from a swagger definition. I have generated the code with the help of below-mentioned command (by using swagger-codegen-cli-2.3.1.jar).
java -jar swagger-codegen-cli-2.3.1.jar generate ^
-i nycemoves.yml ^
--api-package com.nyce.moves.api ^
--model-package com.nyce.moves.model ^
--invoker-package com.nyce.moves.invoker ^
--group-id com.nyce.moves ^
--artifact-id nyce-moves ^
--artifact-version 0.0.1-SNAPSHOT ^
-l spring ^
--library spring-boot ^
-o nyce-moves
Now, we have updated the swagger definition and want to re-generate the resulting models and api-invokers, for this we would like to use a maven plugin.
After looking through various answers on the internet, we came across the following build plugins which we have added in our pom.xml.
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>src/main/resources/nycemoves.yml</inputSpec>
<language>spring</language>
<basePackage>${default.package}</basePackage>
<modelPackage>${default.package}.model</modelPackage>
<apiPackage>${default.package}.api</apiPackage>
<invokerPackage>${default.package}.invoker</invokerPackage>
<configOptions>
<interfaceOnly>true</interfaceOnly>
<dateLibrary>java8</dateLibrary>
<java8>true</java8>
<library>spring-boot</library>
<serializableModel>true</serializableModel>
<sourceFolder>src/main/java</sourceFolder>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Now, when we do mvn clean package, we want it to update / override all the models, api and invokers. But, this is not working. We are seeing the below mentioned exception.
[INFO] 16 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.516 s
[INFO] Finished at: 2019-03-06T15:05:58+05:30
[INFO] Final Memory: 34M/448M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project nyce-moves: Compilation failure: Compilation failure:
[ERROR] /nyce-moves/src/main/java/com/nyce/moves/api/CommentsApi.java:[29,8] duplicate class: com.nyce.moves.api.CommentsApi
[ERROR] /nyce-moves/target/generated-sources/swagger/src/main/java/com/nyce/moves/model/PostRequest.java:[19,8] duplicate class: com.nyce.moves.model.PostRequest
...
So, we actually need the plugin to do the following things, but we are not able to figure it out.
a) When we run mvn clean package it should regenerate all the source-code for the server stub in source folder as well as target folder.
b) In case of the class already exists, it should override them. We would like to handle the override later with the help of .swagger-codegen-ignore.
I know there are lots of discussion threads on this on stackoverflow, but I could not find any solution which can help me here. Please help me on this or direct me to the relevant thread.
I had the same problem and I needed to define also the output directory. Here is a snippet:
<configuration>
<language>spring</language>
<library>spring-cloud</library>
<configOptions>
<sourceFolder>swagger</sourceFolder>
<interfaceOnly>true</interfaceOnly>
<dateLibrary>java8</dateLibrary>
</configOptions>
<output>${project.build.directory}/generated-sources</output>
</configuration>
I'm running Jacoco as an agent to surefire
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<argLine>${jacoco.agent.argLine}</argLine>
</configuration>
</plugin>
I'm configuring Jacoco with a large list of exclusions (constants and my deprecated classes) for my build-breaker.
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<configuration>
<excludes>
<exclude>*/*Test</exclude>
<exclude>*/*Constants*</exclude>
<exclude>${jacoco.exclusions.list}</exclude>
</excludes>
</configuration>
What I'm getting is that when I go to run the tests I get the error:
T E S T S
-------------------------------------------------------
The command line is too long.
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
Is there another way to pass the exclusions list to Jacoco than on the agent parameter arglist on the command line? (Looking at the code it doesn't look like it)
My question is: How to pass the list of exclusions to the Jacoco agent running in surefire other than on the command line?
As of today JaCoCo Java Agent doesn't allow reading of options from files.
However you can specify agent via environment variable JAVA_TOOL_OPTIONS, which supposed to have bigger size limit than command line.
Also JaCoCo in offline mode (without agent) allows to provide configuration via file jacoco-agent.properties.
SonarQube is reporting the following for my project.
Unit Tests Coverage 0.0%; Line Coverage 0.0%; Condition Coverage 0.0%
It is not able to find the reports which was created immediately before the Sonar scan. I am using Jenkins to launch the SonarQube scan. In fact in the console output I can see the unit tests being executed and the reports saved in the surefire directory.
Below are the relevant logs from the console output.
[INFO] --- maven-surefire-plugin:2.12:test (default-test) # earn-promotional-domain ---
[INFO] Surefire report directory: /var/jenkins/workspace/earn/surefire-reports
[INFO] [13:50:20.807] Sensor SurefireSensor
[INFO] [13:50:20.807] parsing /var/jenkins/workspace/earn/surefire-reports
[ERROR] [13:50:20.808] Reports path not found or is not a directory: /var/jenkins/workspace/earn/surefire-reports
[INFO] [13:50:20.808] Sensor SurefireSensor (done) | time=1ms
[INFO] [13:50:20.808] Sensor CoberturaSensor
[INFO] [13:50:20.808] parsing /var/jenkins/workspace/earn/site/cobertura/coverage.xml
I am using SonarQube 5.1.2. Please let me know if any other information is needed that will help to figure out the problem.
You are better off with Jacoco than cobertura. Cobertura has lot of open bugs yet to be addressed.
Also Jacoco provides a aggregator plugin which will aggregate the coverage from all child modules and display a comprehensive coverage.
Jacoco also doesnt require any additional plugin for SonarQube.
Here's a good example of implementing Jacoco:
http://www.petrikainulainen.net/programming/maven/creating-code-coverage-reports-for-unit-and-integration-tests-with-the-jacoco-maven-plugin/
If you prefer to stick with Cobertura rather than moving to Jacoco, you can try this alternative to cobertura maven plugin:
https://github.com/QualInsight/qualinsight-mojo-cobertura
Here are some advantages this mojo provides:
it runs tests once (instead of twice with cobertura-maven-plugin)
it allows you to split coverage (UT / IT / Overall)
you get rid of the "obsolete" Cobertura plugin for SonarQube
The documentation on the project's page explains how to add converted reports to SonarQube.
As #Jeel said, you can use an alternative plugin. But if you necessarily must use the cobertura plugin, you can modify it a little bit.
If I understand correctly, the cobertura:check goal forks a current lifecycle, merges a plugin specific configuration (cobertura-maven-plugin-X.X.jar\META-INF\maven\lifecycle.xml) and executes a forked lifecycle to the test phase. After that "check" mojo is executed.
To make cobertura not to fork a lifecycle you can comment <executePhase> tag in a plugin descriptor (cobertura-maven-plugin-X.X.jar\META-INF\maven\plugin.xml) for the check goal.
Additionaly, you have to copy the configuration from lifecycle.xml to your build configuration. For version 2.7 there is only surefire configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<configuration>
<classesDirectory>${project.build.directory}/generated-classes/cobertura</classesDirectory>
<testFailureIgnore>false</testFailureIgnore>
</configuration>
</plugin>
(possibly extending a default lifecycle using components.xml would also work).
In the last step you have to add an execution for the "instrument" goal in the "process-class" phase because it doesn't have a default phase in a plugin descriptor.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${cobertura.version}</version>
<executions>
<execution>
<id>instrument-classes</id>
<phase>process-classes</phase>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>check-coverage</id>
<goals>
<goal>clean</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
i'm new to maven; I need to compile and packaging 2 war file in two different directory even if the source are the same (change only the web.xml file).
try to explain better:
directory structure of LT:
<DIR> LT1_war
<DIR> LT_war
pom.xml
a part of the pom is:
<modules>
<module>LT_war</module>
<module>LT1_war</module>
</modules>
inside the folder LT_war there is a pom and src-->main-->java
resources
webapp
this compile successful and also i packaging in a war LT_war (to deploy to tomcat)
I need a way in order to compile inside the directory LT1_war (using the source that are in the LT_war directory) and packaging using the webapp inside the LT_war directory (just changing the web.xml file)
I've try to write the pom inside the directory LT1_war but when i lunch mvn packaging it tell me:
[INFO] lt ................................................ SUCCESS [3.995s]
[INFO] LT ................................................ SUCCESS [1:12.629s]
[INFO] LT1 ............................................... FAILURE [41.367s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:59.716s
[INFO] Finished at: Tue Jul 08 23:50:43 CEST 2014
[INFO] Final Memory: 20M/200M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.0:war (default-war) on project LT1: Error assembling WAR: Deployment descriptor: D:\attivi
taTomcat7\LT\LT1_war\target\LT1\WEB-INF\web.xml does not exist. -> [Help 1]:
this is a part of the pom file inside LT1_war:
<build>
<finalName>LT1</finalName>
<resources>
<resource>
<directory>../LT_war/src/</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
<configuration>
<excludes>**/.svn/**</excludes>
</configuration>
<executions>
<execution>
<id>exploded</id>
<phase>prepare-package</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
<execution>
<id>war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
There is a few things that I kindly consider terribly wrong with what you're doing:
A Maven project should never access files that are outside of its own module's folder. So LT1 please stay out of LT's folder!
Try to keep WAR projects small if you can. Modularize your code anyway, and make the WAR just depend on JAR files that contain the actual meat
One WAR file "borrowing" stuff from the other WAR might then be better fixed by having both WAR files depend on the code that you moved into such JAR file(s)
Stop using Java 5 if you reasonably can; it's been EOL since 2009. Also, consider moving your source/target levels to the parent project, so you don't redefine the same, yet have a consistent Java version
Talking about old versions, how come you even still have .svn folders that you need to exclude (for a while now there's only a .svn folder in the root of your Subversion work space, that wouldn't affect the Maven WAR plugin)
So your project structure could look like this:
ROOT
MEAT (packaging JAR, where your classes live)
LT (packaging WAR, depends on MEAT)
LT1 (packaging WAR, depends on MEAT, and stays the heck out of LT)
Addition (forgotten some aspect, as pointed out in comment)...
While MEAT is of packaging JAR, you want it to also include stuff that you had going into webapp without it ending up on the classpath. Provided you're using a fairly recent servlet-api, this can be achieved by giving MEAT a resources folder as follows:
src/main/resources/META-INF/resources/...
E.g. .../META-INF/resources/flower.jpeg will appear in the deployed WAR as <context root>/flower.jpg (instead of it just being added to the Java class path).
I need a way in order to compile inside the directory LT1_war (using the source that are in the LT_war directory) and packaging using the webapp inside the LT_war directory (just changing the web.xml file)
Generally, you compile from the root. It's not convenient to do what you're asking to do but it can be done by using the --also-make command line option.