Say I have a multi module maven project that builds components A and B.
Now I want to make a B a separate maven project but B has a dependency on A.
A also has a dependency on C. Because A has to be run in JAVA 7 and B has to be run on JAVA 8
C is a jar, but in C's pom the packaging is bundle.
<groupId>C</groupId>
<artifactId>C</artifactId>
<version>1.0.0</version>
<packaging>bundle</bundle>
After building A, I'm building B.
I'm declaring A as a dependency in the pom with a correct version, and in the local repository, C.jar exist.
But when I try to build B,
mvn clean install
[ERRROR] Failed to execute on project B: Could not resolve dependencies for B.jar:1.0.0: Could not find artifact B:bundle:1.0.0 in <artifactory_url>
This worked perfectly when I had a parent pom and had them as modules
How can I just make the dependency in B, A, to pick up the jar file from the artifactory without using the pom?
Related
I was given a project structure implementing a board game with GUI that contains two Projects/modules in one IntelliJ Project. Both use Maven to manage dependencies.
Module A (Game-Logic)
Module B (Game-gui)
Module A uses Classes in Module B, and A's pom.xml contains the following dependency:
<dependency>
<groupId>io.bibucket.plt</groupId>
<artifactId>Game-gui</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
But Game-gui is just Module B that is contained locally in the Project itself and the infos (groupId,artifactId etc.) are specified in Module B's pom.xml, so that's what it's pointing to!
Why would we specify a maven dependency to it? I thought the point of maven is to manage dependencies to remote artifacts. Is maven also used to specify local dependencies?
During Maven build I see this error:
The POM for io.bibucket.plt:Game-gui:jar:0.0.1-SNAPSHOT is missing, no dependency information available
What does this error mean? Why is this project using Maven to point to a local Module as an artifact?
You need to use install, package and deploy commands of maven for module B to make it accessible for module A. These commands make a .jar file for module B which can be imported by module A. Models and classes in different artifacts can not be visible for each other unless you define their dependencies in pom file of the other module.
I am working on a multi-module maven project and have third party jar which isn't available in central or public repository, I also even don't want to place on public repo. I am providing following plugin directive in my parent pom to install jar in my local maven repository before its dependency is resolved in child project.
Now I provide dependency in child project as;
But I build the project, it successfully adds dependency in local maven repository (places third party jar in .m2 folder) but the at the same time it gives following error. Looks like, it searches this jar file in child projects libs folder as well, while I have already placed it on root (in myproject.parent/libs).
Failed to execute goal org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file (install-
external-non-maven1-jar) on project myProject.core: The specified file 'C:\Users\myuser\git\MyProjectRepository\myproject.parent\myproject.core\libs\be-ixf-java-sdk-jar-with-dependencies.jar' not exists.
I already know scope and systemPath option but I don't want to use it for some reason.
Kindly help in identifying what I am missing ?
The best approach that you could have if your project have a centralized maven repo like nexus setup is to have your third party library also added to the repo. Now , you are having the bin file added to your project and it's not preferable.
If you already have the required jar under your project code in like : libs\*, then why can't you refer the dependency directly in your pom.xml instead of having to install it in your local maven repo and then use it .
<dependency>
<groupId>anything</groupId>
<artifactId>anything</artifactId>
<version>anything</version>
<scope>system</scope>
<systemPath>${basedir}/lib/jar_name.jar</systemPath>
</dependency>
providing the location of the dependency in your project directory should resolve it during build itself.Look at Maven System dependencies.
Since you do not want to change your current setup . Please bear in mind the following about maven pom structure :
Project Aggregation is similar to Project Inheritance. But instead of
specifying the parent POM from the module, it specifies the modules
from the parent POM. By doing so, the parent project now knows its
modules, and if a Maven command is invoked against the parent project,
that Maven command will then be executed to the parent's modules as
well
So the maven-install-plugin execution that you added in main pom.xml might be getting triggered for all your modules because of this reason. You might want to move that to the module that you actually need this lib to be included in.Read maven doc.
Related : force Maven to copy dependencies into target/lib
I have a project structure like:
However, whenever I run mvn clean test -DskipTests from the Project 1 directory, it ends up NOT including the Project 2 module in the Maven reactor even though I've listed it as a dependency in Project 1 as follows:
<dependency>
<groupId>com.main.sub</groupId>
<artifactId>project2-artId</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
What could be happening and why isnt the dependency being recognized?
From https://maven.apache.org/guides/mini/guide-multiple-modules.html; the reactor "Collects all the available modules to build". (modules of the project that is currently being built)
You need to: create a parent project, with packaging pom; add two modules to this project (one for Project1, one for Project2), and submodules for project1.
Then, when you build the parent project, the build order for all modules are decided by the reactor-
Here is the relations between my projects:
Spring boot project A -> Project B -> Project C
When I run a Maven:install I want to have all the dependencies from Project B AND Project C in my lib folder.
The problem is that for now I just Have the dependencies from Project A...
I just have the spring-boot-maven-plugin as build configuration without any argument...
you should use maven 2.0 or later to have your transitive dependencies imported .
The dependencies in B and C should not have scope "provided" otherwise maven will not import them thinking that the server will provide them
I finally find my mistake...
In the pom of the Project C, I had a dependency in scope system and the system path was like ${basedir}/my/path/librairy.jar. The problem is that Maven wants an absolute path for this librairy when I package Project B. I saw a warning in maven's logs that was saying that. The solution was easy, I change the path for an absolute path and everything went fine! Except for the system librairy that is not packaged. I will put it on our Nexus and it will be fine.
We have 3 modules say A,B and C.These 3 modules are cross dependent.To compile A I want B and C.To compile B I want A and C.To compile C we want B and A.So how to build these 3 modules together and we want to get A.jar,B.Jar and C.war.
Use <dependencies> section in pom.xml to add a dependency for one another module.
Create a parent pom for all of your modules. When building parent, maven builds all children (except if you use -pl :mymodule selector on command line). See parent section of pom
You can also add a 4th child module D (without artefact, just a pom module) with A, B, and C dependencies or a subset. When you build D, maven compiles A, B, C with the option -am (also-make) which forces maven to build the selected module and dependencies too.
Note that you must avoid cyclic dependencies into your code or maven will fail to build your project. If you have a cyclic dependency, extract the code need by two modules into one another and adding a dependency in both
What you are explaining is the cyclic dependency. Maven does not support cyclic dependencies and your build will fail if your try to do that.
You can create a multi-module maven project. Move all the common functionality to Module A. Add the dependency of Module A in Module B and Module C's pom.xml <dependencies>...</dependencies> section.
Maven will build the modules in the order you specify in the parent project pom.xml <modules>...</modules> section. In this way you create A.jar, B.jar and C.war by defining the <packaging>...</packaging>as jar or war in their respective module's pom.xml
These links will be helpful - link1 link2