Using Maven2 in Debian

From Lenny onwards, Debian will provide a Maven2 package:

Please read the page MavenBuilder if you are interested in using maven for building Debian packages.

Bootstrapping and Building Maven

Maven uses a bootstrap process to build itself. This bootstrap process actually downloads existing plugins from the Maven repository, which is not what we want to do here. And to build those plugins, you need to have the Maven libraries available.

Before (upstream build process):

[Maven package]                 [Maven repo]
     bootstrap
       |                 download
     get Maven plugins ----->clean, compile, jar, shade plugins
       |
     compile Maven code
       |
     run Maven with its plugins
       |
     generate documentation, uber jar and final distribution

After:

[Maven distribution package]  [Maven libraries package] [Maven plugins]

                                 Compile with Ant
                                      |
                             put jars in /usr/share/maven-repo
                                      |_____________________
                                                            |
                                                       compile with Ant
                                                            |
                                                        put jars in
                                                  /usr/share/maven-repo
                                                            |
          __________________________________________________|
          |
   copy maven-repo locally
          |
   run Maven with its plugins
          |
   generate uber jar and final distribution

To avoid downloading the Maven plugins from the internet, I need first to build those plugins locally, and for that I need the Maven libraries (maven-project.jar, maven-artifact.jar...). Those libraries are built in the maven2-core package and installed in /usr/share/maven-repo. Then I can build the Maven plugins (maven-clean-plugin, maven-compile-plugin, maven-jar-plugin, maven-shade-plugin and others) as they depend on the Maven libraries. Finally, I use the maven2 package, which contains only the bootstrap build code - the libraries have been moved to maven2-core. This build code builds the maven2.jar uber jar, that's a big jar which contains all Maven libraries and their dependencies but with a transformation called package shading, that is renaming the existing packages for the shared libraries to avoid namespace and version collisions in the Maven plugins at runtime. For example, org.plexus.utils package is renamed to hidden.org.plexus.utils, and all classes in this package and all code referring to this package is modified as well. So the Maven classes in org.apache.maven packages are transformed as well and do not duplicate what's already installed in /usr/share/maven-repo.

This build process is very involved in the deeper mechanisms of Maven, but the result is that the Debian distribution is now almost identical to the official distribution. The previous Debian build of Maven was quite different and missing this packaging shading step, exposing Debian to lots of issues which don't happen with the upstream distribution.

Finally, this is what's in each source tarballs. Note that I could have cleaned maven2-core better, by removing the src and apache-maven folders which are not used there.

Contents of maven2-core

./apache-maven
./debian
./maven-artifact
./maven-artifact-manager
./maven-artifact-test
./maven-cli
./maven-compat
./maven-core
./maven-core-it-runner
./maven-error-diagnostics
./maven-integration-tests
./maven-model
./maven-monitor
./maven-plugin-api
./maven-plugin-descriptor
./maven-plugin-parameter-documenter
./maven-plugin-registry
./maven-profile
./maven-project
./maven-reporting
./maven-repository-metadata
./maven-script
./maven-settings
./maven-toolchain
./src

Contents of maven2

./apache-maven
./debian
./src


CategoryJava