While generating test coverage jenkins sends me errors and does not generate the folder or file - maven

I generated this error: coverage results were found using the pattern '**/target/site/cobertura/coverage.xml
here is my pom.xml
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven.plugin</artifactId>
<version>
2.5
</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin </artifactId>
<configuration >
<formats >
<format> xml </format>
<format>html</format>
</formats>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>coverage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
Am I wrong or is the error in the handle part?

A hint:
Could not find goal 'coverage' in plugin org.codehaus.mojo:cobertura-maven-plugin:2.6 among available goals cobertura, instrument, clean, check, help, dump-datafile -> [Help 1]
Use this :
<project>
....
<build>
<finalName>${project.artifactId}-${project.version}-r${buildNumber}</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.6</version>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>cobertura</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>

Related

Can't generate neither javadoc nor sources via maven-plugins?

I want to generate javadoc from my code in Intellij idea IDE.
I'm going step by step by This link. but I don't get the appropriate result.
But after doing mvn package there was no neither attach-source-javadoc-1.0-SNAPSHOT-javadoc.jar nor attach-source-javadoc-1.0-SNAPSHOT-sources.jar files under target folder.
This is the whole pom file:
<?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>
<packaging>war</packaging>
<groupId>gdg</groupId>
<artifactId>dfgdfg</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
...........
</properties>
<dependencies>
...............
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
You have added the plugin to the <pluginManagement> which is not executed.
To generate both javadoc and source code via maven-plugins
You have to put this inside <plugins>directly:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<failOnError>false</failOnError>
</configuration>
</plugin>
</plugins>
</build>

Maven-replacer-plugin is not invoked with maven-war-plugin

I am trying to replace string %APP_NAME% with enviroment variable in jdbc.properties using maven. I have following configuration:
<pluginManagement>
<plugins>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<basedir>${project.build.directory}/classes</basedir>
<includes>
<include>jdbc.properties</include>
</includes>
<replacements>
<replacement>
<token>%APP_NAME%</token>
<value>${env.BRANCH_NAME}</value>
</replacement>
</replacements>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
<executions>
<execution>
<!-- First step is to disable the default-war build step. -->
<id>default-war</id>
<phase>none</phase>
</execution>
<execution>
<!-- Second step is to create an exploded war. Done in prepare-package -->
<id>war-exploded</id>
<phase>prepare-package</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
<execution>
<!-- Last step is to make sure that the war is built in the package
phase -->
<id>custom-war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<!-- <compilerArgument>-Xlint:all</compilerArgument> -->
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
<compilerArguments>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</pluginManagement>
When i invoke:
mvn clean package
or
mvn clean install
the replacer plugin is not called. Can anyone can please explain why and what can I do to let it work? Or if replacer is not compatible with future war plugin can anyone explain me any other way to replace some string in jdbc.properties before building war? I saw also ant plugin but with same config it is not called too.. Example below..
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>deploy-ui</id>
<phase>package</phase>
<inherited>false</inherited>
<configuration>
<tasks>
<replace dir="${basedir}/src/main/resources">
<include name="**/jdbc.properties" />
<replacefilter token="%APP_NAME%" value="${env.BRANCH_NAME}"/>
</replace>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
The plugin is defined in a <pluginManagement> block:
<pluginManagement>
<plugins>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.2</version>
...
Find the <build><plugins> block for the POM where replacer needs to run, and add the following:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
</plugin>
Plugin Management is rather like a template for what should happen when the plugin is invoked. If the plugin is not referenced in the <build><plugins> block, nothing will happen.

Unable to generate PMD Reports in multi-format

I want to generate PMD Reports using maven in .csv and .xml format. I edited my pom.xml as below:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.1</version>
<configuration>
<formats>
<format>csv</format>
<format>xml</format>
</formats>
<rulesets>
<ruleset>../PMD_RuleSet/PMDRules.xml</ruleset>
</rulesets>
</configuration>
</plugin>
Please let me know if I am following the correct configuration.
Thanks
<formats> not exist :
Try:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.1</version>
<configuration>
<rulesets>
<ruleset>../PMD_RuleSet/PMDRules.xml</ruleset>
</rulesets>
</configuration>
</plugin>
Execute : mvn clean pmd:pmd -Dformat=csv
Execute : mvn clean pmd:pmd -Dformat=xml
Try this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.5</version>
<executions>
<execution>
<id>default-pmd</id>
<goals>
<goal>pmd</goal>
</goals>
<configuration>
<format>xml</format>
</configuration>
</execution>
<execution>
<id>format_csv</id>
<goals>
<goal>pmd or check or cpd-check</goal>
</goals>
<configuration>
<format>csv</format>
</configuration>
</execution>
</executions>
</plugin>

Maven Assembly PlugIn with Shade for produce one Jar

i have this problem,
this is my POM build part
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>bin.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>dist</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- SHADE PLUGIN -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>document.readingXLS.GUIReader</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
<!-- START per maven 3.0 -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.0</version>
<dependencies>
<dependency><!-- add support for ssh/scp -->
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
And i produce 1 JAR with dependencies included.
But when i generate a ZIP file with Assembly into the zip. i have 2 JAR (MyProject and POI)
this is my Assembly PART:
<assembly>
<id>dist</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/LibGenerator</outputDirectory>
<includes>
<include>Vas:Generator:jar</include>
<include>org.apache.poi:poi:jar</include>
</includes>
</dependencySet>
</dependencySets>
</assembly>
How i configure it to produce 1 JAR with Assembly plugIn?
Many Thanks.

Maven: Reporting warnings during regular compile, but not for generated sources

We have a Maven project that uses WSDL files that are turned into Java source files and later compiled.
When this project used Ant, we compiled the generated Java source file and the normal developer written Java source files separately. This allowed me to turn on deprecation and warnings on compiling the developer written Java files, but off for compiling the WSDL generated Java files. I want the developers to fix their warnings and deprecations, but I can't hold the developers responsible for code that the WSDLs generated.
Now, we've moved the project over to Maven, and I would like to do the same thing: Compile the WSDL generated Java source code without the warnings and compile the developer written Java source code with the warnings. Is it possible to do with Maven? (I mean without writing it in Ant and embedding that in the pom.xml).
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>com.vegicorp</groupId>
<artifactId>crypto</artifactId>
<packaging>bundle</packaging>
<version>2.0.4</version> <!--package version-->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<axis2.version>1.5.6</axis2.version>
<maven.dir>${project.build.directory}/maven/crypto.jar</maven.dir>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugins</artifactId>
<version>3.3</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<debug>true</debug>
<debugLevel>lines,vars,source</debugLevel>
<compilerArgs>
<arg>-Xlint</arg>
<arg>Xmaxwarns</arg>
<arg>9999</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<version>2.3.7</version>
<configuration>
<archive>
<manifestSections>
<manifestSection>
<name>Build-Information</name>
<manifestEntries>
<Project-Name>${env.JOB_NAME}</Project-Name>
<Build-Number>${env.BUILD_NUMBER}</Build-Number>
<SVN-Revision>${env.SVN_REVISION}</SVN-Revision>
</manifestEntries>
</manifestSection>
<manifestSection>
<name>Module-Information</name>
<manifestEntries>
<Group-ID>${project.groupId}</Group-ID>
<Artifact-ID>${project.artifactId}</Artifact-ID>
<Version>${project.version}</Version>
</manifestEntries>
</manifestSection>
</manifestSections>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>${axis2.version}</version>
<executions>
<execution>
<goals>
<goal>wsdl2code</goal>
</goals>
<configuration>
<packageName>com.safenet.tokenization.wsclient</packageName>
<wsdlFile>src/main/wsdl/SafeNetTokenizer.wsdl</wsdlFile>
<databindingName>adb</databindingName>
<skipBuildXML>true</skipBuildXML>
<syncMode>sync</syncMode>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}</outputDirectory>
<targetSourceFolderLocation>generated-sources</targetSourceFolderLocation>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<xmlOutput>true</xmlOutput>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<reuseFork>true</reuseFork>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.7</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.0.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
</plugin>
</plugins>
</reporting>
<dependencies>
<!-- COMPILE -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
...
</dependencies>
</project>
Okay, I figured out how to do this, but I am not enamored with the solution:
Define two separate maven-compiler-plugin executions. One called default-compile where I compile the WSDL code, and one called main-compile where I compile the rest of the code.
Use <includes/> and <excludes> in the main-compiler-plugin execution configurations to include and exclude the code I want to compile.
I still need the build-helper-maven-plugin to define two separate source.
The default-compile is always executed (I couldn't figure out a way to turn it off) even if I don't have a configuration default-compile. That would automatically compile everything before looking at my two defined maven-compile-plugin plugin executions. To get around this, I named the WSDL compile default-compile.
Here's the mavin-compiler-plugin configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>default-compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<includes>
<include>**/com/safenet/**</include>
</includes>
<excludes>
<exclude>**/com/vegicorp/**</exclude>
</excludes>
<source>1.6</source>
<target>1.6</target>
<showDeprecation>false</showDeprecation>
<showWarnings>false</showWarnings>
<debug>true</debug>
<debugLevel>lines,vars,source</debugLevel>
<verbose>true</verbose>
</configuration>
</execution>
<execution>
<id>main-compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<includes>
<include>**/com/vegicorp/**</include>
</includes>
<excludes>
<exclude>**/com/safenet/**</exclude>
</excludes>
<source>1.6</source>
<target>1.6</target>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<debug>true</debug>
<debugLevel>lines,vars,source</debugLevel>
<compilerArgs>
<arg>-Xlint</arg>
<arg>Xmaxwarns</arg>
<arg>9999</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
</plugin>
I found David W.'s answer very useful. Unfortunately, I could not find an easy way to separate generated-sources for my current project using <includes>/<excludes> (and <testIncludes>/<testExcludes> for default-testCompile), since they appear to be checked against paths relative to compileSourceRoots.
The solution that worked best for me is to specify <compileSourceRoots> for each <execution>:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<compileSourceRoots>
<compileSourceRoot>${project.build.directory}/generated-sources/swagger/src/main/java</compileSourceRoot>
</compileSourceRoots>
<showWarnings>false</showWarnings>
</configuration>
</execution>
<execution>
<id>compile-with-warnings</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<compileSourceRoots>
<compileSourceRoot>${project.build.sourceDirectory}</compileSourceRoot>
</compileSourceRoots>
<showWarnings>true</showWarnings>
<compilerArgs>
<arg>-Xlint:all</arg>
</compilerArgs>
</configuration>
</execution>
<execution>
<id>default-testCompile</id>
<configuration>
<compileSourceRoots>
<compileSourceRoot>${project.build.testSourceDirectory}</compileSourceRoot>
</compileSourceRoots>
<showWarnings>true</showWarnings>
<compilerArgs>
<arg>-Xlint:all</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
</plugin>
This has the advantage of no longer requiring build-helper-maven-plugin (since ${project.compileSourceRoots} is ignored), but the disadvantage that since ${project.compileSourceRoots} is ignored, compileSourceRoot for each generator plugin must be added to an <execution> explicitly or it will not be compiled.

Resources