How to configure maven based project? - maven

I have a Spring Boot 2 project, the pom of this project contains some dependencies and two of those dependiencies are my another projects (libs). Lets call it LP1 and LP2.
To make SpringBoot run possible, I always need to run "mvn clean install" in the folder of LP1 than run it again in LP2 and now finaly run it again on SpringBoot2 project. Otherwise I got an error cause maven cant find LP1 or LP2 or both.
It is possible to configure my projects another way so I can run "mvn clean install" just once? My Folder Structre looks like this
Root
-SpringBootProjectFolder
-LP1
-LP2

Create a parent Pom for your project and add LP1 and LP2 as dependent modules. This way triggering the build for parent project will first build sub modules. For more details refer this How to make maven build of child module with parent module?

Related

How to ignore a maven pom.xml sub-module from parent clean install in intelliji

I work with intelliji and I have a parent module containing several sub-modules each having a pom.xml. I try to ignore a child sub-module from a clean install of the parent, right clicking on the child project then selecting Maven -> ignore Projects, but I have still an error on this child project telling me that the clean install on parent still takes into account this child project
I found another way to exclude a module. In the run/debug configuration, I execute
clean install -pl !module
The discussion is closed

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.

IntelliJ - How to link modules for maven goal

I have successfully imported a parent pom with child modules into IntelliJ. The child modules have dependencies between themselves and IntelliJ has correctly set up the classpaths so that changes to module A are reflected in module B. However these dependencies are not maintained when I execute a maven goal in IntelliJ (compile, jetty:run etc). Here is my structure:
client_libs
-- servlet-filter
-- filter-example
filter-example depends on servlet-filter. However when I run maven compile on filter-example I get:
The POM for com.cloudseal.client:servlet-filter:jar:1.0-SNAPSHOT is missing, no dependency information available
I can work around this by manually installing servlet-filter into my local repo before I execute a maven goal but obviously this is not ideal. How can I get IntelliJ to maintain the relationships between the modules when I execute a maven goal?
You shall be able to just run mvn package but from place/path where your parent pom is.
If this's not working for you, please post your pom.xml files.

How to rebuild dependencies before running jetty from 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.

Resources