Parent pom calling multiple builds on child with parameters - maven

My parent pom has multiple children and one of them packages war and the rest jar. The unusual circumstance is that the war child project should generate two wars that are almost identical minus some minor configuration settings.
The way I do it at the child level is:
mvn install -Dinst.name=inst1 -Drepl.val=val1
which creates a war named inst1 that contains a properties file containing val.
When I run
mvn install -Dinst.name=inst2 -Drepl.val=val2
It creates inst2.war containing a properties file with the token replaced with val2 etc.
How can I configure the parent pom to call two builds on this sub project and submit the parameters inst.name and repl.val through the pom configuration that I, in the above example, supply via command line?

You can create two wars or two jars using single pom (but it not recommended as it violates the basic concept of maven: modularity) by two ways.
Using maven profiles. You can configure the configuration of the war plugin differently in the profile and enable it using -P argument when you call maven
Using two separate configuration of the war plugin. You can bind the war goal to the package lifecycle phase mulitiple times to generate multiple artefacts.

Related

Maven goal to move file to another directory

I need to move the war generated to some other directory with maven goal.
I know how to move it to another location by adding configuration in pom.xml but i need to do it with a goal.
Which i can run directly without using pom.xml
like: mvn jboss-as:deploy-only deploys jboss with war generated without including any plugin specific configuration in POM.
Their are some restrictions to plugins which can be used in pom. So need to use Maven Goal only

Maven multimodule project with Jenkins and git

Currently we have a number of maven projects (specifically Apache Camel) that reside in isolation. We also have one Jenkins job per project because we need to specify the pom.xml file in the maven build and since the projects are independent then we require one job per project.
However, we also know most of the projects share a lot of dependencies and we want to turn them into a maven multi-module project with a parent pom file where the dependencies and versions are stated. We also want to have fewer Jenkins jobs to maintain and allow more projects to be added without having to create new Jenkins job.
My question is, in the Jenkins job for the maven build I still need to specify a single pom file. Does this mean that I need to point to the parent pom file and then add theparent directory as the directory to for Jenkins to receive the git trigger? In a sense, whenever a code is committed to any of the child projects, the job gets triggered and it uses the parent pom file to build only that project where the code was committed?

How do I set up a TeamCity build job to execute a maven job with no pom

We have an in-house developed MOJO that generates content and doesn't require you to have an existing project or POM. Think of the maven archetype plugin, where you can just run mvn [mojo]:[goal] and have maven just execute that goal without a POM.
This MOJO connects to a specific database instance in a specific environment, and generates some metadata for the contents of the database, so our testers can inspect the metadata and locate production-like data that has certain attributes they need for a given test.
When you execute the metadata mojo, maven resolves the MOJO from the available repo's (in our case an Artifactory repo), and it then does its work and returns. It does not create any artifacts or other outputs.
We use TeamCity as our CI server, but it also has metadata generation jobs so with one click a dev can kick of a metadata generation job against a specific database.
The problem with this is the Maven runner in TeamCity requires a POM. If TC hasn't already checked out a project from a VCS, or the project it's checked out doesn't have a POM, the maven runner won't do anything. In this case, there is nothing to check out (the MOJO is resolved from Artifactory) so there is no POM.
I can set up the TC job to use the Command Line runner and have it execute, say, mvn com.example:metadata-generate -DenvironmentName=UAT1, but then it's impossible to specify the maven settings file that maven should use.
So my question is, how do I do this? Is it possible to have the maven runner execute an arbitrary maven command without needing a POM? Alternatively, using the Command line runner, is it possible to have a TC job copy a specific maven settings file to the build agent so it can be referenced in the maven command as mvn com.example:metadata-generate -DenvironmentName=UAT1 -s {path-to-settings-file}?
So its turns out that TC handles pom-less maven builds just fine. My problem was that the MOJO was not declared to not require a project.
Comparing my MOJO with the MavenArchetypePlugin source, I needed to declare my MOJO with the class level javadoc tag #requiresProject false.
Once I had that in place, TC ran my pom-less job perfectly well. All I had to do was clear the Path to POM file: field in the TC build configuration and leave it blank.
You can customize the name of the pom file that you use as an argument into the maven build-step in the teamcity and use this as the second "build step".Lets call the parameter as pom.file.name
In the first step , resolve all the in-house dependencies that you have and set the name of the pom file you want to execute into the variable pom.file.name
If you want to know more about how to change tha value of a variable in teamcity, you can read about it here

Build child jar using parent war using maven

I need to create a dependent maven project.
The child one should be a jar, that would be called by the parent project which should be a war file.
The steps should be like this. When I build the war, it should automatically build the jar file and include it and build the war and show output of the child jar (suppose a simple print statement).
Note: Build should be done only once and that is for building the final war.
Need to edit the pom.xml accordingly.
I am new to maven,so a bit elaborate solution would be very helpful.

How to build two different jar packages with maven-assembly-plugin?

My project consists of three maven packages and application class (in default package). The existing configuration (defined in pom.xml) uses maven-assembly-plugin to create single executable jar-with-dependencies.
I'd like to add an execution *descriptorRef* \ whatever to create a distributalbe jar package that will contain only classes from two packages out of three (one is a mock-up).
Is it possible?
If I define an configuration can I make it relate to one but not the other?
I have absolutely done this. You can configure multiple executions of the Maven Jar Plugin in the package phase and specify different includes / excludes for each execution.
See Maven Jar Plugin documentation, particularly the section entitled: "How to create an additional attached jar artifact from the project."
If you must use the Assembly plugin, you should just create a new assembly descriptor using the jar-with-dependencies as a template, but adding the inclusions / exclusions to your liking.

Resources