maven

package
v0.23.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 18 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package maven implements Maven build tool support for Java projects. Ported from pombump with enhancements for the unified omnibump architecture.

Index

Constants

View Source
const (

	// MaxPatchFileSize limits patch/properties file size to prevent resource exhaustion.
	MaxPatchFileSize = 10 * 1024 * 1024 // 10 MB

	// MaxPomFileSize limits POM file size to prevent resource exhaustion.
	MaxPomFileSize = 10 * 1024 * 1024 // 10 MB
)

Default scope and type for a dependency.

View Source
const (
	// DefaultManifestFile is the conventional Maven POM filename.
	DefaultManifestFile = "pom.xml"
)

Variables

View Source
var (

	// ErrInvalidVersion is returned when a version string fails validation.
	ErrInvalidVersion = errors.New("invalid version string")

	// ErrPomNotFound is returned when pom file is not found.
	ErrPomNotFound = errors.New("pom file not found")

	// ErrPropertyValidationFailed is returned when property validation fails.
	ErrPropertyValidationFailed = errors.New("property validation failed")

	// ErrRemoteAnalysisNotImplemented is returned when remote analysis is not implemented.
	ErrRemoteAnalysisNotImplemented = errors.New("remote analysis not yet implemented")

	// ErrMissingRequiredFields is returned when a dependency is missing groupId or artifactId.
	ErrMissingRequiredFields = errors.New("missing required fields for dependency")

	// ErrNotMavenPOM is returned when a file is not a valid Maven POM.
	ErrNotMavenPOM = errors.New("file is not a valid Maven POM")

	// ErrNoPOMsFound is returned when no Maven POM files are found in the project tree.
	ErrNoPOMsFound = errors.New("no Maven POM files found")
)
View Source
var (
	// ErrProjectNil is returned when a POM project is nil.
	ErrProjectNil = errors.New("project is nil")

	// ErrFileTooLarge is returned when a file exceeds size limits.
	ErrFileTooLarge = errors.New("file too large")

	// ErrInvalidDependencyFormat is returned when a dependency string has invalid format.
	ErrInvalidDependencyFormat = errors.New("invalid dependencies format")

	// ErrInvalidPropertyFormat is returned when a property string has invalid format.
	ErrInvalidPropertyFormat = errors.New("invalid properties format")

	// ErrPropertyNotFound is returned when a property patch cannot be applied to
	// the current POM or its local parent POM chain.
	ErrPropertyNotFound = errors.New("property not found")

	// ErrUnsafePomPath is returned when an update would write outside the
	// configured Maven project root. It is an alias for pathutil.ErrUnsafePath.
	ErrUnsafePomPath = pathutil.ErrUnsafePath

	// ErrVersionConflict is returned when two updates try to set different
	// versions for the same dependency or property-backed dependency set.
	ErrVersionConflict = errors.New("conflicting version update detected")
)

Functions

func IsMavenPom

func IsMavenPom(path string) (bool, error)

IsMavenPom reports whether path is a Maven POM by parsing the XML and checking that the root element is <project> with the Maven namespace. Returns an error if the file cannot be opened or is not valid XML.

func ParsePom

func ParsePom(pomPath string) (*gopom.Project, error)

ParsePom parses a POM file and returns a gopom.Project.

func PatchProject

func PatchProject(ctx context.Context, project *gopom.Project, patches []Patch, propertyPatches map[string]string) (*gopom.Project, error)

PatchProject applies dependency and property patches to a parsed pom.xml. project is a gopom.Project — a Go struct that mirrors the Maven POM XML schema and can be round-tripped back to XML via project.Marshal().

func UpdatePom

func UpdatePom(ctx context.Context, pomPath string, patches []Patch, properties map[string]string) ([]byte, error)

UpdatePom updates a POM file with the given patches and properties. Returns the marshaled XML content of the updated POM.

Types

type Maven

type Maven struct{}

Maven implements the BuildTool interface for Maven projects.

func (*Maven) Detect

func (m *Maven) Detect(ctx context.Context, dir string) (bool, error)

Detect checks if a Maven project is present in the directory.

func (*Maven) GetAnalyzer

func (m *Maven) GetAnalyzer() analyzer.Analyzer

GetAnalyzer returns the Maven analyzer.

func (*Maven) GetManifestFiles

func (m *Maven) GetManifestFiles() []string

GetManifestFiles returns Maven manifest files.

func (*Maven) Name

func (m *Maven) Name() string

Name returns the build tool identifier.

func (*Maven) Update

func (m *Maven) Update(ctx context.Context, cfg *languages.UpdateConfig) error

Update performs dependency updates on a Maven project.

func (*Maven) Validate

func (m *Maven) Validate(ctx context.Context, cfg *languages.UpdateConfig) error

Validate checks if the updates were applied successfully.

type MavenAnalyzer

type MavenAnalyzer struct{}

MavenAnalyzer implements the Analyzer interface for Maven projects. Ported from pombump/pkg/analyzer.go.

func (*MavenAnalyzer) Analyze

func (ma *MavenAnalyzer) Analyze(ctx context.Context, projectPath string) (*analyzer.AnalysisResult, error)

Analyze performs dependency analysis on a Maven project.

func (*MavenAnalyzer) AnalyzeRemote

func (ma *MavenAnalyzer) AnalyzeRemote(ctx context.Context, files map[string][]byte) (*analyzer.RemoteAnalysisResult, error)

AnalyzeRemote performs dependency analysis on remotely-fetched Maven pom.xml files. files is a map from relative path (e.g. "pom.xml", "parent/pom.xml") to file content.

func (*MavenAnalyzer) RecommendStrategy

func (ma *MavenAnalyzer) RecommendStrategy(ctx context.Context, analysis *analyzer.AnalysisResult, deps []analyzer.Dependency) (*analyzer.Strategy, error)

RecommendStrategy suggests whether to use properties or direct patches.

type Patch

type Patch struct {
	GroupID    string `json:"groupId" yaml:"groupId"`
	ArtifactID string `json:"artifactId" yaml:"artifactId"`
	Version    string `json:"version" yaml:"version"`
	Scope      string `json:"scope,omitempty" yaml:"scope,omitempty"`
	Type       string `json:"type,omitempty" yaml:"type,omitempty"`
	// Classifier selects which classifier variants of an artifact the patch
	// governs:
	//   - unset/empty: every variant — the classifier-less dependency and all
	//     classifier'd ones (e.g. all of netty's native transports at once).
	//   - "none" (classifierNone): only the classifier-less dependency. Use this
	//     to pin just the plain artifact when classifier'd siblings also exist.
	//   - a value (e.g. osx-x86_64): only that exact classifier.
	Classifier string `json:"classifier,omitempty" yaml:"classifier,omitempty"`
}

Patch represents a Maven dependency patch. Ported from pombump/pkg/patch.go.

type PatchList

type PatchList struct {
	Patches []Patch `json:"patches" yaml:"patches"`
}

PatchList represents a list of patches from a YAML file.

type PropertyList

type PropertyList struct {
	Properties []PropertyPatch `json:"properties" yaml:"properties"`
}

PropertyList represents a list of property patches from a YAML file.

type PropertyPatch

type PropertyPatch struct {
	Property string `json:"property" yaml:"property"`
	Value    string `json:"value" yaml:"value"`
}

PropertyPatch represents a property override.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL