Setting profile for dependency of multipart project command line - spring

I have a multi-module project. Basically, I have a Project A, and Project B (An integration test). Project B relies on Project A to run. So when we run project B, we do something like: mvn clean package -B -pl :project-B -am. The -am part of the command instructs maven to also compile the dependency (Project A) and to include it. Problem is... When we run the dependency for project A, it doesn't seem to be pulling the correct profile. How do we set the profile to be used for compilation for dependency A in this command?
Thanks!

Related

build a submodule into jar with maven package

I have a multimodule maven based springboot project with a parent project, and submodule A, B, C, D, E. I need to package module B into a jar file rather than build the whole multimodule project. The application in module B is also depends on several java files in module A and E, and it will run several functions in A and E as well. Could anyone tell me how to build submodule B into a jar file please?
I know for a single module project, I only need to run mvn package to get a jar file, or open maven window and click lifecycle->package. But for multi-module project, I'm not sure how to do that for only a submodule, especially when this submodule will run some functions in other submodule.

Maven "also-make"'s behavior

Let's suppose there are two projects, A and B, and B has a dependency on A.
Then I write
mvn verify --also-make --projects "B"
Maven help claims that also-make build projects required, so project A will be built.
But what does "build" mean? What maven phase will be applied to project A? Compile, verify or another?
It will apply the command or phase that you gave in the Maven command.

How to package jar from one project to another in maven multimodule project

I need a best-practice solution for the following problem. I have a maven multi-module project with 3 subprojects:
client-module (simple java app which packaged as .jar)
module-1-that-uses-client
module-2-that-uses-client
module-*-that-uses-client is a bunch of static xml config files with a client-module.jar which is packaged as a .zip file. So, the packaged structure of a module-*-that-uses-client would look like:
client-module.jar
config1.xml
config2.xml
config3.xml
I wonder how I can implement following build strategies.
If I build client-module, then:
build client-module
copy client-module.jar to all module-*-that-uses-client
build all module-*-that-uses-client modules.
If I build any of module-*-that-uses-client, then:
build client-module
copy client-module.jar to exact module-*-that-uses-client
build exact module-*-that-uses-client modules.
Appreciate any help on this problem.
One solution would be the usage of --also-make and --also-make-dependents.
--also-make builds all dependencies of the specified module. Example: mvn --projects module-1-that-uses-client --also-make clean install builds client-module and module-1-that-uses-client in this order.
--also-make-dependents builds the specified module and all other modules with a dependency to the specified module. Example: mvn --projects client-module --also-make-dependents clean install builds first client-module and then both module-*-that-uses-client.
See also the Guide to Working with Multiple Modules.

Maven dependencies with jenkins using incremental builds

I have a multimodule project, with one of the sub-modules depending on another as this:
pom.xml (parent pom)
|
+---- pom.xml (project A)
|
+---- pom.xml (project B) depends on A
I'm building it in jenkins, using the option "Incremental builds" (Maven job type). My problem is that when only project B has changes (that implies that jenkins is building ONLY project B), Jenkins is downloading latest snapshot from project A, instead of using binaries present in "target" directory of project A (generated in a previous build).
If full build is triggered, the problem goes away, and Jenkins uses correct binaries.
Has anyone have the same problem?
Thanks!
its not a problem, its the way maven operates. artifacts are always brought from the repository, even for multi-module builds. if you build the whole tree you just dont notice because the artifacts pulled from the local repo are the ones your build put there just a few minutes ago.
you'll get the exact same behaviour if you opened a command prompt to project B's root dir and executed a maven build from the command line - maven would look for A in the local repository (and the remotes, if not found) and wont look in A's /target directory.
if this was standard maven you could use maven's also-make flag from the root directory and tell maven to build project B and all of B's dependencies, which would make maven also build A.

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.

Resources