Atlas Robotics
ROS2 PackageIntermediate

package.xml — the manifest of a ROS2 package

Atlasbot · 17/8/2026 · 11 min read

package.xml — the manifest of a ROS2 package
Main tags in package.xml and the role of each depend

Of the two configuration files of a package (CMakeLists.txt/setup.py and package.xml), package.xml is the only file that is required for every package, regardless of C++ or Python. This is the manifest so that colcon, rosdep and other ROS2 tools understand what your package is and what it needs to run.

Key concepts

<?xml version="1.0"?>
<package format="3">
  <name>my_cpp_pkg</name>
  <version>0.0.1</version>
  <description>Package mẫu minh hoạ package.xml</description>
  <maintainer email="[email protected]">Tên bạn</maintainer>
  <license>Apache-2.0</license>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <depend>rclcpp</depend>
  <depend>std_msgs</depend>

  <test_depend>ament_lint_auto</test_depend>

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>
  • name / version / description / maintainer / license — identifier, rosdep/packaging tool used to look up
  • buildtool_depend — build tool to use (ament_cmake or ament_python), matches --build-type at ros2 pkg create
  • export> <build_type> — this line is what actually decides how colcon builds the package, must match buildtool_depend above

How it works

Three (actually four) commonly confused types of dependencies:

TagWhen do you needFor example
<depend>Used when building and when runningrclcpp, std_msgs
<build_depend>Only needed when building, not needed when runningheader-only library is only used to compile
<exec_depend>Only needed when running, not needed when buildinga Python node calling another package via ros2 run, no static link
<test_depend>Only needed when running testament_lint_auto, ament_cmake_gtest

In most practical cases, only <depend> is needed — it is equivalent to declaring both build_depend and exec_depend at the same time, safe to use when not sure at what stage the dependency is needed.

In short: <depend> is wrong or missing, don't do CMakeLists.txt/setup.py report an error immediately — it silently causes colcon build to miscalculate the build order between packages, or causes rosdep install to miss a system library that needs to be installed. This is the reason why package.xml should be fully declared from the beginning, not left "for later".

rosdep uses package.xml to install system dependencies:

cd ~/ros2_ws
rosdep install --from-paths src --ignore-src -r -y

This command scans all package.xml in src/, looks up each <depend> in the rosdep database to know which system package (via apt) needs to be installed accordingly.

Technical details

Parameters

In addition to the tags mentioned, the current package.xml format also supports some less common but useful tags:

Tag/ParameterMeaning
format="3" (attribute <package>)Current format, fully supporting the listed dependencies
format="1" (old, not recommended)Regardless of dependency type, all dependencies are treated as <depend>
<doc_depend>Dependency is only needed when generating documents, rarely used
<buildtool_export_depend>Buildtool dependency needs to be "exported" for another package to reuse your library

Practical applications

In the CI/CD process of building Docker images for robots, the package.xml of the entire workspace is often used as the only source to automatically generate a list of system settings — the CI script runs rosdep install right while building the Docker image, ensuring the image is always correctly installed and has enough dependencies according to the declaration in the code, no need to maintain a manual apt install list in parallel that is easily out of sync compared to actual dependency in package.xml every time a new package is added.

Practical example

$ rosdep install --from-paths src --ignore-src -r -y
Output:
#All required rosdeps installed successfully

reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit https://raw.githubusercontent.com/ros/rosdistro/...
executing command [apt-get install -y libpcl-dev]
executing command [apt-get install -y ros-humble-nav2-msgs]

rosdep automatically translates the ROS2 dependency name (eg: nav2_msgs) to the correct system apt package name (ros-humble-nav2-msgs) — avoiding having to manually look up and manually type each apt install command for dozens of dependencies of a large workspace.

Common mistakes

  • Missing <depend> for a package actually used in the code — build can still succeed if that dependency is already installed on the dev machine, but colcon will miscalculate the build order and rosdep install miss it on another machine — silent error, only revealed when deploying to a new environment.
  • <export><build_type> does not match <buildtool_depend> — For example: declared buildtool_depend as ament_python but export/build_type recorded as ament_cmake — causing colcon to build the wrong package type, a confusing error because it looks like a Python package but is handled like C++.
  • Forgot to update <version> when releasing new version — with packages used for distribution/packaging, the version mismatch between package.xml and the git tag actually causes confusion when tracing errors between versions.
  • Blank <license> — some packaging/compliance tools will warn or reject packages that lack license information when building for general distribution.

Conclusion

package.xml is the only required file of every ROS2 package, acting as a "passport" to declare dependencies for both colcon (calculates build order) and rosdep (installs system dependencies). Declaring the correct type of dependencies (build/exec/test) from the beginning avoids many silent errors that only reveal themselves when deployed in another environment. The next article in this category is about Launch File — how to launch multiple nodes at the same time with the right parameters, instead of having to manually type each command ros2 run.

Get new articles and lessons by email

When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.

Unsubscribe any time with the link in each email. See our Privacy policy.

package.xml — the manifest of a ROS2 package — Atlas Robotics