5

My project structure as below during the integration test.

 Project-A
    |_conf (contains the configuration files)
    |_lib  (Contains the all dependencies)
    |_pom.xml
    |_target
        |_test (Contains the integration tests)

When I run the below maven command it download the dependencies from nexus and pointing to the local repositories instead of lib directory.

How Do I tell maven to check lib folder for dependencies instead of local maven repository?

Note : lib contains the all the dependencies which are required to test the project.

    mvn surefire:test
sree1611
  • 352
  • 1
  • 4
  • 18
  • You can define such things through the settings.xml file located in ~/.m2/settings.xml – raphael_mav Jan 11 '19 at 12:13
  • _lib_ contains the only jars. it is not maven repository. Does't contains the groupid folder structure. – sree1611 Jan 11 '19 at 12:47
  • Start using a repository manager and deploy the lib jars into the repository manager or use default dependencies ...that makes life easier and much more convenient...using a lib directory is really a bad thing apart from that it means to commit jar files into a version control where they don't belong... – khmarbaise Jan 12 '19 at 09:58
  • Your setup is simply a bad idea..first the conf directory ? The configuration files (usually resources called) should be put into src/main/resources if they will be packaged into the resulting jar file.. If they only needed for tests they should be put into /src/test/resources. – khmarbaise Jan 12 '19 at 09:59
  • @khmarbaise, I know it is bad idea, but it is legacy application. We can't change the project structure – sree1611 Jan 12 '19 at 13:31

1 Answers1

10

If you want to use dependency that is not in maven repo, then you can place those jars in in project (in your case lib directory). And specify the path of the jar to use like below.

<dependency>
    <groupId>anything</groupId>
    <artifactId>anything</artifactId>
    <version>anything</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/jar-name.jar</systemPath>
</dependency>

Here you can mention anything for groupId, artifactId and version. These fields are just ignored in this case.

isapir
  • 21,295
  • 13
  • 115
  • 116
Deepak Kumar
  • 1,246
  • 14
  • 38
  • 1
    I want to refer _lib_ directory only during the integration test. I am running this through profile. – sree1611 Jan 11 '19 at 12:49
  • You can try with `` as `test`. – Deepak Kumar Jan 11 '19 at 12:50
  • If you want to refer lib dir during test and maven repo while running than you might need to add dependency two time by specifying `` once as `test` with `` and againg with `` as `runtime`. – Deepak Kumar Jan 11 '19 at 12:54
  • 1
    There are more than 100 jars. Do we need to do it for all? Is there any option to provide the path? – sree1611 Jan 11 '19 at 13:03
  • That kind of jar files are those jar file? Are they generated by other builds? You should use usual dependencies and also as already mentioned use an appropriate scope. Furthermore the scope system is deprecated for a very long time and will produce WARNINGs... – khmarbaise Jan 12 '19 at 10:21
  • > "There are more than 100 jars" >> @sree1611, You can try to use sbt. Benifit: in most cases it is simpler. Worse: it's slower and take more space, both on RAM and hard disk. Maybe groovy also allows to do it. – Mikhail Ionkin Jul 22 '22 at 10:53