How to rebuild dependencies before running jetty from maven - maven

I have a multi module maven project. One of the modules is a reusable part which is packaged into a jar, and the other is a war web-app which depends on the first module. When I use jetty:run-exploded on the second module, the packaged jar is taken from local maven repository whereas I want the first module to be rebuild and packaged into the resulting war. Is there any way to force such behavior instead of the default one?

From everything I can tell from reading documents about Maven's design and using Maven myself this cannot be done in the projects own directory.
Maven will not follow module paths UP a hierarchy. Using -amd (also make dependencies) will only work at the top level module that ties all the other multi-module pom's together. So what you can do is this:
At the TOP level directory
mvn -amd -pl jetty_module jetty:run-exploded

I think you can use maven Advanced Reactor Options to archive this.
http://www.sonatype.com/people/2009/10/maven-tips-and-tricks-advanced-reactor-options/
The -pl or –projects option allows you to select a list of projects from a multimodule project. This option can be useful if you are working on a specific set of projects, and you’d rather not wait through a full build of a multi-module project during a development cycle.
Maven -amd(also-make-dependents ) also help to build multi module project once. Using that you can build a project and any project that depends on that project.

Related

Maven multimodule build. I want to deploy the ear to our Repository, but not the other modules

We have multi-module project that consists of 17 modules. There'a base jar module. There are 15 filter jar modules that depend upon that base jar. Then, there's the Ear that we build that contains the 16 other jars.
We have the build working just fine, but we'd like to deploy our Ear to our Maven repository -- mainly because it'll make it easy for our deployment tools to get to it. Plus, we can easily do that via mvn deploy without having to put together another tool.
The problem is that when we say mvn deploy, we deploy the Ear and the 16 other jars. Those jars are not used in any other project, and we simply don't want them clogging up our Maven repository.
Is there a way to specify that a particular module doesn't get put into the Maven repository when I say mvn deploy?
Looking through the documentation, I found the ${maven.skip.deploy} property. I actually set this to true in the parent project, then set it to false in the EAR build. That does what I want, deploys only the EAR. This way, if another module is added, it will by default not be deployed.
steve c recommended mvn -pl core-ear clean deploy which doesn't work in my circumstance. The module I want to deploy is actually a module of a module, so the main level build doesn't see it.
Our structure is like this:
parent --|
|-engine
|-filter1
|-filter2
.
.
|-distribution --|
|--jar
|--sar
|--ear <-Deploying this one only
khmarbaise mentioned setting <skip>true</skip> in all of the modules except for the one I want to deploy. khmarbaise recommends against this, and I don't blame him. However, there are several issues here. First, we're doing continuous delivery which means that we will have a new version in our repository for each build. I also want to make sure no one tries to depend upon these jars.
I set the property ${maven.deploy.skip} to false in my parent module. This means it's that way in all of my modules and none of them will deploy. I don't need to configure my maven-deploy-plugin in order to set this.
I then set ${maven.deploy.skip} to true in the only module I actually want to deploy (which is the ear module of the distribution submodule). Running mvn clean deploy from the parent now only deploys the ear distribution module I actually want to deploy.

How to run maven plugin for only root of multimodule project [duplicate]

I have maven multi-modules project. At the parent level, i have some java files. And in the parent pom.xml, at the package phase i do some stuff.
Usually, when i run mvn package at parent level, the package phase of parent pom will be run and all the modules will be packaged as well.
I am looking for a way that allow me to do these (when i run mvn package):
allow me to run only paren pom.xml (the script at the package phase), not the modules. This is the 1st priority.
allow me to run paren pom.xml and some particular modules (like module 1, module 2 BUT not module 3 , module 4).
Can i use profile for those issue?
Thanks.
While I agree with the fact that you may not have optimal project structure, the answer is that Maven 2.2.1 has an option "--non-recursive" which satisfies your first requirement:
-N,--non-recursive Do not recurse into sub-projects
So something like this:
mvn --non-recursive clean compile
Why do you want to have java code on the top level? In my opinion this is not a very good idea. Have your code in the subprojects and let the top-level project be responsible for holding the general information and configuration of the entire project.
If you have some base-library code in the top-level project now, you can put it in a sub-project and set up dependencies between the projects.
Take a look at Maven parent pom vs modules pom
The nature of your question indicates that your project structure may not be optimal.

In a Multi-Module maven project, is it possible to have module B depend on a Plugin provided by Module A

I am trying to build a project containing multiple modules, one of which is a maven plugin which we use to generate sources further down the tree as such:
Module A: generator-plugin
Module B: uses generator-plugin
But when I try to build the parent project (doing a mvn clean deploy) during the clean phase, it tries to resolve the generator-plugin, which is obviously before it's built it.
Is there a way for this to be done without separating out the modules and building it first manually?
With Maven, I would suggest doing the most straightforward thing which would work and I think you know what that is--just make these two things separate Maven projects.

Maven Nested Multi-module project

I am building a multi-module project where one of the modules is also a multi-module project. When I try to build the nested multi-module independently using -pl <multi-module child>, Maven only builds the pom(the top-level module of the child) and does not build the rest of the modules specified in the multi-module project.
If I don't use the -pl and build all the modules, everything work fine, the project builds as intended.
Any ideas why this might be happening, I can't get Maven to build the entire project if I single it out individually?
The -pl option builds exactly the projects that you specify. Maven treats a parent POM as a regular project that happens to be the first in the hierarchy.
What you can do is browse into your "sub-multimodule" project and execute Maven from there. The option -rf (resume from) might also work.
There is no good reason for Maven behaving that way, other than this is how Maven always behaved for -pm. The -am option could include the modules listed of any module listed in -pl, because the parent "depends on them" in a way, but because they are not dependencies in the strict sense, Maven does not.
If Maven were an active project, a new -amm also-make-modules option might help.
I think the better way to achieve that is to use -pl to refer to one of the grandchild submodules. As it probably depends on its siblings, will can possibly achieve the same result.
This project is a great example on how to do that:
https://github.com/andyglick/maven-multi-level-modules-project
In short, you can do:
mvn test -pl com.example:my-grandchild-module -am

Why does maven recognize dependencies on only installed POM files?

I've got a project with Maven in which one subproject (A) wants to depend on another subproject (B) which uses "pom" packaging.
If I do this the straightforward way, where A specifies a dependency on B with <type>pom</type>, things work perfectly if I do "mvn install", but if I run any phase earlier than install, such as mvn compile or mvn package, then it fails while trying to build A: it goes looking for B's pom in the repository, and doesn't find it.
I don't really want this pom in the repository, because it's part of our active source code and changes frequently.
For all the jar-packaged projects we build, it seems to work fine to keep them out of the repository, build with mvn package, and Maven knows how to find all the dependencies in the source and build trees it manages without resorting to the repository; however for the pom-packaged project it always wants to go to the repository.
A couple things I learned while trying to understand this:
Maven best practices encourage you to use pom-packaged projects to group dependencies, but with the added step of "mvn install" on the POM project
Maven lifecycle documentation says "a project that is purely metadata (packaging value is pom) only binds goals to the install and deploy phases"; maybe this is why the POM project is invisible as a dependency target unless I invoke the install phase? I tried binding the compiler plugin to the compile phase and this didn't seem to help.
Is there a way that I can specify the POM subproject as a dependency of another subproject in the same parent project, without installing the POM project to the repository?
It isn't purely a question of which goals are bound to which lifecycle phases for POM projects. If it were, then binding the "package" goal would solve the problem.
When building a multi-module project, Maven reads the POMs of all modules to determine dependencies between modules, so that it can build the depended-upon modules before the depending modules. It's able to achieve this even when running the "package" goal (such that the depended-upon modules are not yet in the local repository).
Therefore, the code that constructs the classpath for builds must be managing several cases, notably:
extra-project jar dependency, where it looks for the POM in the local repository, handles its dependencies, and adds the POM's jar to the classpath
extra-project pom dependency, where it looks for the POM in the local repository and handles its dependencies
intra-project jar dependency, where it looks for the POM within the project tree, handles its dependencies, and adds that module's target/classes folder to the classpath
intra-project pom dependency, where for some reason it doesn't look for the POM within the project tree, and therefore doesn't handle it's dependencies.
Notice the asymmetry in the last two cases, as compared to the first two.
I can see two solutions to your problem. One is to file a bug report, or rather a request to change the behaviour (since it's obviously intentional), perhaps only for the case of intra-project dependencies on multi-module projects. Or indeed propose a patch. But since the behaviour is intentional, you might meet a refusal. In the best of cases, you're in for a long wait. (I'd vote for your bug report though - I've been stung by that same behaviour, in a different context.)
The other solution is simply to run an install on your project. I don't really understand why you don't want the POM project in your repository: if needs be, you can use a snapshot repository, where it doesn't matter if things change frequently, to avoid polluting your main repository.
Configuring maven-install-plugin to run during the compile phase, and copy the relevant pom.xml to the repository, seems to accomplish what I wanted as far as Maven itself is concerned, though m2eclipse still is not happy (it throws "failed to read artifact descriptor" errors with no additional description for the pom.xml that has a dependency on the other POM project).

Resources