I am using maven 3.1 and my project inherits from a third party parent pom. The parent pom has a profile which must not be activated as it introduces conflicting dependencies.
In order to prevent the parent's profile from kicking in, I tried defining an "empty" profile with the same id in the child pom - hoping it will override the one from the parent, but that did not work for me.
Is it possible and if so how can you override dependencies introduced by a profile in the parent pom ?
You may explicitly deactivate the profile on the command line by putting a '!' in front of the profile ID, e.g.
mvn -P !profileIdFromParent install
More on profile activation in the Maven docs.
Related
For some investigations I have used another pom which calls module poms. Unfortunately from the documentation it looks like properties are only overwritten if that pom is configured for all modules as a parent
Is there a parameter to run a maven module pom with a command that overwrites the relative path to the parent pom ?
Or even better to set that path in a called pom to make it parent for all modules?
AFAIK, it is not possible.The reference of parent pom cannot be parametrized because the parent pom resolution happens before evaluation of the properties (because it is parent pom who can also define properties for your pom).
In order to change a set of properties in your pom, rather than specifying them in a pom you wanted to plug in as a adhoc parent pom, you can create a shell (or windows cmd) script and specify the properties as -D parameters of your maven command.That is
mvn clean install -Dthe.property.1.to.override=value1 -Dthe.property.2.to.override=value2 ...
You can also specify your properties and values in a property file and let maven load this file by using Maven Properties Plugin.
I'm using the versions plugin to... set versions.
mvn versions:set -DnewVersion=XXXX
That work's great on aggregate project with declared modules
Now my question is how, in other maven project can I change the parent pom version ? I've placed high hopes in the versions:update-parent but I would like just to set the parent with the version i'm specifying regardless whether that version is deployed or not. Besides I can't get it to work. It never modifies the actual pom. Is there a way to do just that using a mvn plug-in ? Right now it's a manual pom.xml edit.
Thanks
Aa.
I usually use release plugin for that. It changes version of the parent and all the submodules:
mvn release:update-versions -DautoVersionSubmodules=true
Details are here:
http://maven.apache.org/maven-release/maven-release-plugin/examples/update-versions.html
I am handling multi module Maven project in which I have defined a property productversion which is inherited by all child modules. I am using this even in the parent tag defined in child pom's. The build when ran is successful and the correct version jar is being deployed in local repository.
Problem I am encountering is that I am not able to build a child module in isolation. it is saying "Non-resolvable parent pom" . this might be because of using this property and maven install the pom file in repository and then on running; parent child relationship are read from local repository pom only.
Is this issue addressed in any of the Maven version?
Can we update the pom in local repo as part of the build process?
I would strongly recommend to upgrade to a more up-to-date version of Maven cause Maven 2.2.1 is EoL for a year now (has been done in february 2014).
To solve what you like to achieve you can use Maven 3.2.5 (or Maven 3.3.1)
Excerpt from the release notes:
A simple change to prevent Maven from emitting warnings about versions
with property expressions. Allowed property expressions in versions
include ${revision}, ${changelist}, and ${sha1}. These properties can
be set externally, but eventually a mechanism will be created in Maven
where these properties can be injected in a standard way. For example
you may want to glean the current Git revision and inject that value
into ${sha1}. This is by no means a complete solution for continuous
delivery but is a step in the right direction.
I wish to upload a binary from one of the child Maven modules to Nexus. This child module tar.gz's jars from other child modules using maven assembly plugin.
question 1#: So should I add the distributionmanagement section to just that particular child module? Or should I add distributionmanagement to parent modules and all other child modules?
question#2: Is it enough to make changes to distributionmanagement and settings.xml? Or should I include "maven deploy plugin" too somewhere?
Thanks in advance.
You're not specifying where you'll be deploying the artifacts from, so I'm assuming you have some sort of CI server like Jenkins or TeamCity already installed.
question 1#: So should I add the distributionmanagement section to
just that particular child module? Or should I add
distributionmanagement to parent modules and all other child modules?
If you'd like to deploy just that module's artifact, then I would recommend you have a separate job for this in your CI server. Alternatively, when deploying from a command-line, you would need to cd in the directory of the module and only execute mvn deploy from there. And -- yes -- you will need to have the <distributionManagement/> section for sure.
question#2: Is it enough to make changes to distributionmanagement and
settings.xml? Or should I include "maven deploy plugin" too somewhere?
You will need both a <distributionManagement/> section in your pom and a properly defined <server/> section in your pom.xml. You shouldn't need to explicitly define settings for the maven-deploy-plugin, unless you need some special options.
You only need distributiionManagement in some parent pom you are inheriting from. Typically this is only set up in an organization wide top level pom. You do NOT need to have it in every project since it is inherited.
Settings has to be configured correctly.
All you need to do is call mvn deploy for the module you want to deploy.
Check out the first videos of the Nexus training video series.. it shows it all.
I know it's mauvais ton to ask twice in a single day but here's another Maven puzzler:
I have a parent POM which defines 5 modules (5 subprojects). Since each module is executed in exactly the same way I pull <profile><build> section into the parent POM to get rid of the duplicate code. Now - if I execute build individually from each module it works, however if I want to build all modules at once and move to the parent directory I got error since the very first thing Maven tries to execute is the parent project itself:
mvn package -P release
[INFO] Scanning for projects...
[INFO] Reactor build order:
[INFO] DWD Parent project
[INFO] Projects
After that build fails because exec plugin tries to execute something that is not there. Looking at the output it is pretty obvious that reactor plugin is driving the build but how can I configure reactor to skip the parent?
P.S. To prevent confusion - I'm trying to suppress profile execution on parent and enable it on child during the same build
You can't skip the parent build, but you can configure the profile to not be activated with a little hack. This answer shows how to control the activation of a profile by the presence or absence of a file-based <activation> element. This way you can define the profile in the parent, but have it deactivated in that project because of the marker file being present in the parent. Child projects would not have the marker file in their source, so the profile would be activated for those projects.
Update to clarify: On my test project this configuration means the profile is deactivated in the parent project (which has the file in src/main/resources), but activated in all child projects which do not have the file in their resources directories.
<profile>
<id>test</id>
<activation>
<file>
<missing>src/main/resources/test.marker</missing>
</file>
</activation>
...
</profile>
What is wrong by building the parent?
In fact, in Maven, there are two different concepts (which are generally used at the same time):
The parent POM
The modules aggregation
The first one is a definition of everything that is common with all the children. You define a parent as a pom-packaged project, and you can install it in your repository.
When you build a child of this parent, Maven2 will retrieve this parent to merge the parent pom with the child pom. You can have a look to the entire pom.xml by running the command mvn help:effective-pom.
In this case, the parent pom will not be built, it will just be retrieved from the repository.
The second case is a project that contains a modules list of sub-projects. The principle is that every command that you run on this project will also be run on all the sub-modules. The order of the modules will be defined by the Reactor, which will look at inter-modules dependencies to find which module must be built before the others. If there are no dependencies, then it will take the list of the modules as they are defined in the parent pom.xml.
In this case, if you run a command on the root project, Maven2 will first built the root project, and then the sub-modules. You cannot skip the creation of the root project.
Edit, thanks to RichSeller comment
A complete explanation of the differences between multi-modules (aggregation project) and inheritance (parent project) can be found in the Maven book, here.
I want to document that there's partial compromise to my situation (thanks to guys on maven users mailing list for suggestion). Basically you need to chop profile in two pieces. Reusable configuration section of plugin goes to the parent POM, and executions stays in the child POM. Then the profile plugin in the child is marked as inherited and voila - at run time parent profile is not executed since it's missing executions section. This is far from ideal but it does work. Refer to this link for example
I wasn't able to implement "missing" file solution as provided by Rick Seller above. It seems that once set active/non-active state of profile will not be changed even the marker file is missing from the module(s). However here's the exact solution to my problem. Warning: this is only available starting with Maven 2.1+
If I have a parent POM with 2 modules defined: foo and boo then in regular circumstances order of execution will be:
parent
foo
boo
All I need to do to skip parent build is to add this command line switch
mvn install –rf foo
Alternatively you can use --resume-from What it will do is to skip parent and continue from foo module down. Now - I'm investigating if this can be achieved by configuring Reactor plugin (P.S. - no it can't) but even with the switch, the above scenario works fine for me
This is implied by #romaintaz's answer to the same question, Maven - skip parent project build
but just to make this explicit, in the parent pom it's imperative that you specify the packaging element as pom (and not jar or war).
Example:
<packaging>pom</packaging>