Reputation: 21
i've a question I can't answer by myself.
Introduction: We've developed a corporate pom which enforces some rules on projects, provided some company wide profiles, distribution management, etc.
Most of our developer use the corporate pom, but not everyone does, and furthermore not all migrate old projects within the next development cycle.
So I decided to write a maven plugin which simply checks whether someone builds a project on developement stage (not qs/prod) and whether the user uses our corporate pom.
Problem: I want to force the plugin to execute on every "mvn clean install" or something similar without configure the plugin within the project pom. My first guess was the settings.xml, but unfortually you can't execute plugins via settings.xml.
Does someone have a solution?
Question in short: Force a plugin execution on every build without providing the plugin in the project pom and or command line!
Upvotes: 1
Views: 96
Reputation: 21
As Robert mentioned it may be better to validate this kind on the infrastructre instead on the developer machine.
A pre-receive hook in git does the trick.
#!/bin/bash
#
# Hook simply validates whether the corporate pom is used
# and rejects the commit when the corporate pom is absent
echo "### Validate commit against Company rules... ####"
corppom_artefactId='corporate-pom'
oldrev=$1
newrev=$2
refname=$3
while read oldrev newrev refname; do
pom=`git ls-tree --full-name -r ${newrev} | grep pom.xml | awk '{ print $3 }'`
# Project seems not to be a maven project. So it's okay that the corporate pom is missing
if [ -z ${pom} ];
then
continue;
else
git cat-file blob ${pom} | grep $corppom_artefactId >> /dev/null
if [[ $? -ne 0 ]];
then
echo "### NO CORPORATE POM... Bye Bye ###"
# Rejecting commit
exit 1;
else
echo "### CORPORATE POM IS USED. GREAT! ###"
fi
fi
done
Be aware that this script is just an example! It will not work on multi module projects and furthermore is not coded very well. But as solution approach it is sufficient.
Upvotes: 0
Reputation: 12345
In general you don't control the system of the developer, so trying to solve this with the settings.xml of with the Maven distribution is not the way to go. You must look for the placing which is used by every project. One system could be the SCM, but adding hooks there is probably hard. Assuming you have a artifact repository manager, that is the place to do these kind of checks. I know both Nexus and Artifactory can validate the uploaded files, and are especially strong in analyzing the pom.xml So your focus should not be on trying to solve this with a maven plugin, but on a common place in the infra.
Upvotes: 1