I would like to create a Maven Parent POM file with a groupId of com.company.maven, which gives its children a default groupId of com.company. Is this possible? If so, how can I accomplish this?
Just create the parent pom like:
<project...>
<groupId>com.company.maven</groupId>
<artifactId>parent</artifactId>
<version>..</version>
...
</project>
and define in the child pom:
<project...>
<parent>
<groupId>com.company.maven</groupId>
<artifactId>parent</artifactId>
<version>..</version>
</parent>
<groupId>com.company</groupId>
</project>
In other words it's possible to do so but i wouldn't do it cause i would have named the parent "com.company" whereas the child "com.company.maven". I would compare the groupId with the java package name which represent folders so your idea of setting the groupId doesn't make sense.
I don't think this is possible. Also, it flies in the face of the Maven Guide to Naming Conventions, which recommends that (if anything), the child modules should append to the parent groupId, not vice versa.
Like a java class, that doesn't know "its" subclasses, a parent pom does not know its child poms. So the parent pom will not be able to set or overwrite attributes of it's children.
Related
We are using a parent pom that has a child module where we have 2 pom files - the one named pom.xml and other being images-pom.xml.
This is the situation because we are doing some naming changes and for the time being we want to have them both.
In our parent pom we have the following code
<modules>
<module>child</module>
</modules>
<packaging>pom</packaging>
By default it seems that this is looking and trying to build the pom.xml - but in reality we want to use the images-pom.xml Is there any way to achieve this without creating a new module and using profiles?
I have a Parent POM that has a Child mentioned in its <dependencies> section. Is this allowed?
Please note this is not the <dependencyManagement> section but the <dependencies> section itself, so that any child inheriting from this parent will have all these dependencies available for them by default.
However, these children that are part of the <dependencies> section of the parent, have to somehow exclude themselves from the parent when they are built?, Is this possible?
Currently, the child builds are failing saying that they are referencing themselves from the dependencies section of the parent.
The reason why we have these children as part of the parent's dependencies section is because these dependencies have to be available by default for the other children of the parent implicitly.
Any suggestions / help is much appreciated!
You cannot use modules as dependencies in the parent POM.
The modules need to declare their dependencies to other modules themselves.
I have a single Git repository that contains several Maven modules, using Maven inheritance and Maven aggregation. That is, in the root directory, there is a parent POM, that defines some modules, each of which use that root POM as their parent.
<project>
…
<groupId>io.example</groupId>
<artifactId>parent</artifactId>
<version>1.2.3-SNAPSHOT</version>
<packaging>pom</packaging>
…
<scm>
<connection>scm:git:https://bitbucket.org/example/foobar.git</connection>
<developerConnection>scm:git:https://bitbucket.org/example/foobar.git</developerConnection>
<url>https://bitbucket.org/example/foobar</url>
</scm>
…
<modules>
<module>foo</module>
<module>bar</module>
</modules>
…
I recently found out that Maven will append the module path to the <scm><url> value for each module (foo and bar above). For example, the foo submodule would get an SCM URL of https://bitbucket.org/example/foobar/foo.
So should each of my modules redeclare the <scm> section, so that the submodule POMs have the same SCM URL as the parent POM? How does the Nexus Staging Maven Plugin use this SCM information, anyway?
I have also cross-posted this at Sonatype.
Regarding your initial question in the title: It does not use it given the code provided at github. When you search for 'scm' in all .java files you have zero hits. Of course they could do some weird tricks like building the String like "s" + "c" + "m" or it is hidden in some third party dependency or...
Still I think besides an offical answer, this is the best any outsider can tell.
I am a newbie of Maven, currently reading Hadoop source code, and found something interesting in some pom.xml files:
Some of the dependency node do not contain version node at all.
Question: why is it like this?
for instance, this pom.xml.
Because specific version of dependency in parent pom.xml file
https://github.com/apache/hadoop/blob/trunk/pom.xml
Reference: https://maven.apache.org/guides/introduction/introduction-to-the-pom.html
As I commented at first, a pom file can have a parent (via inheritance) and such a parent may provide some governance and harmonization across all of its children. A classic case is to provide versioning for certain dependencies via a dependencyManagement section.
is used by POMs to help manage dependency information across all of its children. If the my-parent project uses dependencyManagement to define a dependency on junit:junit:4.0, then POMs inheriting from this one can set their dependency giving the groupId=junit and artifactId=junit only, then Maven will fill in the version set by the parent. The benefits of this method are obvious. Dependency details can be set in one central location, which will propagate to all inheriting POMs.
The mentioned pom has indeed a parent pom:
<parent>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-project-dist</artifactId>
<version>3.0.0-SNAPSHOT</version>
<relativePath>../../hadoop-project-dist</relativePath>
</parent>
Which in chain has another parent pom file which defines several dependencies as part of its dependencies management section.
If you really want to check the effective (merged) pom your build is using, you could run:
mvn help:effective-pom -Doutput=effective-pom.xml
And the maven-help-plugin will produce an additional pom as specified by the command above, merging the current pom file and all of its anchestors.
In Maven you can inherit from parents folder in order to merge or inherit some properties. This can be the version of the modules. Usually you have a "super" POM in the root folder of your project and you put there all the commons dependencies in order to controll them in an easier way. I.e. If you must change one module version, you only need to change in the "super" POM and not in each POM inside each subfolder that need it. If you need more information about POM inheritance the documentation has a couple of useful examples.
https://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Project_Inheritance
I have a project whose structure goes like this
sw
|-aim-pom.xml
|-website
|-pom.xml
|-package
|-pom.xml
My aim-pom.xml looks like this
<packaging>pom</packaging>
<properties>
<product>aim</product>
</properties>
<modules>
<module>website/package</module>
</modules>
Basically I cant seem to get the value of the property 'product' in website/package/pom.xml where I am doing some conditional logic based on it. What am I doing wrong here?
Thanks in Advance.
Do a "mvn help:effective-pom" in the "package" module to see if the property is there. If not, make sure that that module specifies aim-pom.xml (or one of its children) as its parent POM. Remember that in Maven, aggregation (modules build sub-modules via the reactor) and inheritance (POMs have other POMs as parents) are separate concepts.