Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/creekorful/mvnparser
- Owner: creekorful
- License: mit
- Created: 2019-10-08T12:12:38.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2022-09-03T20:39:44.000Z (over 2 years ago)
- Last Synced: 2024-10-13T13:31:40.208Z (3 months ago)
- Topics: go-module, golang, golang-library, maven-pom, parser, pom
- Language: Go
- Homepage:
- Size: 18.6 KB
- Stars: 23
- Watchers: 3
- Forks: 17
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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 mainimport (
"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)
// ...
}
}```