Populate your Maven repo with Mule ESB libraries

Update: I recently discovered that the Mule EE libraries are available in a Maven repository. You have to have a Mule EE license to obtain the credentials. More info about it here. This option would make the remainder of the post redundant.

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 🙂

    Advertisement

About Pascal Alma

Pascal is a senior IT consultant and has been working in IT since 1997. He is monitoring the latest development in new technologies (Mobile, Cloud, Big Data) closely and particularly interested in Java open source tool stacks, cloud related technologies like AWS and mobile development like building iOS apps with Swift. Specialties: Java/JEE/Spring Amazon AWS API/REST Big Data Continuous Delivery Swift/iOS
This entry was posted in Maven, Mule3 and tagged , , . Bookmark the permalink.

1 Response to Populate your Maven repo with Mule ESB libraries

  1. Pingback: Unit testing with Mule ESB 3.4 Enterprise Edition | The Pragmatic Integrator

Comments are closed.