craft_parts.utils.maven.common module

Utilities for Maven projects and settings.

class craft_parts.utils.maven.common.MavenArtifact(group_id, artifact_id, version, packaging_type, field_name='Dependency')[source]

Bases: object

A dataclass for Maven artifacts.

Parameters:
  • group_id (str)

  • artifact_id (str)

  • version (str | None)

  • packaging_type (str | None)

  • field_name (str)

artifact_id: str
field_name: str = 'Dependency'
classmethod from_element(element, namespaces)[source]

Create a MavenArtifact from an XML artifact element.

Parameters:
  • element (_Element)

  • namespaces (dict[str | None, str])

Return type:

Self

classmethod from_pom(pom)[source]

Create a MavenArtifact from a pom file.

Parameters:

pom (Path)

Return type:

Self

group_id: str
packaging_type: str | None
classmethod update_versions(project, namespaces, existing)[source]

Update all of the versions for this project as necessary.

Parameters:
  • project (_Element)

  • namespaces (dict[str | None, str])

  • existing (dict[str, dict[str, set[MavenArtifact]]])

Return type:

None

version: str | None
class craft_parts.utils.maven.common.MavenParent(group_id, artifact_id, version, packaging_type, field_name='Parent')[source]

Bases: MavenArtifact

A dataclass for the Maven parent tag.

Parameters:
  • group_id (str)

  • artifact_id (str)

  • version (str | None)

  • packaging_type (str | None)

  • field_name (str)

field_name: str = 'Parent'
class craft_parts.utils.maven.common.MavenPlugin(group_id, artifact_id, version, packaging_type, field_name='Plugin')[source]

Bases: MavenArtifact

A dataclass for Maven plugins.

These are different because plugins have a default groupId.

Parameters:
  • group_id (str)

  • artifact_id (str)

  • version (str | None)

  • packaging_type (str | None)

  • field_name (str)

field_name: str = 'Plugin'
classmethod from_element(element, namespaces)[source]

Create a MavenPlugin from an XML plugin element.

If no groupId is found, ‘org.apache.maven.plugins’ will be used.

For more information on the default plugin group, see: https://maven.apache.org/guides/mini/guide-configuring-plugins.html

Parameters:
  • element (_Element)

  • namespaces (dict[str | None, str])

Return type:

Self

classmethod update_versions(project, namespaces, existing)[source]

Update all of the versions for this project as necessary.

Parameters:
  • project (_Element)

  • namespaces (dict[str | None, str])

  • existing (dict[str, dict[str, set[MavenArtifact]]])

Return type:

None

exception craft_parts.utils.maven.common.MavenXMLError(message, details=None)[source]

Bases: BaseException

An error encountered while parsing XML for Maven projects.

Parameters:
  • message (str)

  • details (str | None)

details: str | None = None
message: str
craft_parts.utils.maven.common.create_maven_settings(*, part_info, set_mirror)[source]

Create a Maven configuration file.

The settings file contains additional configuration for Maven, such as proxy parameters and a reference to the backstage repository.

Parameters:
  • part_info (PartInfo) – The part info for the part invoking Maven.

  • set_mirror (bool) – Whether to configure for a local build.

Return type:

Path

Returns:

Returns a Path object to the newly created settings file.

craft_parts.utils.maven.common.update_pom(*, part_info, deploy_to, self_contained, pom_file=None)[source]

Update the POM file of a Maven project.

Parameters:
  • part_info (PartInfo) – Information about the invoking part.

  • deploy_to (Path | None) – The path to configure the mvn deploy location. If None, no path is configured.

  • self_contained (bool) – Whether or not to patch version numbers with what is actually available.

  • pom_file (Path | None) – The optional Maven POM file to update. If None, the function will try to use pom.xml on the part’s build subdir.

Return type:

None