Search code examples
javamaven-2mavenmaven-deploy-pluginmaven-install-plugin

How can I embed Maven into my application?


I'd like to embed Maven or the library that does all the magic into my Java application.

The keypoints :

  • They are two tasks I want to perform :

    1/ Publishing a jar in local repository
    2/ Publishing a jar in a private enterprise repository (Nexus)

  • All required jars MUST be located in a public Maven repository

  • The jars SHOULD be Maven version agnostic (ie not specific to Maven 2 or 3)

If you can , please provide a snippet with your response.


Solution

  • Here is an example embedding Maven 2 libraries:

    Instead of looking up the project builder, you can look up the ArtifactInstaller and ArtifactDeployer - you'll find the code you want in the maven-install-plugin and the maven-deploy-plugin.

    The difference just POSTing in this example is that it will generate the appropriate metadata, checksums and snapshot transformations.

    The Maven 3 libraries may be easier to embed and remain compatible with Maven 2, however I don't have any examples readily available.