Generate a runnable jar and include libraries in it with Maven - maven

I'm trying to compile a Java project with Maven and Eclipse but I tried a lot of solutions seen on the web but none of them seem to work. I just want to build the application, create a runnable jar and include the needed libraries. I tried maven-dependency or maven-assembly but I surely miss something because I fail every time.
Here is my pom.xml, is it ok or does it miss something?
<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>
<!-- Project Description -->
<groupId>org.awax</groupId>
<artifactId>toolbox</artifactId>
<version>0.1.0</version>
<name>ToolBox</name>
<packaging>jar</packaging>
<url>http://maven.apache.org</url>
<description>Custom library containing useful code</description>
<!-- Project Properties -->
<properties>
<jdk.version>1.7</jdk.version>
<!-- Libraries Version -->
<log4j.version>1.2.17</log4j.version>
<jdom.version>2.0.5</jdom.version>
<miglayout.version>3.7.4</miglayout.version>
<jfreechart.version>1.0.19</jfreechart.version>
<bounce.version>0.18</bounce.version>
<!-- Maven Plugins Version -->
<eclipse.version>2.9</eclipse.version>
<compiler.version>3.2</compiler.version>
<jar.version>2.5</jar.version>
<assembly.version>2.4.1</assembly.version>
<dependency.version>2.5.1</dependency.version>
</properties>
<!-- Project Libraries -->
<dependencies>
<!-- LOG4J -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- Jdom -->
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom2</artifactId>
<version>${jdom.version}</version>
</dependency>
<!-- MigLayout -->
<dependency>
<groupId>com.miglayout</groupId>
<artifactId>miglayout</artifactId>
<version>${miglayout.version}</version>
</dependency>
<!-- JFreeChart -->
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>${jfreechart.version}</version>
</dependency>
<!-- Bounce -->
<dependency>
<groupId>org.bounce</groupId>
<artifactId>bounce</artifactId>
<version>${bounce.version}</version>
</dependency>
</dependencies>
<!-- Build Options -->
<build>
<pluginManagement>
<plugins>
<!-- Attach source code and Javadoc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>${eclipse.version}</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
</configuration>
</plugin>
<!-- Set a JDK compiler level -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler.version}</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<!-- Copy project dependencies -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${dependency.version}</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeScope>provided</includeScope>
<outputDirectory>${project.build.directory}/dependency</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- Create the Jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${jar.version}</version>
<configuration>
<archive>
<manifest>
<!-- Jar file entry point -->
<mainClass>${project.groupId}.${project.artifactId}.tools.WaveformGenerator</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<!-- Add dependencies to generated Jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${assembly.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

Use the maven-assembly-plugin to generate an executable jar with dependencies
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>2.4.1</version>
<executions>
<execution>
<id>make-executable-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.coderplus.sample.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
It's not working for you because ,you have added the plugin execution in the pluginManagement section. pluginManagement is supposed to be used for managing the plugin version and configuration.
Minimal version of how your build tag should look like :
<build>
<!-- if you have a multimodule project, I will probably manage this in the
parent pom -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${assembly.version}</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<executions>
<execution>
<id>make-executable-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.coderplus.sample.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Related

Why maven packege produce 4 jar files?

When I run mvn package,there are 4 files produced in total:
foo.jar
foo.zip
foo-1.0-SNAPSHOT.jar
foo.1.0-SNAPSHOT.jar.original
Could anyone please explain what leads to this situation?Is it some plugin that I used?
Here is some piece of my pom.xml:
<modelVersion>4.0.0</modelVersion>
<groupId>cn.bar.buzz</groupId>
<artifactId>foo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
... some dependencies
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.16.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<resources>
<resource>
<directory>src/main/resources/web</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
<resource>
<directory>src/main/resources/${profiles.active}</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.16.RELEASE</version>
<configuration>
<fork>true</fork>
<mainClass>cn.bar.service.MyApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>cn.bar.service.AnotherApplication</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>${project.artifactId}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
<outputDirectory>target</outputDirectory>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Is maven itself package for me or the plugins? If the latter,which plugin did which part of job?
spring-boot-maven-plugin produce foo-1.0-SNAPSHOT.jar and
foo.1.0-SNAPSHOT.jar.original
maven assembly plugin created zip file
maven default procude jar

No error in netbeans ide but java.lang.ClassNotFoundException: org.netbeans.lib.awtextra.AbsoluteLayout ERROR when java -jar jarfilename.jar

the maven app is running with no error on netbeans ide and the clean and build are running also without errors , the dependencies i didnt mention are :(mongodb,mongodb driver,mysql,itext) i tried launch4j , the .exe file didnt open.
this is the 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>
<groupId>com.mycompany</groupId>
<artifactId>billing-system</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<repositories>
<repository>
<id>unknown-jars-temp-repo</id>
<name>A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.</name>
<url>file:${project.basedir}/lib</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.netbeans.external</groupId>
<artifactId>AbsoluteLayout</artifactId>
<version>RELEASE120</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<itext.version>7.1.13</itext.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/libs
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>login</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
i tried creating a awtextra folder in lib/ and copy absolutelayout folder in it from external/ and it did not work .and this the command line error :
OneDrive\Desktop\billing-system\target>java -jar billing-system-1.0-SNAPSHOT.jar
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/netbeans/lib/awtextra/AbsoluteLayout
at login.initComponents(login.java:41)
at login.<init>(login.java:21)
Problem solved
1.installed maven
2.added configuration to java JAVA_HOME
3.added configuration to maven MAVEN_HOME
4.added plugin with goals to pom file
5.added built with dependencier to jar file
6.used launch4j for an exe file
my pom file :
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/libs
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>login</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>login</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>login</mainClass>
</configuration>
</plugin>
</plugins>
<defaultGoal>install</defaultGoal>
<!-- Source directory configuration -->
<sourceDirectory>src</sourceDirectory>
</build>

Maven update manifest in dependency jars

Webstart requires that all jar files has certain manifest entries, so now I have to go through all dependencies and update each manifest. Is there a way to get maven update manifest files in arbitrary jar files?
Ideally I would like:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>target</outputDirectory>
<!-- something like this -->
<manifestEntries>
<Trusted-Library>true</Trusted-Library> <!-- does not work! -->
</manifestEntries>
</configuration>
</execution>
</executions>
</plugin>
Are you sure that every jar need to contains MANIFEST? I think it's needed only in Jar with your entry / main class. You can generate it using maven-jar-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<addMavenDescriptor>true</addMavenDescriptor>
<manifestEntries>
<Permissions>all-permissions</Permissions>
<Application-Name>Your Application name</Application-Name>
</manifestEntries>
<manifest>
<mainClass>${entry.class}</mainClass>
</manifest>
</archive>
<finalName>${project.artifactId}</finalName>
</configuration>
</plugin>
You could use Webstart Maven Plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>webstart-maven-plugin</artifactId>
<version>1.0-beta-6</version>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>keytool-api-1.7</artifactId>
<version>1.5</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jnlp-inline</goal>
</goals>
</execution>
</executions>
<configuration>
<filenameMapping>simple</filenameMapping>
<versionEnabled>false</versionEnabled>
<jnlpFiles>
<jnlpFile>
<templateFilename>default-jnlp-servlet-template.vm</templateFilename>
<outputFilename>yourJnlp.jnlp</outputFilename>
<jarResources>
<jarResource>
<groupId>your.package</groupId>
<artifactId>ArtifactId</artifactId>
<version>${project.version}</version>
<mainClass>your.main.Class</mainClass>
</jarResource>
</jarResources>
</jnlpFile>
</jnlpFiles>
<unsignAlreadySignedJars>true</unsignAlreadySignedJars>
<canUnsign>true</canUnsign>
<libPath>lib</libPath>
<codebase>$$$codebase</codebase>
<updateManifestEntries>
<Caller-Allowable-Codebase>*</Caller-Allowable-Codebase>
<Trusted-Library>true</Trusted-Library>
<Application-Library-Allowable-Codebase>*</Application-Library-Allowable-Codebase>
<Application-Name>ApplicationName</Application-Name>
<Permissions>all-permissions</Permissions>
<Codebase>*</Codebase>
<Trusted-Only>true</Trusted-Only>
</updateManifestEntries>
<jnlp>
<j2seVersion>1.7+</j2seVersion>
<outputFile>your_jnlp.jnlp</outputFile>
<mainClass>your.class.here</mainClass>
</jnlp>
<sign>
<keystore>${project.basedir}/youekeystore</keystore>
<storepass>...</storepass>
<alias>your_alias</alias>
<verify>false</verify>
</sign>
<verbose>true</verbose>
</configuration>
</plugin>

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.

Include OSGI-INF to jar package after Maven compilation

I'm creating OSGi package and I want the Apache Felix SCR maven plugin to automatically include generated OSGI-INF folder to .jar package. Now it just generates OSGI-INF to target/scr-plugin-generated. This is my pom.xml
<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>maven.test</groupId>
<artifactId>test-dfs</artifactId>
<version>0.0.4-SNAPSHOT</version>
<name>DFS test</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<version>1.9.0</version>
<executions>
<execution>
<id>generate-scr-scrdescriptor</id>
<goals>
<goal>scr</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
...
</dependency>
<dependency>
<!-- scr annotations - for generating component descriptors only -->
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
<version>1.7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<depl.user>user</depl.user>
<depl.password>password</depl.password>
<depl.host>localhost</depl.host>
<depl.port>4502</depl.port>
</properties>
</project>
if you use:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.4.0</version>
<extensions>true</extensions>
</plugin>
instead maven-jar-plugin + maven-bundle-plugin (with manifest goal), all files generated by maven-scr-plugin will be included into a built bundle implicitly.

Resources