How to generate a combined Maven site from unrelated projects? - maven

I would like to create a general overview of several Maven projects in the form of a website generated with the Maven site goal. The projects are part of different products, some have a parent-child relation, some have dependencies on others.
The site should combine the information from all projects and include JavaDoc, Checkstyle/PMD checks, test results and code coverage metrics.
I've created a POM file that aggregates each existing project as a module, with each project available in subfolder, but then the output is not combined into a single site.

You can do this by setting project.build.directory on all of your projects to a common folder. This can be accomplished by passing in the path as a parameter to the build. You can then run the site goal on the common target folder. If you run maven from in a continuous integration environment, you can do this by setting targetpath in your maven task. Otherwise you would have to specify it on the command line.
<project>
<build>
<directory>${targetpath}/${project.artifactId}</directory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>2.3</version>
<configuration>
<inputDirectory>${targetpath}</inputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
mvn clean deploy -Dtargetpath=Path/To/Build/Output
To keep the build the same for your developers, you could create a profile that is activated when targetpath is not provided by the command line.
<profiles>
<profile>
<id>dev</id>
<activation>
<property>
<name>!targetpath</name>
</property>
</activation>
<properties>
<targetpath>target</targetpath>
</properties>
</profile>
</profiles>

Related

Maven. Build only module that have deploy profile

Context:
I have a rather large system with several maven module formed in a hierarchy. When I need to develop I can go to the root and build using a specific profile -Pdeploy
The problem with this is that, my entire project is built (which takes a while) when I only in truth need to build a dozen lightweight modules that just deploy.
How should I got into improving the team's efficiency when deploying?
Basic Idea: You may not skip building modules but you may skip some of your plugin executions contained.
Usually your repository will already have build module artifacts present, so the overall speed should already be better once a previous build have been run and module artifacts can be pulled from there.
The idea is that you add a profile setting that defines skip-properties according to what you may want to omit when doing a deploy profile build only.
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault />
</activation>
<properties>
<skip.documentation>false</skip.documentation>
<skip.sign>false</skip.sign>
<skip.sources>false</skip.sources>
<skip.checks>false</skip.checks>
<skip.reports>false</skip.reports>
<skip.installer>false</skip.installer>
</properties>
</profile>
<profile>
<id>deploy</id>
<properties>
<skip.documentation>true</skip.documentation>
<skip.sign>true</skip.sign>
<skip.sources>true</skip.sources>
<skip.checks>true</skip.checks>
<skip.reports>true</skip.reports>
<skip.installer>true</skip.installer>
</properties>
</profile>
</profiles>
Your pom than might contain
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${version.maven-checkstyle-plugin}</version>
<configuration>
<skip>${skip.checks}</skip>
</configuration>
</plugin>
This method can be applied on a project pom level (pluginDependencies) or overridden in each module.

How can I make a pom.xml use local properties specific to each developer's local environment?

We have a maven project on our subversion server. There is a pom.xml inside the project. When I want to import project to my local computer and make my changes on it, I have to change this lines relative to my local system inside the pom.xml because I need to deploy project on my local system to test it before submit:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<webappDirectory>/opt/JBoss_4.0.4.GA/server/default/deploy/agg-gateway.war</webappDirectory>
</configuration>
</plugin>
Each of my team members should do that relative to their local systems.
But this settings must be unchanged on main project an I have not to submit pom.xml to subversion. If one of my team members changes this file, every time I update the project, I have to change it again relative to my local system.
Is there any way to make a file unchangeable on subversion? I can not control everybody to not to submit pom.xml to svn.
Injecting POM Properties via settings.xml:
Use a custom property in your ~/.m2/settings.xml which is specific to each developer:
<profiles>
<profile>
<id>local-weblogic</id>
<properties>
<local.weblogic.deployment.directory>/opt/JBoss_4.0.4.GA/server/default/deploy/agg-gateway.war</local.weblogic.deployment.directory>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>local-weblogic</activeProfile>
</activeProfiles>
and use a reference to the property in your pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<webappDirectory>${local.weblogic.deployment.directory}</webappDirectory>
</configuration>
</plugin>

Inherit only some properties or some plugins from parent poms

We have Oracle ADF and SOA projects that are built using custom Ant scripts, instead of normal Maven build. The same Ant plugin is configured differently for ADF and for SOA. The file structure isn't driven by the type of the project, but can be mixed, meaning:
- parent pom
- ADF
- SOA type1
- SOA type2
How can we set in the pluginManagement different versions of Ant plugins, and the children to pick whatever type of Ant plugin they want. As I know you can only pick what plugins you want, but not what flavor of same plugin.
I don't want to complicate my inheritance structure just for this. I need the structure to remain as it is, for release purposes.
The same I want with properties, I want to have some types of properties in central places, and a project to be able to use them, but also inherit the parent pom (for release purposes). Sort of like inherit from multiple parents.
I don't want to be tight by the need of properties and plugins (which are general for all projects, not just mine). I need to keep my pom structure clean, for release purposes.
You could try using profiles. They allow for the ability to customize a particular build for a particular scenario.
You can define multiple profiles in your parent pom each containing their own ant <plugin> section. Each profile would also have activation section. Then in your child modules you would have them activate the appropriate profile.
I'll try and give an example using some sudo code:
parent pom
<profile>
<id>adf-project</id>
<build>
<plugins>
<plugin>
<!-- adf specific ant plugin config -->
</plugin>
</plugins>
</build>
<activation>
<property>
<name>adfBuild</name>
<value>true</value>
</property>
</activation>
</profile>
<profile>
<id>soa-project</id>
<build>
<plugins>
<plugin>
<!-- soa ant plugin specific config -->
</plugin>
</plugins>
</build>
<activation>
<property>
<name>soaBuild</name>
<value>true</value>
</property>
</activation>
</profile>
Then in your soa module pom you would have the following:
<project ...>
<properties>
<soaBuild>true</soaBuild>
</properties>
</project>
This will then automatically activate that profile and use the correct ant plugin configuration.
Another option would be to define the plugin as normal but with multiple executions (one execution for soa and one for adf) and then in the child poms override each execution with a phase of none for those executions that you do not want to run. It should be noted that this latter approach is not recommended. See my answer here for more details on this.

How to skip unittests when using mvn scm:bootstrap

I'm trying to use the mvn scm plugin to check out the daily tag, and create an assembly from that version of the code. I configured the scm plugin and everythhing is working well, except that I can not seem to tell it to not run the unittests.
I tried:
Passing the -Dmaven.test.skip=true command line parameter
Creating a profile where the surefire plugin skips test, and list that profile in the scm configuration "profiles" section
setting the "maven.test.skip=true" as an environment variable
In all cases, when the scm plugin starts running the goals I told it to run in the configuration (see below), it also runs the unittests.
Below is the example I used to skip tests by using a profile:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.0</version>
<configuration>
<goals>install,assembly:assembly</goals>
<profiles>skiptest</profiles>
</configuration>
</plugin>
And this is the profile (I defined this in the pom.xml of the project):
<profiles>
<profile>
<id>skiptest</id>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
The command I use to do the checkout and bootstrap is:
mvn scm:bootstrap -DscmVersion=daily-20110427-421 -DscmVersionType=tag
I'm running mvn 2.2.1 on a Linux machine, and doing a checkout from a CVS repository. It's an existing project, I have continuous integration and tagging all up and running, I just want to check out a daily tag and create an assembly from that.
Any tips are much appreciated.
Edit: Got it to work with the answer below, but only after I upgraded to maven-scm-plugin version 1.1. Apparently, 1.0 did not propagate profiles.
Try this in the profile:
<profiles>
<profile>
<id>skiptest</id>
<properties>
<maven.test.skip>true</maven.test.skip>
</properties>
</profile>
</profiles>

change deployed artifact name based on profile

I have in a web application's pom file, a build profile, which does some necessary things (in my code) for qa testing.
I have this code on svn and this code is compiled in Hudson, which deploys artifacts in nexus..
Hudson has two jobs, one for qa profile (-P qa) and one for customers.
What i need is that i change in my qa profile the artifact's name during deploy phase, so that nexus has two different war files, one for qa and one for customer.
I use (after Google search) the following which looks like it does nothing in hudshon!
<profile>
<id>qa</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.5</version>
<configuration>
<classifier>qa</classifier>
</configuration>
</plugin>
</plugins>
</build>
</profile>
any ideas someone?
You actually need to set the "classifier" configuration option on the plugin that's building the package that's being deployed: maven-(ear|ejb|jar|rar|war|shade)-plugin:
For instance, to build a WAR with a qa classifier, you would do the following:
<profile>
<id>qa</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<classifier>qa</classifier>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Also, instead of setting the classifier you could set any of the following (most default to project.build.finalName, so setting that property updates many of these):
General
project.build.finalName
War Plugin
warName
Ear|Jar|Rar|Shade Plugin
finalName
EJB Plugin
jarName
One final note: I never realized this before, but looking over the documentation, it looks like the RAR plugin doesn't support the "classification" option. Shade does support the classifier concept, but does it via the "shadedClassifierName" property.

Resources