{"id":25528872,"url":"https://github.com/alipsa/maven-utils","last_synced_at":"2025-04-11T07:52:34.748Z","repository":{"id":57742886,"uuid":"450016876","full_name":"Alipsa/maven-utils","owner":"Alipsa","description":"High level api to interact with maven from within the jvm","archived":false,"fork":false,"pushed_at":"2024-02-05T12:45:47.000Z","size":52,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T05:34:36.602Z","etag":null,"topics":["jvm","maven"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Alipsa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["Alipsa"]}},"created_at":"2022-01-20T08:37:41.000Z","updated_at":"2022-09-29T09:08:13.000Z","dependencies_parsed_at":"2024-02-11T06:15:10.557Z","dependency_job_id":null,"html_url":"https://github.com/Alipsa/maven-utils","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alipsa%2Fmaven-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alipsa%2Fmaven-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alipsa%2Fmaven-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alipsa%2Fmaven-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Alipsa","download_url":"https://codeload.github.com/Alipsa/maven-utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248359986,"owners_count":21090629,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jvm","maven"],"created_at":"2025-02-19T23:24:00.616Z","updated_at":"2025-04-11T07:52:34.711Z","avatar_url":"https://github.com/Alipsa.png","language":"Java","funding_links":["https://github.com/sponsors/Alipsa"],"categories":[],"sub_categories":[],"readme":"# maven-utils\nmaven-3.8.4-utils: \n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/se.alipsa/maven-3.8.4-utils/badge.svg)](https://maven-badges.herokuapp.com/maven-central/se.alipsa/maven-3.8.4-utils)\n[![javadoc](https://javadoc.io/badge2/se.alipsa/maven-3.8.4-utils/javadoc.svg)](https://javadoc.io/doc/se.alipsa/maven-3.8.4-utils)\n\nmaven-3.3.9-utils: \n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/se.alipsa/maven-3.3.9-utils/badge.svg)](https://maven-badges.herokuapp.com/maven-central/se.alipsa/maven-3.3.9-utils)\n[![javadoc](https://javadoc.io/badge2/se.alipsa/maven-3.3.9-utils/javadoc.svg)](https://javadoc.io/doc/se.alipsa/maven-3.3.9-utils)\n\nHigh level api to interact with maven from within the jvm\n\nUse it by adding the dependency to your maven pom:\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ese.alipsa\u003c/groupId\u003e\n    \u003cartifactId\u003emaven-3.8.4-utils\u003c/artifactId\u003e\n    \u003c!-- or if you prefer the maven 3.3.9 version:\n    \u003cartifactId\u003emaven-3.3.9-utils\u003c/artifactId\u003e\n    --\u003e\n    \u003cversion\u003e1.0.2\u003c/version\u003e\n\n\u003c/dependency\u003e\n```\n\nFor SNAPSHOT builds you need to have snapshots enabled for the sonatype snapshots repo. Production releases are available \nin maven central so no repository configuration is needed.\n\n```xml\n\u003crepository\u003e\n    \u003cid\u003esnapshots-repo\u003c/id\u003e\n    \u003curl\u003ehttps://oss.sonatype.org/content/repositories/snapshots\u003c/url\u003e\n    \u003creleases\u003e\u003cenabled\u003efalse\u003c/enabled\u003e\u003c/releases\u003e\n    \u003csnapshots\u003e\u003cenabled\u003etrue\u003c/enabled\u003e\u003c/snapshots\u003e\n\u003c/repository\u003e\n```\n\n## Basic usage\n\n### Running a maven goal\n```groovy\nimport org.apache.maven.shared.invoker.InvocationResult;\nimport se.alipsa.maven.MavenUtils;\n\nFile pomFile = new File(\"pom.xml\");\nInvocationResult result = MavenUtils.runMaven(pomFile, new String[]{\"clean\", \"install\"}, null, null);\n```\nThe arguments to `runMaven(final File pomFile, String[] mvnArgs,\n@Nullable InvocationOutputHandler consoleOutputHandler,\n@Nullable InvocationOutputHandler warningOutputHandler)` are as follows:\n- pomFile the pom.xml file to parse\n- mvnArgs the arguments (targets) to send to maven (e.g. clean install)\n- consoleOutputHandler where normal maven output will be sent, defaults to System.out if null\n- warningOutputHandler where maven warning outputs will be sent, defaults to System.err if null\n- InvocationResult the result of running the targets\n- MavenInvocationException if there is a problem with parsing or running maven\n\nNote that maven need to be installed locally for the maven invoker which is used to run maven to work. MavenUtils will first \nlook for the MAVEN_HOME system property, then for the MAVEN_HOME environment variable and if still not found will try to locate\nthe mvn command in the PATH.\n\nThe static method locateMavenHome is used to find maven home.\n```groovy\nimport se.alipsa.maven.MavenUtils;\n\nString mavenHome = MavenUtils.locateMavenHome();\n```\n\n\nGet the local repository\n```groovy\nimport se.alipsa.maven.MavenUtils;\nimport org.eclipse.aether.repository.LocalRepository;\n\nLocalRepository localRepository = MavenUtils.getLocalRepository();\n```\n\n\u003chr /\u003e\nFor the methods below, an instance of MavenUtils must be created. This allows you to pass in\na list of RemoteRepositories used for the resolution. If you use the default constructor (as in the examples below)\nyou get the Maven Central and BeDatadriven repositories.\n\n### Parse a pom file into a Model\n\n```groovy\nimport java.io.File;\nimport org.apache.maven.model.Model;\nimport se.alipsa.maven.MavenUtils;\n\nFile pomFile = new File(\"pom.xml\");\nMavenUtils mavenUtils = new MavenUtils();\nModel model = mavenUtils.parsePom(pomFile);\n```\n\n### Get a Classloader with all dependencies resolved\n\n```groovy\nimport java.io.File;\nimport se.alipsa.maven.MavenUtils;\n\nFile pomFile = new File(\"pom.xml\");\nMavenUtils mavenUtils = new MavenUtils();\nClassLoader loader = mavenUtils.getMavenDependenciesClassloader(pomFile, this.getClass().getClassLoader())\n```\nThe method is defined as `getMavenDependenciesClassloader(File pomFile, @Nullable ClassLoader possibleParent)` \n\n### Resolve a pom file and get a Set of files for the dependencies (and their transients)\n\n```groovy\nimport java.util.Set;\nimport java.io.File;\nimport se.alipsa.maven.MavenUtils;\n\nFile pomFile = new File(\"pom.xml\");\nMavenUtils mavenUtils = new MavenUtils();\nSet\u003cFile\u003e dependencies = mavenUtils.resolveDependencies(pomFile);\n```\n\n### Fetch (resolve) a single artifact\n```groovy\nimport se.alipsa.maven.MavenUtils;\nimport java.io.File;\n\nMavenUtils mavenUtils = new MavenUtils();\nFile file = mavenUtils.resolveArtifact(\"org.slf4j\", \"slf4j-api\", null, \"jar\", \"1.7.32\");\n```\n\nThe method is defined as `resolveArtifact(String groupId, String artifactId, String classifier, String extension, String version)`\n- groupId is the same as the \u003cgroupId\u003e tag in the pom.xml\n- artifactId is the same as the \u003cartifactId\u003e tag in the pom.xml\n- classifier is typically null, javadoc, sources, dist etc\n- extension could be pom, jar, zip etc.\n- version is the same as the \u003cversion\u003e tag in the pom.xml\n\nFor a more elaborate explanation see [the maven documentation](https://maven.apache.org/pom.html)\n\n## Logging\nMaven-utils uses slf4j for logging so a slf4j implementation needs to be present for logging to work. \n\n## License and dependencies\nThe code in this repository is licenced under the MIT license. However, maven-utils depends on a number of other libraries\nto be able to do its thing. Below is a list of them with their respective license.\n\n### org.slf4j:slf4j-api\nUsed for logging. Licence: MIT\n\n### org.apache.maven.shared:maven-invoker\nUsed to run maven. Licence: Apache 2.0\n\n### org.apache.maven.shared:maven-shared-utils\nUsed to run maven and to parse the pom file. Licence: Apache 2.0\n\n### org.apache.maven:maven-core\nUsed to run maven and to parse the pom file. Licence: Apache 2.0\n\n### org.eclipse.aether:aether-connector-basic\nUsed to resolve dependencies. License: EPL 1.0\n\n### org.eclipse.aether:aether-transport-file\nUsed to resolve dependencies. License: EPL 1.0\n\n### org.eclipse.aether:aether-transport-http\nUsed to resolve dependencies. License: EPL 1.0\n\n### org.junit.jupiter:junit-jupiter\nUser for unit testing. Licence: EPL 2.0\n\n### org.slf4j:slf4j-simple\nUser for unit testing. Licence: MIT\n\n## Version history\n\n### 1.0.3\n\n### 1.0.2, Mar 6, 2022\n- add dependency on later version of httpclient since the one that comes with aether-transport-http \nhas security issues.\n- improve download artifact test\n- add dependency on later version commons-io since the one that comes with maven-shared-utils has security issues\n- Add support for system properties in (-Dkey=value) the maven arguments\n- upgrade slf4j dependency version\n\n### 1.0.1, Jan 28, 2022\n- make locateMavenHome public.\n\n### 1.0.0, Jan 27, 2022\n- Initial implementation, heavily based on similar functionality in the [Ride](https://github.com/perNyfelt/ride) project.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falipsa%2Fmaven-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falipsa%2Fmaven-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falipsa%2Fmaven-utils/lists"}