I have a multi module maven project. It has 5 module and 2 of them are web projects.
I want to customize my plugins to be run at only war projects. I mean at parent pom level I would like to trigger my goals and only my war projects will be affected. Is there any way for it?
As a result of this, I will not have duplicated configurations at my war projects pom.
Thanks
You can build a war parent pom (where your war projects are inheriting from) and a general parent pom (where everyone else is inheriting from).
general parent
/ \ \
war parent \ \
/ \ \ \
war1 war2 other1 other2
For building you may have a seperate build pom, having all the above as modules.
HTH
I have faced the same problem numerous times and I have come to the conclusion that the best solution is as follows:
cool-master
|-+ parents
| |- cool-parent
| |- cool-parent-web
|
|- module1
|- module2
|- module3
|- module-web1
|- module-web2
In the above example there are three types of modules:
parent POM-s (cool-parent, cool-parent-web)
non-web aps (extending cool-parent)
webapps (extending cool-parent-web)
In the parents you can define settings which are specific for the different types of modules. For example in the cool-parent define non-webapp related stuff, wheres in the cool-parent-web you can have all the fancy stuff like maven-war-plugin, jetty-maven-plugin, etc. I generally have the cool-parent-web extend the cool-parent in order to avoid having to duplicate dependencies, plugins settings and etc.
In the cool-parent-web define a <pluginManagement/> section and set up all the stuff for your plugins and then just use them across your web modules.
Related
I'm facing the problem with setting up a development environment with Maven and OSGi dependencies in Intellij.
At the beginning, a few words about how it looks like.
Everything is built on top of the Maven build. The whole hierarchy is already set up and I don't have any problems with building the project. It consists of many small submodules:
<modules>
<module>com.modulea</module>
<module>com.moduleb</module>
<modules>
Those modules use OSGi internally so everything might be presented with the following tree:
PARENT (pom.xml)
|----- Module A (pom.xml)
|----- META-INF
|----- MANIFEST.MF
|----- Export-bundle: com.modulea
|----- Module B (pom.xml)
|----- META-INF
|----- MANIFEST.MF
|----- Require-bundle: com.modulea
|----- src
...
|----- ModuleAClass (uses classes from com.modulea bundle)
The problem is connected with importing the project into IntelliJ. I imported it as a Maven project with checkboxes selected:
Create IntelliJ IDEA modules for aggregator projects (with 'pom' packaging)
Create module groups for multi-module Maven projects
IntelliJ created project's submodules basing on maven configurations but...
dependencies of those modules are set to libraries (Maven p2.eclipse-plugin). Is there any way to force it to use project's submodules? Of course, it is possible to do it manually (Project Settings -> Dependencies -> + -> Module dependency) but there are too many dependencies and submodules to repeat it every now and then again.
Additionally, if I have dependencies configured (library dependencies), OSMORC plugin is not able to resolve OSGi dependencies/configuration. For each of classes from an external bundle I got a message:
The package 'com.modulea' is not imported in the manifest less... (Ctrl+F1)
I'm trying to link together a set of disjoint maven projects into a standard multi module project.
The interesting thing is that the modules are currently not arranged in a natural heirarchy. If I link together with a parent pom, then the reactor won't start up until I add relativePaths to the parent stanza in the child pom XML files.
If the GAV details are correct in the parent version vs the child, and the child modules are all linked in the parent pom - shouldn't this be enough?
in simple terms - for a non-standard directory structure, is the relativePath strictly necessary for a multi module maven project?
Thanks, Ace
in simple terms - for a non-standard directory structure, is the relativePath strictly necessary for a multi module maven project?
The answer is: Yes!
If the parent is not yet installed in the local repository and if the directory structure is for example:
.
|-- my-module
| `-- pom.xml
`-- parent
`-- pom.xml
The child modules cannot inherit the groupId / version of their parent POM without setting the <relativePath> element.
See http://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Example_2
I have a maven based project. There are four different projects like shown in the structure below. Each main project and the subprojects have their own pom.xml files.
ProjectA
|
--------subProjects
ProjectB
|
--------subprojects
ProjectC
|
--------subProjects
ProjectD
|
-------subprojects
I am running mvn site on ProjectC which is dependent on ProjectB which is inter-dependent on ProjectA and ProjectB
So when i run maven site all the test results for all these projects get created individually. What I would also like to do is to create a aggregation of all the test results in these projects and sub-projects and show it in one place.
So is it possible with maven site?
Yes. There are two options:
"You can do this by setting project.build.directory on all of your projects to a common folder."
You can add extra directories to the maven-surefire-report-plugin by adding an reportsDirectories element with reportsDirectory children (documentation).
So this should work:
<reportsDirectories>
<reportsDirectory>../ProjectA/target/surefire-reports</reportsDirectory>
<reportsDirectory>../ProjectA/module1/target/surefire-reports</reportsDirectory>
...
</reportsDirectories>
A bit different approach would be to see test results in specialized servers like Jenkins or Sonar. This way no need to modify existing projects.
See running examples at https://builds.apache.org/ and https://analysis.apache.org/
Two screenshot from Sonar:
Result by module and package
For Jenkins there is Dashboard View Plugin
I'm participating in an open source project (ps3mediaserver) which has been moved from google code (SVN) and ANT (for build tasks) to git (GitHub) and maven. I've got my own fork (called pms-mlx), where I'd like to maintain some plugins being part of the default packaging when releasing. I'm pretty new to maven and am not too sure how the project should be structured to respect the maven way.
I'll start by describing how the environment behaved previously and will then give the thoughts about the move to maven.
Links:
Old: SVN + ANT ps3mediaserver project on google code
Old: SVN + ANT pms-mlx project on SourceForge
New: Git + Maven ps3mediaserver project on GitHub
New: Git + Maven pms-mlx project on GitHub
Old behavior:
Project structure:
+--workspace
+--plugins
+--plugin1
build.xml
+--plugin2
build.xml
+--ps3mediaserver_mlx
+--plugins
build.xml
The main project is ps3mediaserver_mlx, all plugins live in sub-folders of the workspace/plugins folder.
ps3mediaserver_mlx/build.xml contains a target BuildWithoutLibs which will build the jar of the main project and copy it to workspace/pms_no_libs.jar which will then be referenced (at this location) by the plugins.
When executing the build target of any plugin, the plugin will be build and the resulting jar copied to ps3mediaserver_mlx/plugins/[plugin_name].jar.
And finally, when packaging the application using the the build target in ps3mediaserver_mlx/build.xml, the plugins containedin workspace/ps3mediaserver_mlx/plugins will be packaged (in a exe installer for windows, dmg for OSX or tar.gz for linux).
New behavior
The project structure has been changed to this:
+-- workspace/
+-- pom.xml (global-pom)
+-- ps3mediaserver/
| +-- pom.xml (pms-pom)
| +-- src/
| ...
+-- plugins/
| +-- pom.xml (plugins-pom)
| +-- Plugin1/
| pom.xml (plugin1-pom)
| src/
| +-- Plugin2/
| pom.xml (plugin2-pom)
| src/
+-- pms-package/
+-- pom.xml (package-pom)
+-- src/main/assembly/
+-- src/main/external-resources/
Responsabilities:
global-pom The root pom containing all dependencies used by pms. This lets use the same version without redeclaring them in any plugin (is this a good idea?). Builds everything and contains a modules section to perform the same maven commands on all projects
<modules>
<module>ps3mediaserver</module>
<module>plugins</module>
<module>pms-package</module>
</modules>
pms-pom: Inherits from global-pom andbuilds the pms jar
plugins-pom: Inherits from global-pom; contains a depency for pms (which will be required for all plugins); contains a list of all modules having to be built
pluginX-pom: Inherits from plugins-pom and contains a custom configuration for a plugin
package-pom: Is responsible to package pms according to the platform it is being built on.
Does this structure represent the way maven is ment to be used?
Everything is working up to the packaging. This means the main application jar as well as all the plugins have been built and need to be packaged. The package-pom is responsible to do that.
In the original application there is only one pom.xml and the packaging is being done by using different profiles for Windows, Linux and OS X. The one I'm currently working on is for OSX and uses osxappbundle-maven-plugin, but the source code is never being packaged in the app file. That's because the packaging project doesn't inherit from the actual project anymore.
How has the built jar to be referenced in order to be packaged correctly in the app file?
I've tried referencing the jar in additionalResources and as custom class path, but never with success.
You have defined a dependency for example in the plugins/pom.xml
<dependencies>
<dependency>
<groupId>net.pms</groupId>
<artifactId>pms-mlx</artifactId>
<version>1.52.1_mlx_v0.8-SNAPSHOT</version>
</dependency>
</dependencies>
which exactly represents your parent. In other words it's wrong to define a dependency which already been defined as your parent.
It's good practice to put the modelVersion tag directly after the project tag and before the parent tag. After the parent tag put the information the current module like artifactId.
After diving into the project i noticed that you defined in your of your plugins/WebservicePlugin:
<modelVersion>4.0.0</modelVersion>
<artifactId>WebservicePlugin</artifactId>
<version>3-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>net.pms</groupId>
<artifactId>pms-plugins</artifactId>
<version>1.52.1_mlx_v0.8-SNAPSHOT</version>
</parent>
which is against the maven way for multi-module builds. You should not define a different version in this case. It should look like this:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.pms</groupId>
<artifactId>pms-plugins</artifactId>
<version>1.52.1_mlx_v0.8-SNAPSHOT</version>
</parent>
<artifactId>WebservicePlugin</artifactId>
If you have problems based on the version of the WebservicePlugin module than you should think about separating the WebservicePlugin from the rest (may be the other plugins as well).
One other things which i have noticed that you defined in many of the plugins (if not all of them) the configuration and the usage of the maven-compiler-plugin...This should be done by using a pluginManagement part in your root pom...to simplyfy maintenance of your project.
The copying of the created plugins-jars via the maven-antrun plugin into a different location whould be done different.
Repeating the license entry in every plugin is not needed cause it's inherited by the parent.
I've got a parent pom building a bunch of modules, looks like this:
pom.xml
| project-A / pom.xml
| project-B / pom.xml
| project-C / pom.xml
Which results in a build order of
Parent
A
B
C
When I install, I want to run a bunch of ant tasks that are in the parent pom, basically moving the jars in them modules into another directory, which requires the modules to be built first and the the parent to do it's thing. The problem is that the parent pom builds first then builds the modules, which isn't want I want.
The main requirement though is that I have to have it done in the install phase, if thats possible.
How can I make it so that when I run clean install, it runs the ant tasks AFTER the modules have been built and the module's jars are in their target directory?
Just create a "packager module" that depends on all of the other modules and run your ant tasks there.
In Linux the order is A,B,C,Parent. That's also a problem for me. It seems Linux and Windows has different fixed order.