1

I usually define a parent pom to inherit the dependencies and the builds. Problem is that I keep getting warnings about redundant groupId, version, ecc. as it seems that my inherited pom should stick to parent's.

I don't want that: is there any way to tell maven "I want the children to be independent"?

<parent>
    <groupId>com.foo</groupId>
    <artifactId>parent</artifactId>
    <version>0.0.1-SNAPSHOT</version> <!-- this is fine -->
</parent>

<modelVersion>4.0.0</modelVersion>
<groupId>com.foo.agroup</groupId> <!-- this is not: I should keep com.foo -->
<artifactId>child</artifactId>
<version>1.0</version> <!-- this is not as well: I should keep 0.0.1-SNAPSHOT -->
Phate
  • 6,066
  • 15
  • 73
  • 138
  • You move versions from a child to a parent pom to reduce duplication. If you don't want to use that, why do you inherit from a parent pom? – Smutje Apr 06 '20 at 10:24
  • Dependency version is ok, but if my parent pom is at version 0.0.1-SNAPSHOT I don't necessarily want that my children are at that version too. – Phate Apr 06 '20 at 10:25
  • Why do you set the parent to version X if you don't want the children to inherit that version? – Smutje Apr 06 '20 at 10:26
  • I have to do that to keep trace of my collection of dependencies, properties and build. – Phate Apr 06 '20 at 10:29
  • ..i think, what you need/want (besides to a parent pom) is a (or several) "dependency import pom(s)" ..where you can compose & manage "sets" of dependencies..(?) – xerx593 Apr 06 '20 at 10:30
  • could you please provide an example? I think you're right: in my project I will generate many projects and I would like to keep the control over the version of libs they will be using. Problem with dep management is that I will not inherit properties as well – Phate Apr 06 '20 at 10:32
  • "dependency import pom": 1. Create a new (pom-only-) project "my-deps". 2. Gather, manage & configure all of the dependencies, you want to import/belongs to "my-deps" (you can think also of "my-web-deps" or "my-backend-deps"..."my-test-" ."my-common-" ... , they can also inherit.. :) 3. (a)Use "my-deps" for dependency **declaration**: `...my-depspom` + `import`. (https://stackoverflow.com/q/16894032/592355) – xerx593 Apr 06 '20 at 10:41
  • Mmm...doesn't work: the jars contained are not seen by the child project – Phate Apr 06 '20 at 11:18

1 Answers1

1

What you did in your question is perfectly right. Don't change it.

If you are not in a multi-module project, it is a common approach to not use the groupId or version of the parent. We do this all the time.

I just wonder where you warnings come from. Are they in the Maven build? Or in Eclipse?

Could be please copy/paste them so we can inspect them.

Summarised: Your POM is fine, the warnings are just noise or rubbish (as long as you are not in a multi-module project).

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • I'm not, those warning come from Eclipse/IntelliJ IDEs. So are you saying I can safely ignore them? Is there a way to prevent them from showing such as ignore warnings in java code? – Phate Apr 06 '20 at 11:46
  • I only know warnings that show up when you write _exactly the same_ groupId, not when you write a different one. Could you add a screenshot to your question? – J Fabian Meier Apr 06 '20 at 11:51
  • Didn't notice I had replaced it by error with the parent. Thanks for the answer, now I think I understand a little more :) – Phate Apr 06 '20 at 12:11