djangofan
djangofan

Reputation: 29669

Is it possible for Maven to dynamically set project name based on Git branch name?

If I have a project in a Git repository, like so:

  [project.git]/tests/pom.xml

And the project has 2 branches, lets say master and develop .

In that instance I develop code in develop and I periodically merge into master.

So, I want to be able to import my Maven project into Eclipse (from the same exact codebase) and have Eclipse name the projects distinct from each other. If I import the project from both branchs, I want Eclipse to show me 2 distinct projects in my Eclipse "project explorer".

So, if I wanted to have the projects be called:

developTests
masterTests

Is this realistic? Can this be done? Can the name property in my pom.xml be dynamic so it can detect the branch name and use it as part of the project name in Eclipse?

Upvotes: 1

Views: 830

Answers (2)

Martin Baumgartner
Martin Baumgartner

Reputation: 3652

1.) Did you try EGit? It displays the branch quite well.

2.) These are just thoughts: Add gmaven-plugin to your pom and use it to determine the branch name. At the end of the groovy-script use

project.properties['project.git.branch']=branchname;

to save your branch name as property.

Next, go to File-Import-Existing Maven Projects, in the advanced section as nametemplate enter: [project.git.branch][artifactId]

I found a groovy get branch example, maybe you can fit the parts together?

Disadvantage: I am pretty sure, the eclipse project name will not update dynamically.

Import-Maven-Project

Upvotes: 2

carlspring
carlspring

Reputation: 32617

You cannot do this through Maven. To do it, you will need to change the artifactId (which is what Eclipse will use to figure out what name to set for the project). That may be a bad idea in the fact that if other projects are depending on it, you'll have to change it there as well.

You also cannot use a property for the project's name (artifactId), because as far as I recall, you need that set before the interpolation of values.

So -- no, I don't think you can.

Upvotes: 1

Related Questions