Recently in Maven Category

Maven is a life saver for Java. It provides some much needed convention, but at the same time it can be really tricky to figure out how to do some basic configuration. One problem I struggled with was setting up an Artifactory repository which required authentication for the uploading and downloading or jars.

To save you some time, here are some steps with the minimal required configuration:

  1. Install artifactory as described on their website
  2. Create a user that you will use for access. Make sure that they have access but they do not need to be an administrator.
  3. Encrypt this user’s password mvn --encrypt-password . You should get a result that looks something like this: {COQLCE6DU6GtcS5P=}
  4. Create your ~/.m2/settings.xml file and add this content to it. This will teach your maven how to download libraries from your repository.
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<pluginGroups> 
<pluginGroup>org.grails</pluginGroup></pluginGroups> 
  <servers>
    <server>
        <id>myrepo.example.com</id>
        <username>johndoe</username>
        <password>{the encrypted password from the previous step}</password>
    </server>
  </servers>
  <profiles>
    <profile>
      <id>default</id>
      <repositories>
          <repository>
              <id>myrepo.example.com</id>
              <url>http://myrepo.example.com:8090/artifactory/repo</url>
          </repository>
      </repositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>default</activeProfile>
  </activeProfiles>
</settings>
  1. Add this to each of your pom.xml files (or to your project root pom). This is how your projects know to deploy your libraries. The user name and password will be used from settings.xml which is why it’s important for the two server IDs to match.
    <distributionManagement>
        <repository>
            <id>myrepo.example.com</id>
            <name>myrepo.example.com</name>
            <url>http://myrepo.example.com:8090/artifactory/libs-releases-local</url>
        </repository>
        <snapshotRepository>
            <id>myrepo.example.com</id>
            <name>myrepo.example.com</name>
            <url>http://myrepo.example.com:8090/artifactory/libs-snapshots-local</url>
            <uniqueVersion>false</uniqueVersion>
        </snapshotRepository>
    </distributionManagement>
0 Votes

Grails does not like loading the same class twice.  I've observed this several times in Grails v1.1.1 and each time there was a different fix.  The stack traces look pretty similar no matter what the root cause.

Example stack trace:

[groovyc] Compiling 33 source files to /Users/me/.grails/1.1.1/projects/trunk/classes
Error executing script TestApp: : java.lang.LinkageError: loader constraint violation: loader (instance of ) previously initiated loading for a different type with name "org/w3c/dom/Attr"
gant.TargetExecutionException: : java.lang.LinkageError: loader constraint violation: loader (instance of ) previously initiated loading for a different type with name "org/w3c/dom/Attr"
	at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:331)
	at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
	at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
	at gant.Gant.withBuildListeners(Gant.groovy:344)
	at gant.Gant.this$2$withBuildListeners(Gant.groovy)
	at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
	at gant.Gant.dispatch(Gant.groovy:334)
	at gant.Gant.this$2$dispatch(Gant.groovy)
	at gant.Gant.invokeMethod(Gant.groovy)
	at gant.Gant.processTargets(Gant.groovy:495)
	at gant.Gant.processTargets(Gant.groovy:480)
Caused by: : java.lang.LinkageError: loader constraint violation: loader (instance of ) previously initiated loading for a different type with name "org/w3c/dom/Attr"

Case 1: /lib/ jar file conflicts with a Grails plugin

I was using a functional test plugin which included xerces.  I already had xerces in the /lib folder of my grails project.

Solution to Case 1:

Remove the jar file from /lib as long as I was using this plugin...  I found the conflicting jar file the crude way: grep -r 'org.w3c.dom.Attr' ./ This solution is kind of messy but solved the problem until I stopped using this functional testing plugin at which time I had to add the jar back into the /lib/ folder.

Case 2: A maven assembly jar-with-dependencies contained a class that conflicted with a grails dependency

In this case I was using a library of my own creation built in maven. To keep the dependency nightmare to a minimum, I used the super-jar provided by the assembly plugin to package all of the dependent classes into my library. This works great in most cases, but as it turns out one of the included libraries, Xerces, is also used by grails internally.

I discovered the conflicting jar files the same way as last time: grep

Solution to Case 2:

I didn't find a satisfactory solution to this issue. Lacking time to investigate the inclusion / exclusion features of the maven assembly plugin, I simply used the standard maven jar and selectively copied the dependencies into the /lib folder of my grails project.

This 'solution' is fairly unsatisfying, but for now it works. Once I end up with dependency hell I'll revisit this issue and update this blog entry. In the mean time if anyone else solves this problem, please comment.

Other Solutions

Although I have not run into any of these solutions, other people have had luck with them

0 Votes

About this Archive

This page is an archive of recent entries in the Maven category.

Joyent is the previous category.

Meta is the next category.

Find recent content on the main index or look in the archives to find all content.

Maven: Monthly Archives