Build an executable Jar from a Maven Project with dependencies with Shade or Maven Assembly Plugin - maven

I am trying to create an executable jar with dependencies packaged. So far I have been receiving the "no main manifest attribute". Does anyone knows what I am doing wrong?
In the top of the POM I have added the packaging jar
<groupId>com.moga</groupId>
<artifactId>capacityplanfacilities</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
Here is my 2 tested approaches (Maven Shade and Apache Maven Assembly) according to the documentation:
Maven Shade
<build>
<!-- <sourceDirectory>${basedir}/src/main/java</sourceDirectory>-->
<!-- <testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>-->
<outputDirectory>${basedir}/target/classes</outputDirectory>
<!-- Do not work for when running tests-->
<!-- <testOutputDirectory>${basedir}/target/test-classes</testOutputDirectory>-->
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.moga.planning.problem.CapacityPlanningApp</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<!-- As per Junit5 Doc https://junit.org/junit5/docs/current/user-guide/#running-tests-build-maven-engines-configure-->
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<!-- End Junit5-->
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Test 2.2 Apache Maven Assembly plugin
<build>
<!-- <sourceDirectory>${basedir}/src/main/java</sourceDirectory>-->
<!-- <testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>-->
<outputDirectory>${basedir}/target/classes</outputDirectory>
<!-- Do not work for when running tests-->
<!-- <testOutputDirectory>${basedir}/target/test-classes</testOutputDirectory>-->
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<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>com.moga.planning.problem.CapacityPlanningApp</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<!-- As per Junit5 Doc https://junit.org/junit5/docs/current/user-guide/#running-tests-build-maven-engines-configure-->
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<!-- End Junit5-->
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
Many thanks

The issue was solving by modyfying the path of the manifest. I tested the built in generation of the Manifest file in the Intellij and discovered that the issue was probably related to the location of the Manifest, I was addying to the same level as the pom, whereas intellij set in the java folder.

Related

VScode maven not executing plugins

I am trying to get my library uploaded to the maven central repository using VScode. In order to meet the requierments for that, I have a bunch of plugins configured in my pom.xml file.
Here are all the plugins:
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
However when I go through the entire maven lifecycle using the VScode maven plugin, no source or javadoc jars are created, and nothing is signed using gpg, what is the issue here?
I guess you put the whole section into <pluginManagement>, right?
Then it is just a configuration and will not be run.
Move it out of <pluginManagement> and it will run as expected.

Maven-dependency-plugin (unpack-dependencies) ignores configuration

The following problem occurred:
There is a dependency in the project. The dependency contains .js and .css files (essentially they will be used as resources). I need to extract and put these files in a certain place. I thought to use maven-dependency-plugin for this, but it does not use the configuration I specified (use defaults). Please tell me where I could be wrong.
pom.xml:
<dependencies>
<dependency>
<groupId>my.group.Id</groupId>
<artifactId>my-artifact-id</artifactId>
<version>my_version</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>unpack</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeScope>runtime</includeScope>
<includeGroupIds>my.group.Id</includeGroupIds>
<includeArtifactIds>my-artifact-id</includeArtifactIds>
<includes>**/*.js,**/*.css</includes>
<outputDirectory>${project.basedir}/my/path</outputDirectory>
<overwriteReleases>true</overwriteReleases>
<overwriteSnapshots>true</overwriteSnapshots>
<overwriteIfNewer>true</overwrteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
You are declaring your plugin execution inside a <pluginManagement> section. This section is great for putting configuration in one place and reusing it later, but it won't execute your plugin.
Try this:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId> <!-- your example contained a typo. -->
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>unpack</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeScope>runtime</includeScope>
<includeGroupIds>commons-lang</includeGroupIds>
<includeArtifactIds>commons-lang</includeArtifactIds>
<includes>**/*.js,**/*.css</includes>
<outputDirectory>${project.basedir}/my/path</outputDirectory>
<overwriteReleases>true</overwriteReleases>
<overwriteSnapshots>true</overwriteSnapshots>
<overwriteIfNewer>true</overwriteIfNewer> <!-- Typo in your POM here as well -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
</plugins>
</build>

Cannot run tests with build-helper-maven-plugin on a groovy project

I have a groovy project in Eclipse. I have to change from Gradle to Maven and now I cannot run the tests that exist in it.
Here is the structure of the project:
Here are the contents of the pom.xml:
<dependencies>
...
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.0-groovy-2.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<compilerArguments>
<indy />
<!-- optional; supported by batch 2.4.12-04+ -->
...
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.12</version>
<executions>
<execution>
<id>add-source</id>
...
</execution>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/groovy</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
However, if I do a mvn clean install, the tests are not being ran.
Here is the output of the console:
The test cases we have are called Spec and not Test, this is fixed like this:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<includes>
<include>**/*Spec.class</include>
</includes>
</configuration>
</plugin>

Checker framework cant resolve symbol<annotatedJdk>${org.checkerframework:jdk8:jar}</annotatedJdk> issue

Im trying to add Checker Framework via Maven repository i followed checker framework manual steps but i got this error on intelij ide
someone else mentioned having same issue on Google groups please any help is appreciated
my maven package is like this
<properties>
<annotatedJdk>${org.checkerframework:jdk8:jar}</annotatedJdk>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>jdk8</artifactId>
<version>2.5.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArguments>
<Xmaxerrs>10000</Xmaxerrs>
<Xmaxwarns>10000</Xmaxwarns>
</compilerArguments>
<annotationProcessorPaths>
<path>
<groupId>org.checkerframework</groupId>
<artifactId>checker</artifactId>
<version>2.5.1</version>
</path>
</annotationProcessorPaths>
<annotationProcessors><annotationProcessor>org.checkerframework.checker.nullness.NullnessChecker</annotationProcessor>
</annotationProcessors>
<compilerArgs>
<arg>-AprintErrorStack</arg>
<arg>-Xbootclasspath/p:${annotatedJdk}</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>properties</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
tell me if miss any steps it also does not allow deleting that line with error
Assuming that the project is built by Maven from command line correctly, this looks like IntelliJ IDEA highlighting issue: IDEA-129269/IDEA-187553.
The way I was able to avoid this issue is to declare the properties as follows:
<checkerframework.version>2.5.6</checkerframework.version>
<annotatedJdk>${settings.localRepository}/org/checkerframework/jdk8/${checkerframework.version}/jdk8-${checkerframework.version}.jar</annotatedJdk>
Then re-import the Maven project.
Also note that with this it may not be necessary to configure the maven-dependency-plugin either.

cobertura-maven-plugin conflicts with FindBugs

After updating cobertura-maven-plugin from 2.6 to 2.7 Cobertura plugin conflicts with FindBugs plugin. FindBugs plugin detects error in cobertura-instrumented code:
[INFO] Incorrect lazy initialization of static field pl.chilldev.sites.commons.ErrorCode.__cobertura_counters in pl.chilldev.sites.commons.ErrorCode.__cobertura_init() [pl.chilldev.sites.commons.ErrorCode] In ErrorCode.java
(everything works fine when Cobertura plugin verison is set to 2.6)
Just in case, FindBugs plugin version is 3.0.1.
Is it possible to set these plugins somehow to work together?
Edit 1 (pom.xml)
This is pom.xml of main project directory (sub-modules contain only dependencies list):
<?xml version="1.0" encoding="utf-8"?>
<!--
# This file is part of the pl.chilldev.sites.
#
# #copyright 2015 © by Rafał Wrzeszcz - Wrzasq.pl.
-->
<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>
<!-- core project settings -->
<groupId>pl.chilldev.sites</groupId>
<artifactId>sites</artifactId>
<packaging>pom</packaging>
<version>0.0.1-SNAPSHOT</version>
<!-- project meta info -->
<name>ChillDev-Sites</name>
<url><!-- TODO --></url>
<description>Content sites storage service.</description>
<inceptionYear>2015</inceptionYear>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<organization>
<name>Rafał Wrzeszcz - Wrzasq.pl</name>
<url>http://wrzasq.pl/</url>
</organization>
<!-- plugins configuration -->
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<url>${project.url}</url>
<Specification-Title>${project.name}</Specification-Title>
<Specification-Version>${project.version}</Specification-Version>
<Specification-Vendor>Rafał Wrzeszcz - Wrzasq.pl; Chillout Development</Specification-Vendor>
<Implementation-Title>${project.name}</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
<Implementation-Vendor>Rafał Wrzeszcz - Wrzasq.pl; Chillout Development</Implementation-Vendor>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArgs>
<arg>-Xlint:all</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<escapeString>\</escapeString>
</configuration>
<executions>
<execution>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.4</version>
<executions>
<execution>
<goals>
<goal>check</goal>
<goal>cpd-check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.15</version>
<dependencies>
<!-- Maven Checkstyle plugin has a 6.1.1 version by default which is buggy -->
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>6.5</version>
</dependency>
</dependencies>
<configuration>
<configLocation>src/main/checkstyle/checkstyle.xml</configLocation>
<propertyExpansion>checkstyle.project.basedir=${project.basedir}</propertyExpansion>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.4</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-module-markdown</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>lt.velykis.maven.skins</groupId>
<artifactId>reflow-velocity-tools</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pdf-plugin</artifactId>
<version>1.3</version>
<!-- TODO:
- fix rendering of company and project logos
- add UTF-8 font
-->
<executions>
<execution>
<phase>site</phase>
<goals>
<goal>pdf</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.2</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<effort>Max</effort>
<threshold>Low</threshold>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<!-- reporting plugins -->
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.8</version>
<configuration>
<dependencyLocationsEnabled>false</dependencyLocationsEnabled>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.2</version>
<configuration>
<show>private</show>
<excludePackageNames>test.pl.chilldev.sites.*</excludePackageNames>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.15</version>
<configuration>
<configLocation>src/main/checkstyle/checkstyle.xml</configLocation>
<propertyExpansion>checkstyle.project.basedir=${project.basedir}</propertyExpansion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.18.1</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<!-- TODO: 2.7 doesn't work well with Findbugs -->
<version>2.6</version>
<configuration>
<formats>
<format>html</format>
</formats>
<instrumentation>
<excludes>
<exclude>test/**/*.class</exclude>
</excludes>
</instrumentation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<effort>Max</effort>
<threshold>Low</threshold>
</configuration>
</plugin>
</plugins>
</reporting>
<!-- project dependencies -->
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- components of the project -->
<modules>
<module>sites-backend</module>
<module>sites-commons</module>
<module>sites-core</module>
<module>sites-frontend</module>
<module>sites-rpc-client-backend</module>
<module>sites-rpc-client-frontend</module>
<module>sites-rpc-service</module>
</modules>
</project>
Edit 2 (ErrorCode.java)
package pl.chilldev.sites.commons;
/**
* JSON-RPC error codes.
*/
public class ErrorCode
{
/**
* Dummy code that represents successful operation - should not be used at all.
*/
public static final int OK = 0;
/**
* No entity of specified ID exists.
*/
public static final int NO_ENTITY = 1;
}
Cobertura 2.7 alters project.build.outputDirectory in order to produce report for integration tests (new kind of report introduced in 2.7). In the next step Findbugs checks violations not on just compiled classes but on instrumented.
See bug:
http://jira.codehaus.org/browse/MCOBERTURA-203
As a workaround you can override classFilesDirectory:
...
<build>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<effort>Max</effort>
<threshold>Low</threshold>
<classFilesDirectory>${project.build.outputDirectory}</classFilesDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
...
</build>
...
Another solution is to skip integration tests report and proceed with unit tests report only:
http://mojo.codehaus.org/cobertura-maven-plugin/usage.html#Using_different_reports
If you force findbugs to run in the "compile" phase instead of the "test" phase, it will cause findbugs to run before the code is instrumented by cobertuar, thus solving the issue as described by Mateusz Balbus. This findbugs maven configuration works for me:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.5</version>
<configuration>
<executions>
<execution>
<id>findbugs-check</id>
<phase>compile</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</configuration>
</plugin>
Need to know about your project structure first.
I think your problem can be solved by using transitive dependency but not sure.
It does two things.
Set a default version for dependencies in submodules/child projects
override the version of transitive dependencies
it does override a specified value in a transitive dependency.
The enforcer plugin does not ignore the dependencyManagement. But is unable to recognize the discrepancy since the transitive dependency's version was altered before it went to work.
Here is a nice article : You can go through it:
http://andydennie.com/2012/08/02/maven-enforcer-plugin-vs-dependencymanagement/
And another source: http://maven.apache.org/enforcer/maven-enforcer-plugin/
Thanks.

Resources