Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Populate Your Maven Repo With Mule ESB Libraries

DZone's Guide to

Populate Your Maven Repo With Mule ESB Libraries

· Integration Zone
Free Resource

Share, secure, distribute, control, and monetize your APIs with the platform built with performance, time-to-value, and growth in mind. Free 90-day trial of 3Scale by Red Hat

When you build applications based on Mule EE (Enterprise Edition) and you are using Maven to build your projects, you will notice you have dependencies to libraries that are not available in the public Maven repos. To add these libraries to your local maven repo the Mule distribution comes with a script ‘populate_m2_repo’ which is described here how to use it.

Now that is okay if you are the only developer and you are running your continuous integration on your local machine. In my case we are using Artifactory as our company Maven repository and also our build server is using it as the Maven repo. So what I wanted was not to populate my local repository but the Artifactory instance with all Mule libraries. To do so I did two things:

  • First make sure that Maven is authorised to add libraries to Artifactory. You can do this by adding the following to your settings.xml:
  • <servers>
      <server>
        <id>artifactory</id>
        <username>admin</username>
        <password>password</password>
      </server>
    </servers>
  • Second step is to modify the original ‘populate_m2_repo.groovy’ script. Replace the following line:
    mvn(["install:install-file",
    "-DgroupId=${project.groupId}", 
    "-DartifactId=${project.artifactId}", 
    "-Dversion=${version}", "-Dpackaging=pom", 
    "-Dfile=${localPom.canonicalPath}"])
    with
    mvn(["deploy:deploy-file", 
    "-DgroupId=${project.groupId}", 
    "-DartifactId=${project.artifactId}", 
    "-Dversion=${version}", 
    "-Dpackaging=pom", 
    "-Dfile=${localPom.canonicalPath}", 
    "-DrepositoryId=arti", 
    "-Durl=http://localhost:8080/artifactory/libs-release-local" ])
    And do the same for the line:
    def args = ["install:install-file", 
    "-DgroupId=${pomProps.groupId}", 
    "-DartifactId=${pomProps.artifactId}", 
    "-Dversion=${pomProps.version}", 
    "-Dpackaging=jar", 
    "-Dfile=${f.canonicalPath}", 
    "-DpomFile=${localPom.canonicalPath}"]
    by replacing it with:
    def args = ["deploy:deploy-file", 
    "-DgroupId=${pomProps.groupId}", 
    "-DartifactId=${pomProps.artifactId}", 
    "-Dversion=${pomProps.version}", 
    "-Dpackaging=jar", 
    "-Dfile=${f.canonicalPath}", 
    "-DpomFile=${localPom.canonicalPath}", 
    "-DrepositoryId=arti", 
    "-Durl=http://localhost:8080/artifactory/libs-release-local" ]
    Now you can run the script with:
    ./populate_m2_repo bla
    As you can see it doesn’t really matter what you supply as M2_REPO_HOME here because the libraries are uploaded to Artifactory anyway.

    If you want you can replace the hardcoded url for Artifactory in the script with the supplied parameter but in my case this solution was sufficient :-)

Explore the core elements of owning an API strategy and best practices for effective API programs. Download the API Owner's Manual, brought to you by 3Scale by Red Hat

Topics:

Published at DZone with permission of Pascal Alma. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}