Question

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>
Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top