简体   繁体   中英

maven dependency for multi-module project

I have a strange issue with maven.

I'm running a dropwizard project that has multiple modules.

Project -> ServiceModule1 -> ServiceModule2 -> ModelsModule -> TestModule

All modules depend on the test module, and all of the service modules depend on the models module.

I'm using a test-jar to distribute the test module since all of the fixtures live in there.

So when I package my project, I do this:

cd testModule
mvn jar:test-jar
cd ..
mvn package

This works fine, except it means every time I want to package my project I have to run all the tests. If I switch to

mvn package -Dmaven.test.skip=true

I get a failure because my modules start to look for their dependency jars in maven central.

This is really frustrating, since the tests depend in a database and I don't want to install a database on every web server.

What should the "correct" setup be?

Just to be clear, if your ServiceModule1 wants to depend on ModelsModule, you can build it in two steps,

$ cd ModelsModule
$ mvn clean install
$ cd ..
$ cd ServiceModule1
$ mvn clean package

Please note install in step2,

In other words, it is not mandatory that all your lib should be in maven central. But it is mandatory that all of them should be in your local repo. install is a goal which can install a lib to your local repo.

Now this link will show you how to install a test jar to your local repo.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM