I have a multi-module project and one of the modules should create an EAR out of the other modules artifacts. To make things more interesting, these other 4 artifacts have to be shaded into 2 artifacts:
super-pom
|-- ear module
|-- ejb1
|-- ejb2
|-- web1
|-- web2
What it creates is an EAR containing ejb2-shaded, web2-shaded AND ej1, web1 (which are included in the shaded versions!).
Oddly enough, if I run maven manually in each module and in the ear-module in the end, I get what I wanted.
What I can't figure out is, how the super-pom sneaks these artifacts into the EAR. Event maven package -X only lists the right artifacts in the ear cration step:
[DEBUG] Resolving artifact type mappings ...
[DEBUG] Initializing JBoss configuration if necessary ...
[DEBUG] Initializing ear execution context
[DEBUG] Resolving ear modules ...
[DEBUG] Resolving ear module[ejb:com.mycomp:ejb2]
[DEBUG] Resolving ear module[war:com.mycomp:web2]
[DEBUG] Resolving ear module[jar:org.jboss.seam:jboss-seam]
[INFO] Generating application.xml
Some simplified poms, starting with the super-pom:
<artifactId>super-pom</artifactId>
<packaging>pom</packaging>
<modules>
<module>ejb1</module>
<module>web1</module>
<module>ejb2</module>
<module>web2</module>
<module>ear</module>
</modules>
ear-pom:
<artifactId>ear</artifactId>
<packaging>ear</packaging>
<parent>
...
<artifactId>super-pom</artifactId>
...
</parent>
<dependencies>
<dependency>
...
<artifactId>ejb2</artifactId>
<type>ejb</type>
...
</dependency>
<dependency>
...
<artifactId>web2</artifactId>
<type>ejb</type>
...
</dependency>
<!-- Little "trick" to avoid listing all shared deps from WAR. To use skinyWar,
deps to be shared via EAR/lib must be explicitly listed here. Including the
POM let's maven deal with this -->
<dependency>
...
<artifactId>web2</artifactId>
<type>pom</type>
...
</dependency>
</dependencies>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.6</version>
<configuration>
<!-- Tell Maven we are using Java EE 6 -->
<version>6</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<!-- See maven docs; Necessary because we CAN'T have 2 jboss-seam.jars
in the same EAR -->
<skinnyWars>true</skinnyWars>
<initializeInOrder>true</initializeInOrder>
<modules>
<ejbModule>
<groupId>com.mycomp</groupId>
<artifactId>ejb2</artifactId>
</ejbModule>
<webModule>
<groupId>com.mycomp</groupId>
<artifactId>web2</artifactId>
<contextRoot>/</contextRoot>
</webModule>
<jarModule>
<groupId>org.jboss.seam</groupId>
<artifactId>jboss-seam</artifactId>
<includeInApplicationXml>true</includeInApplicationXml>
<bundleDir>/</bundleDir>
</jarModule>
</modules>
</configuration>
</plugin>
</plugins>
ejb2-pom:
<artifactId>ejb2</artifactId>
<packaging>ejb</packaging>
<parent>
...
<artifactId>super-pom</artifactId>
...
</parent>
<dependencies>
<dependency>
...
<artifactId>ejb1</artifactId>
<type>ejb</type>
...
</dependency>
</dependencies>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<artifactSet>
<includes>
<include>com.mycomp:ejb1</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
web2-pom:
<artifactId>web2</artifactId>
<packaging>war</packaging>
<parent>
...
<artifactId>super-pom</artifactId>
...
</parent>
<dependencies>
<dependency>
...
<artifactId>web1</artifactId>
<type>war</type>
...
</dependency>
</dependencies>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<artifactSet>
<includes>
<include>com.mycomp:web1</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Related
This question already has answers here:
How can I create an executable/runnable JAR with dependencies using Maven?
(33 answers)
Closed 3 years ago.
How to make Maven include the JDBC driver for Postgres inside my app's .jar file?
I added this dependency element to the <dependencies> element in my POM.
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.8</version>
</dependency>
The IntelliJ IDE shows the driver was successfully downloaded, as it is listed in the "External Libraries" item of my Project pane. And my code can use the JDBC classes such as PGSimpleDataSource.
When I build, if I look inside the resulting .jar file, there is no JDBC driver included.
My project is driven by Maven, using the maven-archetype-quickstart archetype. I did update all the version numbers within the POM to the latest. My only other change was to add the following to get the manifest file of the JAR to specify a main class.
<configuration>
<archive>
<manifest>
<mainClass>work.basil.example.App</mainClass>
</manifest>
</archive>
</configuration>
I thought that Maven by default would bundle all dependencies inside the resulting JAR file. That is the behavior I have seen in building Vaadin web apps. Is that not the case more generally? Or is the JDBC driver special and being omitted for some reason.
If it helps, here is the entire POM.
<?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>tryjdbc</artifactId>
<version>1.0-SNAPSHOT</version>
<name>tryjdbc</name>
<description>A simple tryjdbc.</description>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>13</maven.compiler.source>
<maven.compiler.target>13</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.0-M1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.8</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.8.2</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<archive>
<manifest>
<mainClass>work.basil.example.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<reporting>
<plugins>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
</plugin>
</plugins>
</reporting>
</project>
The .war files, such as those you saw in building Vaadin web apps, do include dependencies by default.
In contrast, the .jar files built by Maven do not include any dependencies by default.
You can use a plugin such as maven-shade-plugin to create a shaded jar, which does include the dependencies:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<!-- put your configurations here -->
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
Further examples can be found on the Apache Maven Shade Plugin project page.
I am trying to transform a working single GWT-Project into several Maven-Modules.
New structure should look like this:
Project
|- pom.xml
|- Project-Common(only Common-Classes)
|--- pom.xml
|--- Packaging: jar
|- Project-War(includes *gwt.xml)
|--- pom.xml
|--- Packaging: war
My files look like this(many dependencies, I think i removed the unnecessary to make my problem more clear)
Project pom.xml:
<modelVersion>4.0.0</modelVersion>
<artifactId>project</artifactId>
<packaging>pom</packaging>
<name>Project - Modules</name>
<version>1.0.0-SNAPSHOT</version>
<parent>
<groupId>com.project</groupId>
<artifactId>project-parent-parent</artifactId>
<version>2.0.0</version>
<relativePath />
</parent>
<modules>
<module>/project-war</module>
<module>/project-common</module>
</modules>
Project-Common pom.xml:
<modelVersion>4.0.0</modelVersion>
<artifactId>project-common</artifactId>
<packaging>jar</packaging>
<name>Project - Common</name>
<version>1.0.0-SNAPSHOT</version>
<parent>
<groupId>com.project</groupId>
<artifactId>project-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath />
</parent>
<build>
<plugins>
<plugin>
<groupId>com.github.koraktor</groupId>
<artifactId>mavanagaiata</artifactId>
<executions>
<execution>
<id>load-git-branch</id>
<phase>validate</phase>
<goals>
<goal>commit</goal>
</goals>
<configuration>
<dirtyFlag>*</dirtyFlag>
<gitDir>../../.git</gitDir>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Project-War pom.xml:
<modelVersion>4.0.0</modelVersion>
<artifactId>project-war</artifactId>
<version>1.1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>Project - WAR</name>
<parent>
<groupId>com.project</groupId>
<artifactId>parent-project</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>com.project</groupId>
<artifactId>project-common</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.7.0</version>
<inherited>true</inherited>
<configuration>
<runTarget>/test.html</runTarget>
<modules>
<module>com.project.modules.Test</module>
</modules>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<id>VerifyRequestFactoryInterfaces</id>
<executable>java</executable>
<arguments>
<argument>-cp</argument>
<classpath />
<argument>com.google.web.bindery.requestfactory.apt.ValidationTool</argument>
<argument>${project.build.outputDirectory}</argument>
<argument>com.project.factorys.TestRequestFactory</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<filesets>
<fileset>
<directory>src/main</directory>
<includes>
<directory>gwt-unitCache/**</directory>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>com.github.koraktor</groupId>
<artifactId>mavanagaiata</artifactId>
<executions>
<execution>
<id>load-git-branch</id>
<phase>validate</phase>
<goals>
<goal>commit</goal>
</goals>
<configuration>
<dirtyFlag>*</dirtyFlag>
<gitDir>../../.git</gitDir>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The old Project was in my Project-War and I added Project & Project-Common. In this setup the Project builds and I get the "new" Project-War.war .
But when I move a ErrorCode.java from Project-War to Project-Common I get the following Error:
[INFO] Tracing compile failure path for type 'com.project.modules.TestViewImpl'
[INFO] [ERROR] Errors in '.../project/project-war/src/main/java/com/project/modules/TestViewImpl.java'
[INFO] [ERROR] Line 20: No source code is available for type com.project.errorcodes.ErrorCode; did you forget to inherit a required module?
[INFO] [ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly
Your Project-Common doesn't package its sources to be available to the Project-War, so GWT effectively can't find the source for ErrorCodes class.
You have to either use the maven-source-plugin's jar-no-fork goal in Project-Common to package sources, and then add a second dependency on Project-Common in Project-War with <classifier>sources</classifier>; or declare your src/main/java as a resource directory to package sources into the Project-Common's JAR.
As a side note, Mojo's Maven Plugin for GWT isn't a great fit for multi-module projects. I'd advise switching to the net.ltgt.gwt.maven:gwt-maven-plugin which was designed for multi-module builds from the ground up (disclaimer: I'm the author of that plugin, and former maintainer of Mojo's plugin)
Found a Solution:
Added a Module in Common-Project
<module>
<inherits name='com.google.gwt.activity.Activity' />
<inherits name='com.google.gwt.place.Place' />
<inherits name="com.google.gwt.user.User" />
<inherits name='com.google.web.bindery.requestfactory.RequestFactory' />
<inherits name="com.google.gwt.user.cellview.CellView" />
<inherits name='com.google.gwt.logging.Logging' />
<inherits name="com.google.gwt.inject.Inject" />
<inherits name="com.google.gwt.text.Text" />
<inherits name="com.google.gwt.i18n.I18N" />
<inherits name="com.google.gwt.debug.Debug" />
<source path="shared"/>
</module>
any my ErrorCode.java is under Path shared/** .
In Project-War Modules I added <inherits name="com.project.Common" /> and in pom.xml from Project-War:
<dependency>
<groupId>com.project</groupId>
<artifactId>project-common</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.project</groupId>
<artifactId>project-common</artifactId>
<version>1.0.0-SNAPSHOT</version>
<classifier>sources</classifier>
<scope>provided</scope>
</dependency>
Seems to need dependency with classifier in scope provided.
Seems like there are couple of questions, which are quite old and things changed from Java 8 support of Jacoco.
My Project contains following structure
pom.xml
|
|
-----sub module A pom.xml
|
|
-----sub module B pom.xml
|
|
-----sub module C pom.xml
I have configured the main pom like this
Main 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>com.test</groupId>
<artifactId>jacoco-multi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>projectA</module>
<module>projectB</module>
</modules>
<properties>
<jacoco.version>0.5.7.201204190339</jacoco.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit-dep</artifactId>
<version>4.10</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3.RC2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3.RC2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<configuration>
<destFile>${project.basedir}/../target/jacoco.exec</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.16</version>
<executions>
<execution>
<id>default-integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
</plugin>
</plugins>
</build>
</project>
A 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>
<parent>
<artifactId>jacoco-multi</artifactId>
<groupId>com.test</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>projectA</artifactId>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
B 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>
<parent>
<artifactId>jacoco-multi</artifactId>
<groupId>com.test</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>projectB</artifactId>
<dependencies>
<dependency>
<groupId>com.test</groupId>
<artifactId>projectA</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
</plugin>
</plugins>
</pluginManagement>
</build>
I am executing this command mvn clean package. I can see jacoco.exec is getting generated, however I am not able to see any HTML reports are being to verify the data.
Please help me with this.
Another point is, my configuration is correct for Multi-Module projects?
Update
Identified issue.
<destFile>${project.basedir}/../target/jacoco.exec</destFile>
changed to
<destFile>${project.basedir}/target/jacoco.exec</destFile>
Now it's generating reports for individual modules.
Any idea how to generate consolidated report
JaCoCo version 0.7.7 can generate an aggregate coverage report from multiple Maven modules through a new goal jacoco:report-aggregate.
After scanning many solutions I created a simple but complete Jacoco demo project showing:
Multi module project
Unit test (via mvn clean install)
Integration test (via mvn clean install -P integration-test)
Jacoco - test coverage ( both aggregate data file and aggregate reporting)
FindBugs - code quality
Enjoy the simple demo project. In this simple project the README.md file contains information you are looking for. An example is:
The simple demo project contains 3 branches:
Master branch - containing the above functionality
Multi-module-only-unit-tests - contains modules with only unit tests
Multi-module-unit-tests-try2 - contains modules with unit tests, differently.
Follow below-mentioned instructions
Create a new sub-project (usually called maven module). This will be used as report aggregator.
parent pom will be like:
<modules>
<module>A</module>
<module>B</module>
<module>C</module>
<module>ReportAggregator</module>
</modules>
In aggregator module pom- add other subprojects dependencies.
<dependency>
<groupId>xyz</groupId>
<artifactId>A</artifactId>
<version>${project.version}</version>
</dependency>
In aggregator module pom- configure jacoco plugin
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report-aggregate</id>
<phase>verify</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
<configuration>
<dataFileIncludes>
<dataFileInclude>**/jacoco.exec</dataFileInclude>
</dataFileIncludes>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-aggregate</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
In aggregator module pom- configure surefire plugin as
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>**/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
(optional step) If anybody face warning/error like:
Classes in bundle '*' do no match with execution data. For report generation, the same class files must be used as at runtime.**
Then add below mentioned lines in aggregator module pom
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<executions>
<execution>
<id>instrument-ut</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>restore-ut</id>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report-aggregate</id>
<phase>verify</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
<configuration>
<dataFileIncludes>
<dataFileInclude>**/jacoco.exec</dataFileInclude>
</dataFileIncludes>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-aggregate</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
run mvn clean install
One problem in multimodule projects is caused, if the aggregator pom is used as parent pom for the modules either, like it is the case in the above example:
- parentAggregator pom
---sub module A pom.xml -> parentAggregator pom
---sub module B pom.xml -> parentAggregator pom
---sub module C pom.xml -> parentAggregator pom
In this case, the build order is:
- parentAggregator
- sub module A
- sub module B
- sub module C
which means, that the parent aggregator can not collect complete information. In my case a transfer of data into sonarQube by mvn sonar:sonar resulted in unexpected and uncomplete results.
Changing the module structure to:
- aggregator pom
-- parent pom
---sub module A pom.xml -> parent pom
---sub module B pom.xml -> parent pom
---sub module C pom.xml -> parent pom
will change the build order to:
- parent
- sub module A
- sub module B
- sub module C
- aggregator
In this case aggregator will be the last one and work with the results of the modules. In my case the results in SonarQube were like expected.
Run Coverage as... Junit for each module separately. Then create a launch group and add each of the run configurations. There is a popup "Launch Mode" with options Inherit, Profile, Coverage, Debug or Run. Choose Coverage for all of them. You probably also want to select "Wait until terminated".
You can now run all the coverage tests in one click. After they complete you need to go into the Coverage View and select merge sessions (double red/green bar) and merge them all into one report.
I'm using maven-webstart-plugin to generate 2 JNLP (jnlpA and jnlpB), configured as 2 executions. The project, has 2 dependencies:
dependencyA.jar (that depends of some commons and others as A1.jar, A2.jar, A3.jar...)
dependencyB.jar (that depends of some commons and others as B1.jar, B2.jar, B3.jar...).
I need that jnlpA has as dependencies dependencyA.jar, commons and A1.jar, A2.jar, A3.jar... And jnlpB dependencyB.jar, commons and B1.jar, B2.jar, B3.jar... I don't know how to do this with maven-webstart-plugin.
I have tried with this:
Use the plugin property called "excludeTransitive" to false (default). In this case both JNLP will have all dependencies.
Change "excludeTransitive" to true, in this case both JNLP will only have dependencyA.jar and dependencyB.jar as dependencies.
With "excludeTransitive" to false (default), use the options exclude and include that the plugin allow to use in each execution:
If I use exclude in the execution of jnlpA, and I exclude dependencyB.jar, the jnlpA still has as dependenci B1.jar, B2.jar... I.E. only exclude the dependency and not all its transitive dependencies.
If I use include in the execution of jnlpA, and I include dependencyA.jar, the A1.jar, A2.jar... are not included. I.E. only include this dependency and not all its transitive dependencies.
So, my problem is that I need to include or exclude a dependency in a execution but with all its transitive dependencies.
An example of my pom when I was trying option 3 was:
<?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>
<artifactId>MyJnlp</artifactId>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>webstart-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<executions>
<execution>
<id>install-jnlp</id>
<phase>process-resources</phase>
<goals>
<goal>jnlp-inline</goal>
</goals>
<configuration>
<workDirectory>target/dist</workDirectory>
<jnlp>
<inputTemplate>src/main/jnlp/jnlpA-template.vm</inputTemplate>
<outputFile>jnlpA.jnlp</outputFile>
<mainClass>Start</mainClass>
</jnlp>
<dependencies>
<excludes>
<exclude>xxx:dependencyB</exclude>
</excludes>
</dependencies>
</configuration>
</execution>
<execution>
<id>uninstall-jnlp</id>
<phase>process-resources</phase>
<goals>
<goal>jnlp-inline</goal>
</goals>
<configuration>
<workDirectory>target/dist</workDirectory>
<jnlp>
<inputTemplate>src/main/jnlp/jnlpB-template.vm</inputTemplate>
<outputFile>jnlpB.jnlp</outputFile>
<mainClass>Uninstaller</mainClass>
</jnlp>
<dependencies>
<excludes>
<exclude>xxx:dependencyA</exclude>
</excludes>
</dependencies>
</configuration>
</execution>
</executions>
<configuration>
<excludeTransitive>false</excludeTransitive><resourcesDirectory>${project.basedir}/src/main/jnlp/resources</resourcesDirectory>
<jnlp>
<inputTemplateResourcePath>${project.basedir}</inputTemplateResourcePath>
</jnlp>
<gzip>true</gzip>
<makeArchive>false</makeArchive>
<outputJarVersions>false</outputJarVersions>
<verbose>true</verbose>
<encoding>ISO-8859-1</encoding>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>xxx</groupId>
<artifactId>dependencyA</artifactId>
<version>1.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>xxx</groupId>
<artifactId>dependencyB</artifactId>
<version>1.0</version>
<scope>runtime</scope>
</dependency>
</dependencies>
I have a project consisting of 3 libraries - let's call them 1) BABY, 2) CHILD and 3) ADULT. Lib "CHILD" depends on "BABY" and "ADULT" depends on "CHILD".
What I want to do is produce:
a dev version that has all the (transitive) dependencies
a production version that creates a standalone JAR for each library (embedding the dependencies)
I have a profile dev and a profile release already, and I know how to use ProGuard to generate the JAR.
The question is how to tell Maven to keep all dependencies in dev and ignore them (optional/provided) in production?
To have different dependencies when you develop to deployment you could use maven profiles.
http://maven.apache.org/guides/introduction/introduction-to-profiles.html
So when developing you would use something like mvn -Pdev compile
When you say "standalone jar" it sounds like you mean a jar with all dependencies merged into it.
How can I create an executable JAR with dependencies using Maven?
or http://maven.apache.org/plugins/maven-assembly-plugin/
Here is what I used eventually:
The parent POM defines a profile release that configurates the proguard plugin (crates one big JAR) and the install plugin (places the release artifact in the repo).
The lib-baby POM simply calls the 2 plugins in the <build> section.
The lib-child POM additionally specifies a dev profile where the dependency to lib-baby is defined. Within the release profile this dependency has an optional tag and is included in the big JAR.
In the end when run by default, the libs com.company.dev:lib-baby and com.company.dev:lib-child are created (included their dependencies).
When run with -Prelease the libs com.company:lib-baby and com.company:lib-child are created (standalone libs [WITHOUT any dependencies]) - only side effect is that the default artifacts (.*dev) are overwritten :(
parent:
<project>
<groupId>com.company</groupId>
<artifactId>lib-parent</artifactId>
<packaging>pom</packaging>
<modules>
<module>lib-baby</module>
<module>lib-child</module>
<module>lib-adult</module>
</modules>
<profiles>
<profile>
<id>release</id>
<activation>
<property>
<name>release</name>
</property>
</activation>
<build>
<pluginManagement>
<plugins>
<!-- aggregate to one big jar -->
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<executions>
...
</executions>
<configuration>
<injar>${project.build.finalName}.jar</injar>
<outjar>${project.build.finalName}-release.jar</outjar>
....
</configuration>
</plugin>
<!-- install release version of artifact separately (under com.company) -->
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-release</id>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>
target/${project.build.finalName}-release.jar
</file>
<groupId>com.company</groupId>
...
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>
lib-baby:
<project>
<groupId>com.company.dev</groupId>
<artifactId>lib-baby</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>com.company</groupId>
<artifactId>lib-parent</artifactId>
</parent>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<!-- produces 'lib-baby-release.jar -->
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
</plugin>
<!-- installs 'lib-baby-release.jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-release</id>
<phase>install</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
lib-child:
<project>
<groupId>com.company.dev</groupId>
<artifactId>lib-child</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>com.company</groupId>
<artifactId>lib-parent</artifactId>
</parent>
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>com.company.dev</groupId>
<artifactId>lib-baby</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>release</id>
<dependencies>
<dependency>
<groupId>com.company.dev</groupId>
<artifactId>lib-baby</artifactId>
<version>1.0</version>
<!-- made optional because will be embedded in standalone jar -->
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<!-- produces 'lib-child-release.jar -->
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<configuration>
<assembly>
<inclusions>
<inclusion>
<groupId>com.company.dev</groupId>
<artifactId>lib-baby</artifactId>
</inclusion>
</inclusions>
</assembly>
</configuration>
</plugin>
<!-- installs 'lib-child-release.jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-release</id>
<phase>install</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>