0

I know it is a bad practice, but the situation must have this approach.

I am trying to put part of the dependencies in the project dir itself. I created a dir called m2 in the project root(it is on the same level as the pom file) and copied the file structure there. Also, I added this local maven repo to the POM. The problem is that I am using a parent POM which is located in this new local m2 repo, but it can't get resolved. I am using a windows machine.

Local file repo added to pom:

<repository>
    <id>local-maven-repo</id>
    <name>asd</name>
    <url>file:///${project.basedir}/m2</url>
</repository>

Parent pom definition:

<parent>
    <groupId>com.test.example</groupId>
    <artifactId>tests-parent</artifactId>
    <version>6.3.3</version>
</parent>

Screenshot

enter image description here

mvn -U shows this error:

Scanning for projects...
Downloading from local-maven-repo: file:///${project.basedir}/m2/com/test/example/tests-parent/6.3.3/tests-parent-6.3.3.pom
Downloading from central: https://repo.maven.apache.org/maven2/com/test/example/tests-parent/6.3.3/tests-parent-6.3.3.pom

Non-resolvable parent POM for com.test.example:tests:1.0.0-SNAPSHOT: Could not find artifact com.test.example:tests-parent:pom:6.3.3 in local-maven-repo (file:///${project.basedir}/m2) and 'parent.relativePath' points at wrong local POM @ line 9, column 10

Looks like the ${project.basedir} variable is not resolved at all.

Updates:

Tried also with 2 slashes file://, but still not resolved.

CuriousGuy
  • 1,376
  • 3
  • 16
  • 38
  • it's a bad practice, why not uploading the artifacts to a repository(public/private) or have it installed on your local machine? – Khoda Nov 10 '20 at 11:00
  • Remove the third forward-slash: ```file://${project.basedir}/m2``` See also: https://stackoverflow.com/questions/2229757/maven-add-a-dependency-to-a-jar-by-relative-path – codeflush.dev Nov 10 '20 at 11:05
  • @codeflush.dev, nope, still same result – CuriousGuy Nov 10 '20 at 11:08
  • It's really a bad idea to try to create a directory which in your project with dependencies. The maven way is to consume them from a repository for example central... The other question is: Where does tests-parent coming from? From another Maven build? Than use simply `mvn install` and consume it...I strongly recommend to start using a repository manager ... if you are working in a corporate environment... – khmarbaise Nov 10 '20 at 11:14
  • @khmarbaise, yes, I know, but I must do it. It's too long for explanation. The tests-parent are in the local repo `m2` dir which is in the project dir. – CuriousGuy Nov 10 '20 at 11:18
  • You start fighting with Maven a combat which you will loose.. Go the right direction that helps a lot... and makes it easier... If someone is telling you.. you must... interesting... – khmarbaise Nov 10 '20 at 11:21
  • @khmarbaise, okay, let me explain the situation and maybe you could suggest better approach. We have local artifactory server. But we must transfer the project to another machine which will not have access to the artifactory server. So, we need to transfer the dependencies "manually". The idea is the export them to the project base dir and just add this dir as a local maven repo. This is what I'm trying to do. – CuriousGuy Nov 10 '20 at 11:25
  • Why transfering artifacts to a machine which is used to build things but does not has access to artifactory? That does not make sense. Simply give the access to artifactory. That would make it a lot easier. Why is the machine without artifactory access needed? And why building on that machine? – khmarbaise Nov 10 '20 at 11:37
  • @khmarbaise, because it is 3rd party machine and it must not have direct access to our internal artifactory – CuriousGuy Nov 10 '20 at 11:38
  • Then why are you building on that machine? Does not make sense from my point of view... – khmarbaise Nov 10 '20 at 14:20
  • @khmarbaise, I am building on this machine, because we need to give the code to this 3rd party, but we don't want to give them access to our artifactory. Why does it look so strange to you? :) – CuriousGuy Nov 10 '20 at 16:43
  • Create a repository in artifactory and deploy the code there which can be controlled by permissions etc. So very easy in the end... – khmarbaise Nov 10 '20 at 17:06
  • @khmarbaise, our repository is in our private network. We don't want to give them VPN access :) – CuriousGuy Nov 10 '20 at 17:15
  • 1
    So you have a organisational problem not a technical one.. Put a repository manager in outside your private network which access only that single repo within the private network ... – khmarbaise Nov 11 '20 at 07:48

0 Answers0