0

I've been asked to look at an old project that requires Maven 2.1 and a couple JARs that are not (and will not) stored in our Nexus.

I'm trying to follow the advice from @Nikita Volkov in this post about creating a project repo to hold the JARs as artifacts. The idea being I can check this repo into source control. I can then check it out on any machine and have it build without any special configuration.

To start with I've created a repo and added my first Jar to it by running:

mvn install:install-file -DlocalRepositoryPath=repo -DcreateChecksum=true -Dpackaging=jar -Dfile=lib/myJar.jar -DgroupId=my.group -DartifactId=myArtifact -Dversion=0.0.1

I then create POM that looks like:

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>my.group</groupId>
    <artifactId>MyApp</artifactId>
    <packaging>ear</packaging>
    <version>1.0-SNAPSHOT</version>

    <repositories>
      <repository>
        <id>my-repo</id>
        <url>file://${project.basedir}/repo</url>
      </repository>
    </repositories>

    <dependencies>
      <dependency>
        <groupId>my.group</groupId>
        <artifactId>myArtifact</artifactId>
        <version>0.0.1</version>
      </dependency>
    </dependencies>

    <build>
    </build>
</project>

When I view this in Eclipse if flags the dependency with error
Missing artifact my.group:myArtifact:jar:0.0.1.

When I run it from the command line Iget the error
Unable to find resource 'my.group:myArtifact:pom:0.0.1' in repository my-repo

Clearly I've not understood something in the original post, but I don't see what

So, can anybody provide a working example of how to create a in-project Maven Repo?

Update The files stored in my local repo are:

  • my/group/myArtifact/0.0.1/myArtifact-0.0.1.jar
  • my/group/myArtifact/0.0.1/myArtifact-0.0.1.jar.md5
  • my/group/myArtifact/0.0.1/myArtifact-0.0.1.jar.sha1
  • my/group/myArtifact/0.0.1/myArtifact-0.0.1.pom
  • my/group/myArtifact/0.0.1/myArtifact-0.0.1.pom.md5
  • my/group/myArtifact/0.0.1/myArtifact-0.0.1.pom.sha1
  • my/group/myArtifact/maven-metadata-local.xml
  • my/group/myArtifact/maven-metadata-local.xml.md5
  • my/group/myArtifact/maven-metadata-local.xml.sha1

Update The contents of my .m2/settings file is:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

  <mirrors>
    <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://192.168.152.78:5000/nexus/content/groups/public/</url> 
    </mirror>
  </mirrors>
</settings>
Community
  • 1
  • 1
Stormcloud
  • 2,065
  • 2
  • 21
  • 41

1 Answers1

1

Working solution after several updates to the original question

Your settings.xml file declares a catch-all mirror. This takes effect over the local repository declaration in your pom file. Either remove the catch-all mirror, or try excluding the repository ID of your project repository from the mirroring:

<mirror>*,!my-repo</mirror>

Original answer

Looks like you install the library to the default local Maven repository location (~/.m2/repository), but then you try to pick it up from a location within your project.

Try changing the repository location for Maven before you run the "mvn install:install-file" goal. You can do this by adding a "localRepository" setting in your settings.xml.

You could also create a new settings.xml specifically for your project and tell Maven to use that whenever you work on your project (-s parameter on the command line). IDEs like Eclipse or IntelliJ also support using an alternative settings.xml file.

rec
  • 10,340
  • 3
  • 29
  • 43
  • Hi @rec, Thanks for commenting. I had hoped that the -DlocalRepositoryPath=repo option when creating the repo and adding the JAR would have meant that the repo was created in a subdirectory or my current project. I can certainly see that maven has created something here and added the sha1/md5 files. Am I wrong to think this is a repo? As for changing the settigs.xml file to point to a new local repo, it's an interesting idea, but I'll have to pull down almost 600 artefacts into it. Since I indent to check all of this in to source control that's a lot of files I don't want to have to manage. – Stormcloud Feb 10 '14 at 14:03
  • You are right, I didn't notice this parameter. It should have the same effect as changing the settings.xml. Another guess might be that you are on Windows (are you?) and the file URL may have do be specified differently - maybe without the double // - I'm guessing here - I'm pretty sure that what you are trying to do should work. – rec Feb 11 '14 at 00:08
  • Hi @rec. I am using Windows and I've got Cygwin installed. I've tried running maven through both shells (cmd.exe and bash) but neither is finding up the repo. I've also tried playing with the slashes with the URL with out much luck. Could it be that I've got to use Maven 2.1 for this project? – Stormcloud Feb 11 '14 at 09:34
  • The Maven version shouldn't matter. I've been looking at your command again. Is it possible that you installed the JAR, but not the pom.xml file that describes this JAR? The install-file target basically only copies a file to the repository location and sets up some metadata (as you see it), but it cannot automatically generate a POM file. Maven complains about missing this file, not about the missing JAR. If you do not have a POM, you may be able to find one in the META-INF/maven folder inside your JAR, or you have to create one yourself and then also install it using the install-file target. – rec Feb 11 '14 at 09:50
  • I've updated the original question to include the contents of my repo. There is a POM file there - it's called myArtifact-0.0.1.pom rather than pom.xml. The file doesn't contain much more then the the maven coordinates for my JAR – Stormcloud Feb 11 '14 at 10:23
  • That looks perfectly ok from here. I don't see why Maven should be unable to find the file. You could try running your build with "-X" to see detailed logs, but I believe that there will probably not be additional helpful in there. I'd still suggest to try using a custom settings.xml pointing directly to your repo folder - just to see if that also works or if it does not work - or to try with a toy project and a newer Maven version. Maybe Maven 2.1 is unable to resolve properties in a repo path. I'm wildly guessing at possible diagnosis paths. – rec Feb 11 '14 at 14:22
  • Hi again. I've tried the same thing using maven 3.0.3 - the error I'm getting is "[ERROR] Failed to execute goal on project MyApp: Could not resolve dependencies for project my.group:MyApp:jar:1.0-SNAPSHOT: Failure to find my.group:myArtifact:jar:0.0.1 in http://192.168.152.78:5000/nexus/content/groups/public/ was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced -> [Help 1]". I've added the content of my settings.xml file to the original question as I might have missed something. – Stormcloud Feb 11 '14 at 16:19
  • Aha! Your settings.xml file declares a catch-all mirror. This takes effect over the local repository declaration in your pom file. Either remove the catch-all mirror, or try excluding the repository ID of your project repository from the mirroring: *,!my-repo – rec Feb 11 '14 at 16:24
  • That works perfectly. Thanks for taking the time to look at this - you are a genius! – Stormcloud Feb 12 '14 at 09:33