Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/creekorful/mvnparser

Go parser for maven Project Object Model (POM) file
https://github.com/creekorful/mvnparser

go-module golang golang-library maven-pom parser pom

Last synced: 2 months ago
JSON representation

Go parser for maven Project Object Model (POM) file

Awesome Lists containing this project

README

        

# mvnparser

[![Continuous Integration](https://github.com/creekorful/mvnparser/actions/workflows/ci.yml/badge.svg)](https://github.com/creekorful/mvnparser/actions/workflows/ci.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/creekorful/mvnparser)](https://goreportcard.com/report/github.com/creekorful/mvnparser)
[![Maintainability](https://api.codeclimate.com/v1/badges/ac9fd99e18e6ef2661e3/maintainability)](https://codeclimate.com/github/creekorful/mvnparser/maintainability)

Go parser for maven Project Object Model (POM) file

# how to use it ?

Let's take the following POM file

```xml


4.0.0

com.example
my-app
1.0.0-SNAPSHOT



junit
junit
test


javax.enterprise
cdi-api
provided






org.apache.maven.plugins
maven-compiler-plugin
3.8.0

11





```

You can read the pom file using

```go
package main

import (
"github.com/creekorful/mvnparser"
"encoding/xml"
"log"
)

func main() {
// filled with previously declared xml
pomStr := "..."

// Load project from string
var project mvnparser.MavenProject
if err := xml.Unmarshal([]byte(pomStr), &project); err != nil {
log.Fatalf("unable to unmarshal pom file. Reason: %s", err)
}

log.Print(project.GroupId) // -> com.example
log.Print(project.ArtifactId) // -> my-app
log.Print(project.Version) // -> 1.0.0-SNAPSHOT

// iterate over dependencies
for _, dep := range project.Dependencies {
log.Print(dep.GroupId)
log.Print(dep.ArtifactId)
log.Print(dep.Version)

// ...
}
}

```