English
Packaging Maven project
This step by step guide will show you how to package Maven project. Let's start with probably simplest spec file possible.
include::example$maven_project/simplemaven.spec[]
The spec file above is a real world example how it may look like for simple Maven project. Both `%build` and `%install` sections consist only of one line.
Another interesting lines:
10: BuildRequires: maven-local
All Maven projects need to have BuildRequires on `maven-local`. They also need to have Requires and BuildRequires on `jpackages-utils`, but build system adds these automatically. Package maintainer doesn't need to list them explicitly.
31: %dir %{_javadir}/%{name}
By default, resulting JAR files will be installed in `%{_javadir}/%{name}`, therefore package needs to own this directory.
The build could fail from many reasons, but one probably most common is build failure due to xref:common_errors.adoc#error_missing_dependency[missing dependencies]
We can try to remove these missing dependencies from pom.xml and make Maven stop complaining about them. However, these removed dependencies may be crucial for building of the project and therefore it may be needed to package them later. Let's remove the dependencies from `pom.xml`.
Remove dependencies from pom.xml
...
%prep
%setup -q
# Add following lines to %prep section of a spec file
%pom_remove_dep :commons-io
%pom_remove_dep :junit
Package maintainer can use a wide variety of "`pom_`" macros for modifying `pom.xml` files. See xref:pom_macros.adoc#helper_macros[Macros for POM modification] section for more information.
Now try to build the project again. The build will fail with xref:common_errors.adoc#error_compilation_failure[compilation failure].
Oops, another problem. This time Maven thought it had all the necessary dependencies, but Java compiler thinks otherwise.
Now it's possible to either patch the source code not to depend on missing libraries or to package them. Second approach is usually correct. It's not necessary to package every dependency right away. Maintainer could package compile time dependencies first and keep the rest for later (test dependencies, ...). But Maven needs to know that it shouldn't try to run tests now. This can be achieved by passing `-f` option to `%mvn_build` macro. Maven will stop complaining about missing test scoped dependencies from now on.
Another major reason to disable the test phase is to speed up the local build process. This can also be achieved by specifying an additional switch `--without=tests` to the `fedpkg` or the `mock` tool instead of adding a switch to `%mvn_build`.
Another switch `--without=javadoc` causes the build to skip Javadoc generation.