Macros para configuración de compilador Maven

Pueden configurarse las compilaciones Maven para producir distribuciones alternativas, incluyendo aliases adicionales dentro de metadatos del paquete o creando subpaquetes separados para ciertos artefactos.

Instalar artefactos adicionales

It is possible to explicitly request an installation of any Maven artifact (JAR / POM file). Macro %mvn_install only knows about Maven artifacts that were created during execution of %mvn_build. Normally, any other artifacts which were built by some other method would need to be installed manually. %mvn_build macro does not even need to be used at all. Luckily, all artifacts created outside of %mvn_build can be marked for installation with %mvn_artifact macro. This macro creates configuration for %mvn_install.

Solicitar instalación de artefacto Maven
%prep
...
# Solicita instalación de archivos POM y JAR
%mvn_artifact subpackage/pom.xml target/artifact.jar
# Solicita instalación de artefacto POM (ningún archivo JAR)
%mvn_artifact pom.xml
# Solicita instalación para archivo JAR especificado por las coordinadas del artefacto
%mvn_artifact webapp:webapp:war:3.1 webapp.war
spec

Asignaciones Adicionales

The macro %mvn_alias can be used to add additional mappings for given POM / JAR file. For example, if the POM file indicates that it contains groupId commons-lang, artifactId commons-lang, this macro ensures that we also add a mapping between groupId org.apache.commons and the installed JAR / POM files. This is necessary in cases where the groupId or artifactId may have changed, and other packages might require different IDs than those reflected in the installed POM.

Añadiendo más asignaciones para ficheros de ejemplo para JAR/POM
%prep
...
%mvn_alias "commons-lang:commons-lang" "org.apache.commons:commons-lang"
spec

Nombres de Fichero JAR Alternativo

In some cases, it may be important to be able to provide symbolic links to actual JAR files. This can be achieved with %mvn_file macro. This macro allows packager to specify names of the JAR files, their location in %{_javadir} directory and also can create symbolic links to the JAR files. These links can be possibly located outside of the %{_javadir} directory.

Añadiendo enlaces simbólicos de archivo para compatibilidad
%prep
...
%mvn_file :guice google/guice guice
spec

This means that JAR file for artifact with ID "guice" (and any groupId) will be installed in %{_javadir}/google/guice.jar and there also will be a symbolic links to this JAR file located in %{_javadir}/guice.jar. Note the macro will add .jar extensions automatically.

Único Artefacto Por Paquete

If the project consists of multiple artifacts, it is recommended to install each artifact to the separate subpackage. The macro %mvn_build -s will generate separate .mfiles file for every artifact in the project. This file contains list of files related to specific artifact (typically JAR file, POM file and metadata). It can be later used in %files section of the spec file.

Creando un subpaquete para cada artefacto generado
...
%description
Las Herramientas de Complemento Maven contiene...

%package -n maven-plugin-annotations
Sumario:        Anotaciones de complemento Maven en Java 5

%description -n maven-plugin-annotations
Este paquete contiene anotaciones de Java 5 para utilizar en Mojos.

%package -n maven-plugin-plugin
Sumario:        Complemento Maven

%description -n maven-plugin-plugin
El Plugin Plugin se utiliza en…
…

%build
%mvn_build -s

%install
%mvn_install

%files -f .mfiles-maven-plugin-tools
%doc LICENSE NOTICE
%files -n maven-plugin-annotations -f .mfiles-maven-plugin-annotations
%files -n maven-plugin-plugin      -f .mfiles-maven-plugin-plugin
%files -f .mfiles-javadoc
...
spec

Asignación de los Artefactos Maven para los Subpaquetes

The macro %mvn_package allows maintainer to specify in which exact package the selected artifact will end up. It is something between singleton packaging, when each artifact has its own subpackage and default packaging, when all artifacts end up in the same package.

Asignar múltiples artefactos para subpaquete único
...
%prep
%mvn_package ":plexus-compiler-jikes"   plexus-compiler-extras
%mvn_package ":plexus-compiler-eclipse" plexus-compiler-extras
%mvn_package ":plexus-compiler-csharp"  plexus-compiler-extras

%build
%mvn_build

%install
%mvn_install

%files -f .mfiles
%files -f .mfiles-plexus-compiler-extras
%files -f .mfiles-javadoc
spec

In above example, the artifacts plexus-compiler-jikes, plexus-compiler-eclipse, plexus-compiler-csharp will end up in package named plexus-compiler-extras. If there are some other artifacts beside these three mentioned (e.g. some parent POMs), then these will all end up in package named %{name}.

%mvn_package macro supports wildcards and brace expansions, so whole %prep section from previous example can be replaced with single line: %mvn_package ":plexus-compiler-{jikes,eclipse,csharp}" plexus-compiler-extras.

It is possible to assign artifacts into a package called __noinstall. This package name has a special meaning. And as you can guess, artifacts assigned into this package will not be installed anywhere and the package itself will not be created.

Skipping installation of an artifact
%prep
...
%mvn_package groupId:artifactId __noinstall
spec

Modifying XMvn configuration from within spec file

Some packages might need to modify XMvn’s configuration in order to build successfully or from other reasons. This can be achieved with mvn_config macro. For example, some old package can use enum as an identifier, but it is also keyword since Java 1.5. Such package will probably fail to build on current systems. This problem can be easily solved by passing -source 1.4 to the compiler, so one could add following line to the spec file:

Overriding default XMvn configuration
%prep
...
%mvn_config buildSettings/compilerSource 1.4
spec

XMvn’s configuration is quite complex, but well documented at the project’s official website. The website should always be used as a primary source of information about XMvn configuration.

Read about XMvn’s configuration basics and see the full configuration reference.

All %mvn_ macros have their own manual page which contains details on how to use them. All possible options should be documented there. These manual pages should be considered most up to date documentation right after source code. Try for example man mvn_file. These pages are also included in the Appendix.