Maven dependency resolution in a project with modules - installation

my maven project is stuctured as:
project
moduleA
moduleB
moduleC
The moduleB and moduleC are dependend on moduleA. if I execute the 'mvn install' command maven installs moduleA and moduleB in my local repository after that maven tries to install the modeleC but without success, first it tries to find the artifact moduleA in all known maven remote repositories and after that, I'm getting a message that the moduleA artefact is missing. Its so weard because sometimes it works fine and sometimes not. Because of this issue I wasted a lot of time.
The artifact moduleA and moduleB are in my local repository.
I'm using maven 2.2.1 on a 64Bit machine under windows 7 pro.
Does anyone know what the problem is?
Thanks,
Kevin

If you use mvn install, that command will put the artifact in your local repository. Usually in your home directory under .m2/repository unless you have specified differently. If moduleC is trying build (with mvn install) and depends on moduleA, moduleA should be pulling from your local repository when moduleC. If moduleC is looking remotely for moduleA then moduleA never got installed into your local repository.
Check the pom file for moduleC. Make sure the dependency information in moduleC's pom.xml for moduleA matches the groupId, artifactId, and version specified in moduleA's pom.xml. If that matches, make sure moduleA is really producing an artifact. It should be in the target directory under moduleA. If moduleA is not a jar make sure you have the type attribute listed in the pom.xml for moduleA and that moduleC's pom.xml has that type listed for the dependency.
If the above doesn't lead to a consistent resolution, you're may want to edit your question adding some of the pom.xml details.

Related

run a unit test in intellij idea without compiling dependency module

I have a project of intellij idea of two module:
project
moduleA
moduleB
and the moduleB is depending on the moduleA.
So right now I have developed some features on moduleA which is used in moduleB. And I have made a release version of moduleA to the nexus maven repo.
Now I am testing on module B.
I do a mvn dependency:resolve -U to update the dependency of module B and reload the project.
I want to only run one unit test in moduleB, which in my opinion, doesn't need to recompile the moduleA since it is already downloaded from the nexus to my local maven repo. But in intellij, it's still compiling the moduleA which takes much time.
How can I avoid compiling a module in project which is already present in maven repo pls?
thank you

How to force modules recompilation in multimodule SpringBoot maven project?

There is a Maven project with two modules with this structure.
project
moduleA
pom.xml // library
moduleB
pom.xml // SpringBoot application
pom.xml // parent aggregator
Module B depends on A.
When executing command mvn spring-boot:run -pl moduleB (from project folder) Maven takes compiled package moduleA.jar from local repository and fails if it is absent there.
Please, help me to find a way of forcing usage of the latest compiled moduleA version every time the moduleB application starts.
In perfect case I would like to avoid mvn install step, just inducing mvn compile (if code changed) or reusing a compiled moduleA; but it also works if somehow application could be started with the latest compiled version of all code in the multimodular project.

Maven - do a mvn install on local artifact when packaging

i have a maven project which has some local artifacts as dependencies.
When I have to package my main application, i have to do a mvn install command on my local repositories before, which is quite annoying and easy to forget.
Is there a way to tell maven to install local repositories when packaging the main one?
One solution can be to wrap up all your components into a pom project.
When building a parent pom maven automatically triggers a build of all the sub-modules.

Maven release plugin fails for cross module dependencies

I have a multi module maven project, like this:
parent
moduleA
moduleB
moduleC
All the modules inherit their version from the parent pom. moduleC has a dependency to moduleB, so the pom.xml for moduleC contains:
<dependency>
<groupId>blah</groupId>
<artifactId>moduleB</artifactId>
<version>${project.version}</version>
</dependency>
This is all fine. I can run the install goal without any problem, and the dependencies resolve fine.
However, I'm trying to do a release using the maven release plugin using the following command:
mvn release:prepare -DreleaseVersion=1.0 -DdevelopmentVersion=1.1-SNAPSHOT
I can see that all the versions in my pom are updated correctly. However, the problem arises when it tries to compile the code. Because release:prepare does not call the install goal, the compilation for moduleC fails because it cannot resolve the dependency to moduleB version 1.0.
Has anybody else come across this problem? I think having cross module dependencies is fine, but the maven release plugin doesn't seem to cater for this?
Thanks in advance

Maven-ear plugin: could not resolve dependencies to ejbModule

I am probably missing something but how is the maven ear plugin (I'm using version 2.5) resolving ejbModule dependencies? I have the following structure:
my-parent (multimodule)
-- pom.xml
-- myEar
-----pom.xml
---myEjb
-----pom.xml
In the ear I have the dependency to myEjb.
2 things that are unexpected when i execute mvn package under myEar
It does not build (package) myEjb.
It does try to resolve the depedency to myEjb via repository, which is in our case our custom sonar repository that we configured in settings.xml. I would like not to have to install myEjb to our custom sonar respository in a separate step.
What I expected from the plugin would be: check the ejbModules dependencies, build and package them if not done or something changed, copy the jar to the target directory of the ear project and package the whole thing correctly.
Obviously I am missing something though, anybody can enlighten me?
Based on your structure you have to build from the root of your project which means you have to change to my-parent directory
my-parent (multimodule)
-- pom.xml
-- myEar
-----pom.xml
---myEjb
-----pom.xml
and do
mvn clean package
The behaviour you described that maven tries to solve the dependencies against your local repository is the usual process. You can do partialy building a single module within a multi-module build but in your case this won't work cause you depend on your myEjb which neeeds to be rebuilded. Otherwise you can do a
mvn install
first and after that you can do from the root:
mvn -pl myEjb clean test
which will only build the myEjb module and uses the dependencies from the repository (localy in this case).

Resources