If my pom is a child a hierarchy of other poms, is there a way to show exactly which parent pom contains the definition of a plugin?
Short answer is most probably: No.
According to the way Maven builds its model before executing a certain build, the Maven Builder Model:
In phase 1 the hierarchy of poms is resolved
In phase 2 model normalization and plugins configurations are further resolved
But only at the end of phase 2 the effective model validation is performed, which is done on the final effective pom.xml file, as a result of merges, overriding, profiling, injections (of properties) and so on.
To have a look at the full pom, the effective-pom goal of the maven-help-plugin is definitely the right tool. It will show (or write to a given file) the final effective pom a build is gonna use.
The full definition of a plugin (its executions, its global configuration and so on) can only be created once we have the effective pom, because:
the pluginManagement section in any point in the hierarchy can influence a certain plugin
The plugin section in any point in the hierarchy can also influnce it
profiles declared in any point in the hierarchy can also influence it
properties, if used as placeholders, can also play an important role
Having a look at the official Maven POM reference, we can see many entry point to influence a certain plugin definition, which will only be effective to our build once merged through the whole pom hierarchy. A definition per se would not help much since it can then be overriden/influenced further on on the hierarchy chain.
Think about the inherited element of a plugin:
true or false, whether or not this plugin configuration should apply to POMs which inherit from this one. Default value is true.
Or merging of plugin configuration sections:
The default behavior is to merge the content of the configuration element according to element name. If the child POM has a particular element, that value becomes the effective value. if the child POM does not have an element, but the parent does, the parent value becomes the effective value.
You can control how child POMs inherit configuration from parent POMs by adding attributes to the children of the configuration element. The attributes are combine.children and combine.self. Use these attributes in a child POM to control how Maven combines plugin configuration from the parent with the explicit configuration in the child.
Or further down per execution of a plugin:
inherited: Like the inherited element above, setting this false will supress Maven from passing this execution onto its children. This element is only meaningful to parent POMs.
The overall management can then be influenced by pluginManagement:
Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one. However, this only configures plugins that are actually referenced within the plugins element in the children. The children have every right to override pluginManagement definitions.
As such, the plugin definition at a certain point of the pom hierarchy may not be meaningful to the final effective build.
Related
We have 6 child modules, and all of them have same values for & . But slight addition in jvmArguments for few modules.
I want to extract this out into a common place either parent pom or a property file.
what i have done is
<mymodule-jvmArguments>long list of props</mymodule-jvmArguments>
in parent pom and use this property in child modules.
so whereever there is additional propeties, it would be like
<jvmArguments>
additional properties
${mymodule-jvmArguments}
</jvmArguments>
Is this something advisable? Please suggest if there is a better means to handle shared properties. Thanks in advance
child pom sample properties
<jvmArguments>
-DmyAppp1.host=${local.base.url}:${myAppp1.port}
-DmyAppp2.host=${local.base.url}:${myAppp2.port}
-DSENSITIVE_CONFIG_PATH1=${project.parent.parent.basedir}/foo1/bar1
-DSENSITIVE_CONFIG_PATH1=${project.parent.parent.basedir}/foo1/bar1
-DDSENSITIVE_CONFIG_PATH3=${project.parent.parent.basedir}/foo3/bar3
-DDSENSITIVE_CONFIG_PATH4=${project.parent.parent.basedir}/foo4/bar4
-DCOMMON_SENSITIVE_PATH=${project.parent.parent.basedir}/foo/common
</jvmArguments>
I have work with maven for some time but I am not sure if it is always recommended to write the artifact id at the end of the group id although it is repetitive as maven coordinates would include the concatenation of the group id, the artifact id, and the version.
For example, givin a java project with package com.example.helloword I always do:
<groupId>com.example.helloword</groupId>
<artifactId>hello-word</artifactID>
<version>0.0.1-SNAPSHOT</version>
It is there a case in which it is preferred not to put the artifact id in the group id, what come to my mind is if the project is a shared module. For instance, a utility module used with helloword:
<groupId>com.example.helloword</groupId>
<artifactId>utilities</artifactID>
<version>0.0.1-SNAPSHOT</version>
Is it correct? or should I append also the artifact id to the group id?
You should not append the artifactId to the groupId. GroupIds are used to gather different, related artifacts. You do not create your own groupId for each and every artifact.
It is usually a good idea to begin the package names with the groupId. But package names can (and usually are) longer.
Generally speaking you should not append the artifactId on the groupId.
But I think it depends a bit on the size of the project.
As the Maven documentation on naming says
A good way to determine the granularity of the groupId is to use the project structure. That is, if the current project is a multiple module project, it should append a new identifier to the parent's groupId. For example,
org.apache.maven, org.apache.maven.plugins, org.apache.maven.reporting
I am interested in showing private members in javadoc for only certain packages. For the all other packages only show public and protected members in javadoc. The show tag is for configuration, but not for the group.
Thank You
According to Apache Maven Javadoc Plugin it uses javadoc - The Java API Documentation Generator. I'm not aware of an option in javadoc for changing access modifiers for indivdual packages with the standard doclet. You could write your own doclet, of course.
I can also imagine the following hack:
create a "main" JavaDoc with a certain access modifier and assign the desired packages
create a second JavaDoc with a different access modifier and assign the desired packages
create a third ...
Now the hacker's part:
merge the second JavaDocs' allclasses-[frame|noframe].html (All Classes) into main's allclasses-[frame|noframe].html
merge the second JavaDocs' overview-frame.html (Packages) into main's overview-frame.html
merge the third ...
merge the third ...
I am trying to find an authoritative list of which elements get inherited from a parent POM. Based on this page
When you inherit a POM, you can choose to live with the inherited POM information or to selectively override it. The following is a list of items a Maven POM inherits from its parent POM:
identifiers (at least one of groupId or artifactId must be overridden.)
dependencies
developers and contributors
plugin lists
reports lists
plugin executions (executions with matching ids are merged)
plugin configuration
But when I see the effective POM in one of my projects I see it also inherits inceptionYear, description (which is a problem, this should be a description of the POM that contains it, not of its children. What's the point of all children having a description like "The root of all POMs")
So is there an actual list or does it just inherit everything from the parent pom? i use some of these properties in the artifact's manifest so I want to add meaningful values
The child pom inherits everything from the parent pom. If you need to set meaningful values in the child pom then you will need to override the values in the parent pom.
From the Docs:
When a project specifies a parent project, Maven uses that parent POM
as a starting point before it reads the current project’s POM. It
inherits everything, including the groupId and version number.
Most elements from the parent POM are inherited by its children. Two elements that aren't inherited are artifactId & name. (Also, any plugins which explicitly set <inherited>false)
Is it possible to do string and math operations on properties in maven 2?
I have a property ${version} that has a value of something like 5.3.0-SNAPSHOT, now I'd like to extract the 5 and do some math on it, say subtract 3 from it. So my new property would get the value 2.
You may want to look at the parse-version goal of build helper maven plugin. As the example in this page indicates, once this goal is run, it makes available a bunch of propeties which can be used to do subsequent operations.
parsedVersion.majorVersion
parsedVersion.minorVersion
parsedVersion.incrementalVersion
parsedVersion.qualifier
parsedVersion.buildNumber
There is an example here (http://ronalleva.com/groovy/maven/programming/2008/01/23/using-the-groovy-maven-plugin-to-do-magic.html) which embeds groovy into your plugin. Further in the example he sets a property in the maven project.