dcalap
dcalap

Reputation: 1072

Get inherited groupId with readMavenPom

I have a question concerning readMavenPom (Link to doc) utility from Jenkins pipelines.

I have a project with a pom.xml where no groupId is defined but this pom.xml has a parent pom with a a defined groupId. (It could happen that, even this parent doesn't have a defined groupId and is the parent.parent the one that has it).

Is there a way to get the, let's say, effective groupId in an elegant way?

I'm currently getting null with the getGroupId() method (or property accessor .groupId)

NOTE: With elegant way I mean, not looping into parents and checking if groupId is not null.

Thanks in advance.

Upvotes: 6

Views: 1006

Answers (1)

khmarbaise
khmarbaise

Reputation: 97477

You could simply use the maven-help-plugin:evaluate goal via command line which can give you what you need.

The following will exactly extract the groupId of the project and will handle all the things based on your inheritance part.

mvn help:evaluate -Dexpression=project.groupId -q -DforceStdout

This could be done in a separate stage step of the Jenkins Pipeline.

Upvotes: 2

Related Questions