0

I feel like I must be lacking some very very basic Maven knowledge here. I have a (couple of) maven project(s) and a shared library. This library should be a separate maven project with its own life cycle. I'm trying to import the library into my project using:

<dependencyManagement>
   <dependencies>
      <dependency>
         <groupId>nl.whatever.com</groupid>
         <artifactId>my_shared_library</artifactId>
         <version>1.0-SNAPSHOT</groupid>
      </dependency>

      ...
   </dependencies>
</dependencyManagement>

But maven keeps looking in my repro instead of trying to find my local build. And worst of all, it keeps looking for a jar. I get:

Could not resolve dependencies for project my.project:ejb:1.0-SNAPSHOT: Could not find artifact nl.whatever.com:my_shared_library:jar:1.0-SNAPSHOT

What's my rookie mistake? Yes, I did do a clean install of my library project.

edit:

My .m2 directory has a settings file redirecting my local repro to

/ws/repro, which contains:
/ws/repro/nl/whatever/com/my_shared_library/1.0-SNAPSHOT/
   my_shared_project-1.0-SNAPSHOT.jar.lastUpdate
   my_shared_project-1.0-SNAPSHOT.pom

and some property files.

edit2: I don't think it's a duplicate. I looked at the question linked before posting my question. There is no non-maven project or external jar involved here.

Arne
  • 742
  • 4
  • 12
  • Have you confirmed that the artifact jar is there in your local `.m2` folder in the correct location? – Strelok Aug 18 '17 at 14:14
  • You say that you ran install, but is your shared library's pom file configure with the information you defined in your dependency? – pabrantes Aug 18 '17 at 14:14
  • I don' think this question is a duplicate of the stated question. This is not about installing external files, but about building a library so that it can be used by other projects. – J Fabian Meier Aug 18 '17 at 14:29
  • @Strelok updated the question based on your comments. My library's pom file matches the versions and names. – Arne Aug 18 '17 at 14:36

2 Answers2

1

Your local repository is usually in .m2/repository below the user repository. If You do clean install on your library project, it should be installed into this repository (in nl/whatever/com/my_shared_library/...). Then you can use it from all other Maven projects on the same computer.

It is furthermore important that the <packaging> is correct, i.e. the packaging needs to match the artifact you want to build. If the packaging is pom then you only create a pom (like a parent pom or a bom). Leaving out the packaging tag implictely means that you use packaging jar.

J Fabian Meier
  • 26,766
  • 8
  • 52
  • 98
  • Why delete the .lastupdate files and how does that provide me the jar I apparently need in there? – Arne Aug 18 '17 at 14:38
  • The lastupdated files prevent you from using a jar because they tell Maven that the jar does not exist. This is common reason for not getting a jar that should be present. Have you looked into your local repository? Does it contain the library you build with "clean install"? – J Fabian Meier Aug 18 '17 at 14:42
  • The clean install creates the 1.0-SNAPSHOT folder, containing the following files: `_remote.repositories`, `maven-metadata-local`, and `my_shared_library-1.0-SNAPSHOT.pom`. No jar. – Arne Aug 18 '17 at 14:51
  • Does your my_shared_library have an entry pom? If so, remove it. – J Fabian Meier Aug 18 '17 at 14:53
  • If not, there is obviously some wrong entry in that pom that prevents the project from being build as a jar. – J Fabian Meier Aug 18 '17 at 14:54
  • That.... explains a lot :X. A whole lot... Could you edit your answer so I can accept it? :X – Arne Aug 18 '17 at 15:01
  • I added a paragraph. – J Fabian Meier Aug 18 '17 at 15:07
0

You shall try updating your pom.xml with a tag named as repositories.

Maven repositories are the places that hold build artifacts and dependencies of varying types.

A sample maven remote repository tag with its values is:

<repositories>
  <repository>
    <id>central</id>
    <name>Maven Repository</name>
    <url>http://repo1.maven.org/maven2</url>
  </repository>
</repositories>

To configure multiple repositories you can follow the guide and make use of profile in settings.xml as well.


On a side note, unless following a hierarchy or making use of specific versions of a library. You should use <dependencies> instead of <dependencyManagement>, take a look at the differences between dependencymanagement and dependencies in maven.

Naman
  • 23,555
  • 22
  • 173
  • 290