How to package software built with Maven in Debian

It's actually quite easy, since Maven gives lots of information about a project, in particular its list of dependencies. So if your project has already all its dependencies packaged for Debian, and with the correct Maven metadata, then it's a piece of cake!

So for example I want to package Jakarta Commons Exec. I search for the SVN url pointing to the latest release of this library in the project pages, find http://svn.apache.org/repos/asf/commons/proper/exec/tags/EXEC_1_0_1/, then I run:

> mh_make --from-svn=http://svn.apache.org/repos/asf/commons/proper/exec/tags/EXEC_1_0_1/

Environment variable DEBLICENSE not set, using GPL-3+ by default
Enter the name of the new Debian source package. If empty, it will defaults to exec
>
Enter the name of the binary package. If empty, it will defaults to libexec-java
>
Enter y (yes) or n (no) to run tests while building the package. Defaults to no
>y
Enter y (yes) or n (no) to generate the Javadoc while building the package. Defaults to no
>y
A    exec
A    exec/NOTICE.txt
A    exec/LICENSE.txt
A    exec/doap_exec.rdf
[...]
Exporté à la révision 957046.
This plugin may be ignored in some cases. Ignore this plugin?
  org.apache.maven.plugins:maven-assembly-plugin:maven-plugin:2.2-beta-4
[y]/n > y
This dependency cannot be found in the Debian Maven repository. Ignore this dependency?
  org.apache.maven.plugins:maven-changes-plugin:maven-plugin:2.0
[y]/n > y
This plugin may be ignored in some cases. Ignore this plugin?
  org.codehaus.mojo:findbugs-maven-plugin:maven-plugin:1.2
[y]/n > y
This dependency cannot be found in the Debian Maven repository. Ignore this dependency?
  org.codehaus.mojo:cobertura-maven-plugin:maven-plugin:2.0
[y]/n > y
WARNING:
pom.xml: Dependency is not packaged in the Maven repository for Debian: org.apache.maven.plugins:maven-changes-plugin:2.0
pom.xml: Dependency is not packaged in the Maven repository for Debian: org.codehaus.mojo:cobertura-maven-plugin:2.0
--------
[INFO]
NOTE: Maven is executing in offline mode. Any artifacts not already in your local
repository will be inaccessible.

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Commons Exec
[INFO]    task-segment: [org.debian.maven:maven-packager-utils:1.0:generate] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [packager-utils:generate {execution: default-cli}]
Cannot locate the version in the download url (http://svn.apache.org/repos/asf/commons/proper/exec/tags/EXEC_1_0_1/).
Please run again and provide the download location with an explicit version tag, e.g.
-DdownloadUrl=scm:svn:http://svn.codehaus.org/modello/tags/modello-1.0-alpha-21/
> chmod +x debian/rules
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7 seconds
[INFO] Finished at: Tue Jun 22 23:51:52 CEST 2010
[INFO] Final Memory: 10M/138M
[INFO] ------------------------------------------------------------------------
>

That's it. Now I have a debian folder, and it contains changelog, control, rules, copyright and a few other files. My package is ready! Ok, I need to file an ITP, fix the copyright, the watch file was not generated because the download url does not contain an easily recognizable version, but most of the job is done. The package can be installed, there is even a documentation package, and all is in the proper place.

mh_make should works on most upstream sources packaged with Maven 2, and there is even this neat option, --from-svn, where it can download the sources for you and build sometimes the watch file.