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: about 1 year 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 6 years ago)
- Default Branch: main
- Last Pushed: 2022-09-03T20:39:44.000Z (almost 4 years ago)
- Last Synced: 2025-03-18T03:43:56.757Z (over 1 year ago)
- Topics: go-module, golang, golang-library, maven-pom, parser, pom
- Language: Go
- Homepage:
- Size: 18.6 KB
- Stars: 23
- Watchers: 2
- Forks: 17
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mvnparser
[](https://github.com/creekorful/mvnparser/actions/workflows/ci.yml)
[](https://goreportcard.com/report/github.com/creekorful/mvnparser)
[](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)
// ...
}
}
```