mvn-skills

module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT

README ΒΆ

mvn-skills β€” Maven SDK for Go

CI Release Go Reference Go Report Card

Language: English | δΈ­ζ–‡

A Go SDK for conveniently operating Maven (mvn) in Go applications. It detects and uses the locally installed Maven to execute commands, parse POM files, manage settings, and more.

Features

  • πŸ” Maven Finder β€” Auto-detect Maven from PATH, M2_HOME, or Maven Wrapper
  • πŸ“¦ Command Builder β€” Fluent API with 30+ Maven CLI options
  • πŸ“„ POM Parser β€” Parse and analyze pom.xml files
  • βš™οΈ Settings Parser β€” Parse Maven settings.xml
  • πŸ—‚οΈ Local Repository β€” Navigate and search the local Maven repository
  • πŸ“₯ Maven Installer β€” Download and install Maven on Linux/macOS/Windows
  • πŸ—οΈ Context Support β€” Cancel and timeout Maven commands via context.Context
  • πŸ–₯️ Cross-Platform β€” Full Windows, macOS, and Linux support

Installation

go get github.com/scagogogo/mvn-skills
Specific Version
go get github.com/scagogogo/mvn-skills@v0.2.0
From Release

Download the source archive from the latest release:

# Download and extract
curl -sL https://github.com/scagogogo/mvn-skills/releases/latest/download/mvn-skills-latest.tar.gz | tar -xz
cd mvn-skills-*/
go mod download

Quick Start

Find Maven
package main

import (
    "fmt"
    "github.com/scagogogo/mvn-skills/pkg/finder"
)

func main() {
    maven, err := finder.FindMaven()
    if err != nil {
        panic(err)
    }
    fmt.Printf("Maven executable: %s\n", maven)
}
Execute Maven Commands

Simple (standalone functions):

output, err := command.Clean("mvn")
output, err := command.Version("mvn")
output, err := command.DependencyGet("mvn", "joda-time", "joda-time", "2.10.10")

Builder pattern (recommended for complex builds):

output, err := command.NewCommandBuilder().
    WithWorkingDirectory("/path/to/project").
    WithBatchMode().
    WithSkipTests().
    CleanInstall()
Context & Cancellation
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()

output, err := command.NewCommandBuilder().
    WithContext(ctx).
    CleanDeploy()
Parse POM Files
project, err := pom.ParseFile("pom.xml")
if err != nil {
    panic(err)
}
fmt.Printf("GAV: %s:%s:%s\n", project.GroupId, project.ArtifactId, project.Version)
Parse Maven Version
output, _ := command.Version("mvn")
v, err := command.ParseVersion(output)
if err != nil {
    panic(err)
}
fmt.Printf("Maven %d.%d.%d\n", v.Major, v.Minor, v.Patch)
if v.IsAtLeast(3, 8, 0) {
    fmt.Println("Maven 3.8+ features available")
}

API Overview

Command Builder Options
Option Flag Description
WithBatchMode() -B Non-interactive mode (CI/CD)
WithSkipTests() -DskipTests Skip test execution
WithSkipTestsCompletely() -Dmaven.test.skip=true Skip tests entirely
WithOffline() -o Offline mode
WithUpdateSnapshots() -U Force update SNAPSHOTs
WithProfiles(...) -P Activate profiles
WithProperty(k, v) -Dk=v Set system property
WithPomFile(path) -f Specify POM file
WithSettingsFile(path) -s Specify settings.xml
WithProjects(...) -pl Build specific modules
WithAlsoMake() -am Also build dependencies
WithDebug() -X Debug output
WithQuiet() -q Quiet mode
WithThreads(n) -T Parallel threads
WithFailAtEnd() -fae Fail at end
WithFailNever() -fn Never fail
WithNoTransferProgress() -ntp No download progress
WithEnv(...) β€” Set environment variables
WithContext(ctx) β€” Cancellation/timeout support
Lifecycle Convenience Methods
builder.Clean()          // mvn clean
builder.Compile()        // mvn compile
builder.Test()           // mvn test
builder.Package()        // mvn package
builder.Verify()         // mvn verify
builder.Install()        // mvn install
builder.Deploy()         // mvn deploy
builder.Site()           // mvn site
builder.Validate()       // mvn validate
Multi-Phase Convenience Methods
builder.CleanInstall()   // mvn clean install
builder.CleanPackage()   // mvn clean package
builder.CleanDeploy()    // mvn clean deploy
builder.CleanVerify()    // mvn clean verify
builder.CleanTest()      // mvn clean test
Structured Option Types

For commands with many parameters, use structured option types:

// Dependency get with options
opts := &command.DependencyGetOption{
    GroupId:    "joda-time",
    ArtifactId: "joda-time",
    Version:    "2.10.10",
    Classifier: "sources",
}
output, err := command.DependencyGetWithOptions("mvn", opts)

// Deploy file with options
deployOpts := &command.DeployDeployFileOption{
    File:         "target/my-app.jar",
    PomFile:      "pom.xml",
    RepositoryId: "internal-repo",
    URL:          "https://repo.example.com/maven2",
}
output, err := command.DeployDeployFileWithOptions("mvn", deployOpts)

// Install artifact with flexible packaging
installOpts := &command.InstallFileOption{
    File:       "my-app.war",
    GroupId:    "com.example",
    ArtifactId: "my-app",
    Version:    "1.0.0",
    Packaging:  "war",
}
output, err := command.InstallFile("mvn", installOpts)
Error Handling
output, err := command.Clean("mvn")
if err != nil {
    var me *command.MavenError
    if errors.As(err, &me) {
        log.Printf("Exit code: %d", me.ExitCode)
        log.Printf("Command: %s %s", me.Command, strings.Join(me.Args, " "))
        log.Printf("Stderr: %s", me.Stderr)
    }
}

Packages

Package Description
pkg/command Maven command execution (builder pattern + standalone functions)
pkg/finder Find Maven executable on the system
pkg/installer Download and install Maven
pkg/pom Parse and analyze pom.xml files
pkg/settings Parse Maven settings.xml files
pkg/local_repository Navigate and search local Maven repository

Releases

Releases are automated via GoReleaser and published to GitHub Releases.

Download a Release

Each release includes:

  • Source archive β€” Full source code tarball
  • Checksums β€” SHA256 checksums for verification
# Download latest source archive
curl -sL https://github.com/scagogogo/mvn-skills/releases/latest/download/mvn-skills-latest.tar.gz -o mvn-skills.tar.gz

# Verify checksum
curl -sL https://github.com/scagogogo/mvn-skills/releases/latest/download/checksums.txt -o checksums.txt
sha256sum -c checksums.txt --ignore-missing
Use as Go Module

The recommended way to use this library is via Go modules:

# Latest version
go get github.com/scagogogo/mvn-skills@latest

# Specific version
go get github.com/scagogogo/mvn-skills@v0.2.0

# Specific commit
go get github.com/scagogogo/mvn-skills@abc1234
Import Paths
import (
    "github.com/scagogogo/mvn-skills/pkg/command"
    "github.com/scagogogo/mvn-skills/pkg/finder"
    "github.com/scagogogo/mvn-skills/pkg/installer"
    "github.com/scagogogo/mvn-skills/pkg/pom"
    "github.com/scagogogo/mvn-skills/pkg/settings"
    "github.com/scagogogo/mvn-skills/pkg/local_repository"
)

Documentation

Full API documentation is available at:

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License β€” see the LICENSE file for details.

Directories ΒΆ

Path Synopsis
examples
finder command
pom/parse_pom command
pkg
command
Package command provides a comprehensive API for executing Maven commands.
Package command provides a comprehensive API for executing Maven commands.
finder
Package finder locates Maven executables on the system.
Package finder locates Maven executables on the system.
local_repository
Package local_repository provides utilities for working with the Maven local repository (~/.m2/repository).
Package local_repository provides utilities for working with the Maven local repository (~/.m2/repository).
pom
Package pom provides a parser for Maven POM (Project Object Model) XML files.
Package pom provides a parser for Maven POM (Project Object Model) XML files.
settings
Package settings provides a parser for Maven settings.xml configuration files.
Package settings provides a parser for Maven settings.xml configuration files.

Jump to

Keyboard shortcuts

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