Building multimodule maven project - maven

Hi I've searched the net, read a bunch of articles, so questions and documentation but I can not find solution, here is my problem.
I have a multimodule maven project which contains three modules A,B and C.
A and B independent and C is depend on A and B, and of course I have a parent project. I also have a jenkins server set up to build these projects, and a nexus repository.
My problem is that when I build the project the maven builds A and B correctly but for C it downloads an older artifact from the nexus repository and of course it fails to build module C.
How can I make the maven to use the currently built jars which installed into the local repository instead of the older ones on nexus?
Version of A and B and C set to 1.1.{build_number}-SNAPSHOT with maven version plugin, and as I understand maven should use the newer from local but it does not do it.
Initially I do not want to post hundreds of lines of pom.xmls but if you need section I will provide it.
Any help would be appreciated. Thank You!

I have been setting the version numbers in the submodule's poms and changed to inherit version number from parent pom. In module C's pom module A and B versions set to ${project.version}

Related

maven pack too many jars to WEB-INF/lib, clear the local repository and re-execut mvn can make things right

In our company, thousands projects are build on 3 servers, with mvn commands.
A few projects occasionally pack too many jars to its WEB-INF/lib folder, the unwanted jars looks like another projects business code and its dependencies.
This is
the diff in WEB-INF/lib between right one(left) and too many jars one(right)
The jar in red frame looks like another project' jars, project name is "jd-common", and the other green jar on right is another project's dependencies.
This situation always reappeared until I clear local repository.
I guess the another project uses "mvn install" to install jars into local repository on build server, and our project is actually depend on jd-common-cached and jd-common-util only.
How can I avoid this?! Thanks for help.
First of all if the jars are there - you depend on them. You may depend on them implicitly (transitive dependencies). Run mvn dependency:tree to list all the dependencies (including transitive). You may find out that you depend on another project that in turn depends on those red/green jars.
Second, on the Build Server you don't want to share local repo with other projects. That's why, at least in Jenkins, there is an option Use Private Repository - this way all the project are going to be separated. This protects you from the situation when the artifact is not in remote repo anymore but the build is still green since that artifact is in local repo. But this has nothing to do with the problem you described.
It's finally be resolved!
The project A depend on a jar which deployed by another project B, the depend jar is a sub-module in B. (A->B)
Unfortunately:
1. A and B are packaged on the same build server
2. B's sub-module jar has the parent config in its pom.xml.
3. B use "mvn clean install -DskipTests" as the build command, so all the B's modules are installed in local repository.
Maven always package the local installed jar, and use the installed jar's pom file to find the sub dependencies, so when maven is executed, project A found that:"one of my depended jar has a parent, it's B, and all the B's sub-modules are found in local repository because of B installed all of them, I should package them all!".

How to use gradle without maven

Is it possible to use gradle without maven?
I ask this question because I've encounered a case where it isn't possible. For example, I have a project(let it be project A) which results in a jar file after the build. This project is used by another project(project B). When I change smth in project A, project B has to see those changes. In maven we could simply make mvn install on project A, then refresh dependencies on project B and changes hapen to be seen there(in project B)
Gradle has an opportunity to use maven plugin which can do the descibed thing. But in that case we rely on maven(maven repo in particular). I was founding information(seems on stackoverflow also) that gradle filestore, which is located in GRADLE_USER_HOME, is only a cache and can't be used for such purpose.
So, how to achieve that functionality in gradle
Thanks
Gradle downloads dependencies from repositories. These repositories can be Maven repositories, Ivy repositories, local Maven repositories or file repositories. So, to solve your use-case, you would indeed have to publish A to a repository, and to use this repository as the source of the A dependency in B.
See the documentation for more details.

Can Maven automatically build a dependency that is not found?

I have three separate projects I am working on (A, B, and C).
Project B and C rely on a jar that project A generates.
Does Maven have the ability to automatically build project A if the dependency is not found?
The answers I've found so far are indicative of making the other 2 projects modules (which I believe to mean repository layout and incorporate them into project A) and create a parent / child pom.
A just plain "no" was also one of my conclusions as well.
It seems as though if I make a module of project A in B and C, maven doesn't really like that. Can Maven see projects during build time that are outside of the scope of the current project? Sorry if that's a little wordy.
The scenario works fine if A, B and C are modules of a common container project.
From root pom.xml:
<modules>
<module>project-a</module>
<module>project-b</module>
<module>project-c</module>
</modules>
where "project-a" etc. are names of maven project folders inside the parent folder.
The parent project must have <packaging>pom</packaging> for this to work.
Then you can build the parent project and it will build all children in order, or you can use one of the advanced Maven reactor flags.
e.g. mvn clean install -pl project-b will only build project B.
For more info, execute mvn --help and read the multi modules chapter from the Maven By Example book.
But to this question:
Does Maven have the ability to automatically build project A if the
dependency is not found?
... the answer is always no. Maven fails if the dependency is not found, but it never decides which projects to build. You are in charge of which projects need building.

Maven uses different timestamps when building snapshot artifacts in a large project

We have a large maven 3 project with around 250 modules. All modules have version 1.0-SNAPSHOT and modules tree has single parent module with the same version as a tree root.
Project is built with Bamboo nightly and artifacts are installed to a Nexus repository using command "mvn clean install".
It happens that part of modules are built with one timestamp while the rest with the other, something like:
module1-1.0-20121127.150154-7.jar
module100-1.0-20121127.150527-7.jar
In another project I was trying to set dependency to artifacts of this project using specific version of a snapshot dependency (as discussed in this question Maven specific version of a snapshot dependency) but failed to build due to the problem described above.
Does anyone know why maven would use different timestamps and how to fix that?
MNG-6754 was finally fixed in 3.8.2.

Build a maven product with components from a different git repository

Our project has two different git repositories A and B. Both A and B are multi module projects. B's code is finally built as a eclipse product using maven parent pom. B requires a component/ feature from A which needs to be included in the eclipse product. How can I achieve this functionality. Do I need to publish the results of A's build to a webserver, so that B can access it as a repository? or can I include A as dependency to B's build so that B can package this component in the final product? Where/ how can I specify this configuration?
Let me know if any other information is required.
Thanks in Advance!
This should be possible on your local machine if you run 'mvn install' on project A. If you want the artifact from project A to be available to other developers you need to setup a maven repository such as Archiva and run 'mvn deploy' instead
You should at least deploy project A to the local repository (mvn install). Then it will be available to project B through maven.

Resources