30

I'm trying to release a multi-module maven project that uses git as the SCM, and among the first problems I've encountered is the way in which the maven release plugin builds the release.properties scm.url. My parent POM looks something like this:

<packaging>pom</packaging>
<groupId>org.project</groupId>
<artifactId>project-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>

<scm>
    <connection>scm:git:git://github.com/username/project.git</connection>
    <developerConnection>scm:git:git@github.com:username/project.git</developerConnection>
    <url>http://github.com/username/project</url>
</scm>

<modules>
    <module>api</module>
    <module>spi</module>
</modules>

And the module POMs are straightforward:

<parent>
    <groupId>org.project</groupId>
    <artifactId>project-parent</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>api</artifactId>
<version>0.2.2</version>

My goal is to be able to release individual modules since they each have different versions and I don't want to increment all of the versions together each time I do a release.

When I change to the api directory and do a mvn release:clean release:prepare I'm met with the following output:

[INFO] Executing: cmd.exe /X /C "git push git@github.com:username/project.git/api master:master"
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Unable to commit files
Provider message:
The git-push command failed.
Command output:
ERROR: Repository not found.

It looks like the maven release plugin creates the scm.url by appending the module name to the developerConnection, which ends up not being a valid repository at github. I'm not sure what the right way to set this up is. It might be the case that Maven + git + releasing an individual child module simply won't work? Any input is appreciated.

Jean-Rémy Revy
  • 5,607
  • 3
  • 39
  • 65
Josh Stone
  • 4,328
  • 7
  • 29
  • 37

7 Answers7

14

I found this question with a search on "git-push command failed". I have a similar configuration where I have a master-pom and then submodules that I release as their own maven packages.

To get it to work I had to tune the scm section of the pom.xml to something like the following. The connections specifically had to be tuned right to work. None of the github ones worked at all.

<scm>
    <url>https://github.com/XXX/YYY</url>
    <connection>scm:git:ssh://git@github.com/XXX/YYY.git</connection>
    <developerConnection>scm:git:ssh://git@github.com/XXX/YYY.git</developerConnection>
</scm>

The XXX in the above example is your github username. You cannot use the :XXX format (git@github.com:XXX/...) because the value past the : is interpreted as being a port number instead. The YYY is obviously your repository name under the XXX account.

I just released all 3 of my submodules one-by-one using this pattern successfully.

Gray
  • 115,027
  • 24
  • 293
  • 354
14

To see how to make this work, have a look at a working example, such as:

https://github.com/sonatype/sonatype-aether

However, this won't help if you like to release the individual pieces. In that case, you have to just copy the <scm> elements into all the poms.

This is an active topic of discussion on the maven dev list, but don't hold your breath for a solution from there; it's a big deal.

bmargulies
  • 97,814
  • 39
  • 186
  • 310
  • 2
    It looks like that project releases from the top level POM as opposed to releasing from the individual modules as I am trying to do. The problem I am having comes up when I try to release from inside the directory of one of the modules. It is important for me to be able to release individual modules since module versions are different and I don't want to increment all module versions at the same time. – Josh Stone Jul 17 '11 at 23:49
  • 1
    I've never seen anyone do that. – bmargulies Jul 18 '11 at 00:45
  • Thanks for the info. Do you happen to have links to any of the threads on the maven dev list where this has been discussed? – Josh Stone Jul 18 '11 at 00:49
  • http://mail-archives.apache.org/mod_mbox/maven-dev/201107.mbox/ajax/%3C4E1F03BF.8090503@redhat.com%3E – bmargulies Jul 18 '11 at 01:00
  • I saw your posts on that thread. FWIW, I like the idea of defining your SCM information once and (in the parent POM) and not having Maven modify it at all. – Josh Stone Jul 18 '11 at 04:09
  • I am in exactly the same position as Josh: multimodule but want to keep module versions independent and release them independently. In my case I get "fatal: https://github.com/.git//info/refs not found: did you run git update-server-info on the server?" – Rafa Feb 01 '13 at 13:21
  • See as a parameter to the release plugin. – bmargulies May 21 '13 at 22:28
  • This mailing list link worked for me: [discussion](http://maven.40175.n5.nabble.com/SCM-info-and-modules-td4586987.html) – Jesse Glick Aug 18 '15 at 10:26
2

I was trying to do a similar thing for a long time, and never found a good solution, so wrote my own release plugin for git. It only releases changed modules, you don't need any scm config, it tags based on the module names, and inter-component dependencies work.

Documentation: http://danielflower.github.io/multi-module-maven-release-plugin/index.html

Introduction blog: http://danielflower.github.io/2015/03/08/The-Multi-Module-Maven-Release-Plugin-for-Git.html

Daniel Flower
  • 687
  • 7
  • 13
  • While using your plugin, I am getting authentication issue. How can I set the credentials for JGit without any java code. Also, is your plugin compatible with BitBucket ? – napster Apr 18 '18 at 08:04
1

For anyone that comes to this question in search of a good solution as I did, what I found that works for me is the following:

http://blog.avisi.nl/2012/02/15/maven-release-plugin-setup-guide-for-git/

You still 'tag' off the entire trunk because that's how git works but it allows to you only build/version/deploy the submodule that you want to.

Wysawyg
  • 712
  • 8
  • 22
1

A simple way, what worked for me is to use the parent properties in the modules pom.xml like follow in the scm tag like follow:

<!--module pom.xml-->
<scm>
    <connection>${project.parent.scm.connection}</connection>
    <developerConnection>${project.parent.scm.developerConnection}</developerConnection>
</scm>
toschneck
  • 770
  • 7
  • 12
0

I know this is late for a response but I ran into this same issue and the only solution where you could achieve both, a multi module maven project, and independent releases for each module is when you do the following:

  1. For the maven multi-module project setup a GIT project
  2. For each maven module in (1) add a GIT submodule in (1)
  3. Link each GIT submodule (2) to a GIT project of its own

Essentially, within git each maven module will exist as a project of its own. There will be a separate git project for the maven parent project but it will not contain the actual modules, only git submodule links to the git location where actual projects are stored.

sshekhar1980
  • 327
  • 2
  • 12
0

I answered to a related question here (multi-module with multi-repository). basically, you can use a property called commitByProject, since maven-release-plugin 2.0-beta-5, that lets you commit per project each submodule (referenced from root pom with 'git submodule add' strategy also works).

mvn release:prepare -DcommitByProject=true
le0diaz
  • 2,488
  • 24
  • 31