I'm trying to configure my multimodule maven project like this :
Parent Project
web
dao
core
<modules>
<module>../dao</module>
<module>../core</module>
<module>../web</module>
</modules>
My "web" module have one dependency to my "core" project and my core project to my "dao" project.
For example, my web pom contain :
<dependency>
<groupId>com.groupid</groupId>
<artifactId>core</artifactId>
<version>${project.version}</version>
<classifier>jar-with-dependencies</classifier>
</dependency>
When I build my parent project all build work fine but there is a very strange dependency copy. In fact, my parent project contains all child dependencies
For example, joda-time is in my web pom.
When I try to uncompress my web.war, it contains my core-jar-with-depency.jar and all the dependency.
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<skipAssembly>false</skipAssembly>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
How can I configure my parent project to disable dependency inclusion?
Any specific reason for using classifier jar-with-dependencies? Looking at your need, I think you can do this ---
dao --> module with packaging jar
core --> module with packaging jar & dependency of dao without any classifier.
web --> module with packagingc war & dependency of core without any classifier.
Eventually your web war file will 'transitively' get core & dao & all its dependencies. See if this helps.
--- Update:
I just created one sample project with core module & web module in my GIT hub.
https://github.com/Ravikharatmal/MyGitRepo/tree/master/MultiModuleMavenProject
Web is dependent on Core. Core has a dependency on third party library commons-lang. When I do 'mvn install', you can see that the final web.war file has core.jar as well as commons-lang.jar i.e. transitive dependency of core.jar.
https://github.com/Ravikharatmal/MyGitRepo/tree/master/MultiModuleMavenProject/web/target/web-0.0.1-SNAPSHOT/WEB-INF/lib
I hope this is what you are looking for.
Related
I have a maven plugin and I'd like to configure it by providing a path to a file/directory which is inside a dependency jar.
Here is a sample of my maven projects pom.xml. It has a plugin with a dependency which has a property as part of its execution called templateDirectory. I would like to put a path here to the plugins dependency mylang-swagger-codegen to a file/directory inside of the dependency
{ Some path }/src/resources/api/
How can I get to this path? I understand references like ${project.basedir} work to get to the project. Is there a way I can reference to the dependency and inside the jar to get to the file / directory I want?
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.4.19</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/api/swagger.yaml</inputSpec>
<language>myLang</language>
<templateDirectory> <!-- Path here to api.mustache --> </templateDirectory>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>mylang-swagger-codegen</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
Jar files are built on .zip. Maybe a Maven plugin that unwraps dependencies can help with what you want to accomplish.
Take a look at this to unpack a specific artifact: https://maven.apache.org/plugins/maven-dependency-plugin/examples/unpacking-artifacts.html
Or this, to unpack the project dependencies: https://maven.apache.org/plugins/maven-dependency-plugin/examples/unpacking-project-dependencies.html
After running this plugin, you can access the path where you unpacked the jar. In the examples above, the plugin runs in the "package" phase of maven. If you want to change the order, take a look at the maven build phases: https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
I am trying to make a mojo that takes all the unit tests from all the modules that have a certain annotation made by me. The problem is that I can't access the unit tests from any module.
The module structure looks like this:
|--ModuleA (depends on Module D)
|--ModuleB (depends on Module D)
|--ModuleC (depends on Module D)
|--ModuleD (the mojo)
The question is how to access or retrieve the unit test classes of each module when the mojo runs for it.
Updated Response since you told us about the dependencies of the modules.
Best way to do this is :
- moduleA, moduleB, moduleC built with maven
- generate test jars : add in your pom
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>test-jar</id>
<phase>package</phase>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
moduleD has dependcy on moduleA.jar,moduleB.jar,moduleC.jar & moduleA-test.jar,moduleB-test.jar,moduleC-test.jar
add in your moduleE's pom.xml for each module :
<dependency>
<groupId>com.rizze</groupId>
<artifactId>moduleA</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.rizze</groupId>
<artifactId>moduleB</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.rizze</groupId>
<artifactId>moduleC</artifactId>
<version>1.0.0</version>
</dependency>
Module E is here to call all the test of Module A,B,C,D in the order you want to. Module E is making integration of all the modules in order to perform all the tests (as requested by you).
I want to create ear application with one ejb project and dependencies (without war file). Is it possible to specify build configuration in one pom.xml to avoid unnecessary multiplication of application modules (I have about 8 projects witch will be packaged this way and if I would do this "standard" way I would have to create 8*3=24 modules/poms). I don't want to put all my applications into one ear, because I need to could undeploy/redeploy them separately.
Right now I have two solutions:
Create ear in standard way with module structure:
project
ejb
src
pom.xml
ear
pom.xml
pom.xml
But as I mentioned it's creating multiplication of modules.
Create jar with dependencies using maven-shade-plugin
<build>
<plugins>
<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>
<finalName>project</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
But with this solution I get jar instead of ear and my dependencies are mixed with my code.
Is there any other way to create deployable application with only ejb and dependencies with maven using single pom.xml?
Is there a way to pack the dependencies of a maven ejb project in with the final jar?
I typically use a separate ear project and include the ejb as a dependency - it will fill out the lib folder automatically this way. However, this seems a bit wasteful - to have a project just to build the ear.
Right now I have:
<artifactId>projectname</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>ejb</packaging>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<!-- without this, the datetime stamp unique id's will be appended to classpath items -->
<!-- see: http://maven.apache.org/shared/maven-archiver/examples/classpath.html#Snapshot -->
<useUniqueVersions>false</useUniqueVersions>
</manifest>
</archive>
</configuration>
</plugin>
Do I need to set the packaging type to ear? Can I include transitive dependencies in a standalone ejb jar? If I set it to ear, how do I config the ear plugin?
Thanks in advance!
The Maven Shade Plugin can package dependencies in with the JAR. It will extract the classes/resources from all the project's dependencies on package them in with the final JAR.
This should be enough to package all your dependencies:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
There are disadvantages to doing this, however.
Multiple resources with the same name in different JARs can cause problems (e.g. /META-INF/services/...). You can use Shade's resource transformers, but it can get messy.
Not as easy to track what JARs are dependencies in your project once deployed (you'd have to refer back to the POM instead of just looking at the EAR).
Unless you have good reason not to, I'd recommend you stick with building an EAR.
I don't think there is a direct way to do this. Instead, what can be done is to create it as a module project with an ear and an ejb module. It isn't exactly what I wanted, but it works and is better than separate projects.
Something bother me a lot...
On a big project with many dependencies, some of them are set as SNAPSHOT in Maven2.
The matter is that it seems i can't get the sources through Eclipse without loading the project or fixing the dependency to the last release.
For debugging, it's really annoying me...
EDIT
This is what i get in eclipse maven console:
26/08/10 11:31:46 CEST: Downloading http://repo-maven/archiva/repository/snapshots/com/blabla/1.1-SNAPSHOT/blabla-1.1-20100824.213711-80-javadoc.jar
26/08/10 11:31:47 CEST: Could not download sources for com.blabla:blabla:1.1-20100824.213711-80
On archiva i can see the deployed stuff i want to retrieve in eclipse...
Repository snapshots
Group ID com.blabla
Artifact ID blabla
Version 1.1-20100824.213711-80
Packaging jar
Parent com.blabla bla 1.1-SNAPSHOT (View)
Other Versions 1.1-20100824.213535-79
I can download sources of this artifact with my browser but not within Eclipse... Any idea?
The matter is that it seems I can't get the sources through Eclipse without loading the project or fixing the dependency to the last release. For debugging, it's really annoying me...
Well, these modules are probably not publishing source JARs as part of the "regular" build process (i.e. outside the release). If these modules are under your control (which is my understanding), configuring the Maven Source Plugin to produce source JARs for them and deploying them in your corporate repo should solve the problem. From the Usage page:
Installing the sources along with your artifact
There are two ways to do this. You can
either bind this plugin to a phase or
you can add it to a profile. The goals
source:jar-no-fork and
source:test-jar-no-fork are preferred
for binding the goal to the build
lifecycle.
Installing the sources using a phase binding
Here is how you would configure the
plugin in your pom.xml to run
automatically during the verify phase:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
We are using the verify phase here
because it is the phase that comes
before the install phase, thus making
sure that the sources jar has been
created before the install takes
place.
Installing the sources using a profile
If you want to install a jar of your
sources along with your artifact
during the release process, you can
add this to your pom.xml file:
<project>
...
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
...
</project>
Using a profile would probably be a good idea so that building source JARs will only be done by the build running at the CI server level but not on developer machines.