maven-release-plugin does not work for multi-module POMs - maven

Plugin version: 2.0
I am trying to use the maven-release-plugin to set the version of the parent POM and all modules.
Using the following parent POM:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>uk.co.mycompany</groupId>
<artifactId>myProject</artifactId>
<version>latest-SNAPSHOT</version>
<packaging>pom</packaging>
<name>My Project</name>
<modules>
<module>../../subPom1</module>
<module>../../subPom2</module>
<module>../../subPom3</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>clean</phase>
<id>set-release-versions</id>
<configuration>
<developmentVersion>1.1.8</developmentVersion>
<autoVersionSubmodules>true</autoVersionSubmodules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
When running mvn clean install -DskipTests -Pdeploy, the configuration to run the plugin on the clean phase is totally ignored and the build is made using the value "latest-SNAPSHOT".
I was expecting it to pick up the value "1.1.8" from the plugin configuration.
Each child POM is equivalent to:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>uk.co.mycompany</groupId>
<artifactId>myProject</artifactId>
<version>latest-SNAPSHOT</version>
<relativePath>../../System/build/parentPom.xml</relativePath>
</parent>
...
</project>
Why is the configuration ignored?
Edit #1: Filesystem structure as requested:
/
|- system
| |
| |- build
| |
| |-parentPOM file
|
|- business
| |
| | - childPOM1
| | - childPOM2
|- client
| | - childPOM3
| | - childPOM4
Ignore the .../... in the SSCCE - I have obfuscated the true values to describe the problem generically.
Edit #2: I have moved the definition to <pluginManagement> as advised but the problem remains the same (not using plugin, no feedback to console):
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.0</version>
<configuration>
<developmentVersion>1.1.8</developmentVersion>
<autoVersionSubmodules>true</autoVersionSubmodules>
</configuration>
</plugin>
</plugins>
</pluginManagement>

You forgot to set the goal of the plugin. You configured the parameter needed for the update-versions goal but you told maven only to execute the plugin in the clean phase, but not which goal of the plugin. So it does nothing at all.
Check the maven log when you try a mvn clean it should only show:
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) # test ---
When you change your config to:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>clean</phase>
<id>set-release-versions</id>
<goals><goal>update-versions</goal></goals>
<configuration>
<developmentVersion>1.1.8</developmentVersion>
<autoVersionSubmodules>true</autoVersionSubmodules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The goal update-versions is called in the clean phase of maven.
[INFO] --- maven-release-plugin:2.0:update-versions (set-release-versions) # bdd ---
Not sure if this will solve all your problems but this will force maven to execute the plugin in the clean phase like expected.
However the release plugin needs a lot of special settings (like a scm connection) when used for only changing the version. So I suggest to use the versions-maven-plugin
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<goals>
<goal>set</goal>
</goals>
<phase>clean</phase>
<configuration>
<newVersion>1.1.8</newVersion>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

In the end, I gave up.
That Stack Overflow et all is littered with unanswered questions just like this one, and that the plugin documentation fails to provide usage examples in POM format, tells me everything that I need to know about this plugin.
My workaround was to set the parent POM's version to "latest-SNAPSHOT" and introduce a property called <myproject.release.version>, which I used everywhere that I wanted to print the release number.
In particular, I wanted to print the release number in the WAR file's manifest. I did so as below:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Implementation-Version>${myproject.release.version}</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
<executions>
<execution>
<id>war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
<configuration>
<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
<filters>
<filter>${project.parent.basedir}/filter/${webapp.filter}.properties</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
Using the above configuration, I drop the release number, as a Maven property, into my manifest.
In my application, I pick it up from there and draw it on the screen.

Related

Checkstyle not working in build or verify phase

I cannot get maven checkstyle to run on build or verify, despite copy & pasting the code directly from the checkstyle website.
I can see checkstyle working fine and finding problems when running mvn checkstyle:check, but not on any phase like clean compile verify. These phases just compile fine and find no problems, completely ignoring checkstyle. I set up a minimal example here. The pom.xml is as follows:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>checkstyle-test</groupId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>15</java.version>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
</properties>
<modelVersion>4.0.0</modelVersion>
<artifactId>core</artifactId>
<version>0.0.2</version>
<packaging>jar</packaging>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<failOnViolation>true</failOnViolation>
<linkXRef>false</linkXRef>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
You need to bind Checkstyle execution to the verify phase, like this:
...
<execution>
<id>checkstyle-check</id>
<phase>verify</phase>
<configuration>
<sourceDirectories>${project.build.sourceDirectory}</sourceDirectories>
<configLocation>config/checkstyle_checks.xml</configLocation>
<encoding>UTF-8</encoding>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
...
This snippet is taken from one of my projects, you can view the entire pom.xml here.
Figured it out: I had the block in <pluginManagement>. Moving it out of there it instantly worked. I wished, maven would have more complete example on their website.

How to delete .original file after Spring boot maven build

After built, we are getting two jars.
One myjar.jar with all dependencies and another one myJar.jar.original without dependencies. How to delete the myJar.jar.original file ?
<build>
<finalName>myJar</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
</executions>
<configuration>
<mainClass>${start-class}</mainClass>
</configuration>
</plugin>
</plugins>
</build>
This is how you could do it with maven-antrun-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<delete file="target/myJar.jar.original" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
Based on the question apparently there are two possible ways you are getting myJar.jar.original.
1. There might be repackage configuration in your pom.xml which repackages a jar or war that is built during the package phase of the Maven lifecycle.
Here is sample pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- ... -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.2.1.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
If the above configuration is present then you simple $ mvn package command will generate myJar.jar.original and myJar.jar
$ mvn package
$ ls target/*.jar
target/myJar.jar target/myJar.jar.original
Secondly you might be using maven repackage to build you mvn
$ mvn package spring-boot:repackage
$ ls target/*.jar
target/myproject-1.0.0.jar target/myproject-1.0.0.jar.original
So please check your maven configuration and if you have the repackage in your pom than please remove it. Else if you are building using "$ mvn package spring-boot:repackage" than i would suggest you "$ mvn package"

Integrate jQAssistant in Maven build using profile and running server

I'm trying to integrate jQAssistant into my existing Maven build. I have a hierarchy of POMs, but basically the top POM defines what the build does. That's where I have my <pluginManagement> and my build plugins that are always used. I also have a couple of Maven profiles for special builds.
So, I want to scan all classes during build time and aggregate the results into a running server to have a fully populated Neo4J database after the build of all my Maven modules. The database should contain my whole code base.
Analysing and checking would be a different step, I don't want to do that directly when building a Maven module.
The examples I see all build a local database and then check the classes against it. As far as I understand it, I would have to run the server as a daemon and then configure the Maven plugin to use the 'bolt' URI to populate it - is this right?
Also, since I don't want to slow down the 'normal' build, I added a Maven profile to active the jQAssistant scan. However, this only works on my top POM, but doesn't work in any other Maven project/module. The inheritance of profiles is a normal and expected Maven feature - so what am I doing wrong?
Here's my parent POM. Just to see whether the profile is active, I added PMD as well:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<groupId>foo</groupId>
<artifactId>parent</artifactId>
<version>1.50.0-SNAPSHOT</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<version>1.5.0</version>
<configuration>
<useExecutionRootAsProjectRoot>true</useExecutionRootAsProjectRoot>
</configuration>
</plugin>
</pluginManagement>
</build>
<profile>
<id>architecture</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>pmd</goal>
<goal>cpd</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<executions>
<execution>
<id>scan</id>
<goals>
<goal>scan</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</project>
When I run mvn clean package -P architecture on a Maven project with that parent POM, I see the following output, which shows that the profile is active:
09:30:12.316 [INFO]
09:30:12.316 [INFO] --- maven-pmd-plugin:3.5:pmd (default) # util-type ---
09:30:15.073 [INFO]
09:30:15.073 [INFO] --- maven-pmd-plugin:3.5:cpd (default) # util-type ---
09:30:15.976 [INFO]
However, jqassistant-maven-plugin is nowhere.
Now, if I add it to my normal <build> plugins:
<build>
<plugins>
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<executions>
<execution>
<id>scan</id>
<goals>
<goal>scan</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
then I see the following output for mvn clean package for my parent POM:
10:38:14.252 [INFO] --- jqassistant-maven-plugin:1.5.0:scan (scan) # parent ---
10:38:15.684 [INFO] Loaded jQAssistant plugins [CDI, Common, Core Analysis, Core Report, EJB3, GraphML, JAX-RS, JPA 2, JSON, JUnit, Java, Java 8, Java EE 6, Maven 3, OSGi, RDBMS, Spring, TestNG, Tycho, XML, YAML].
10:38:15.952 [INFO] Connecting to store at 'file:/C:/jp/maven-parents/parent/target/jqassistant/store/'
10:38:20.058 [INFO] Initializing embedded Neo4j server 3.x
10:38:20.078 [INFO] Resetting store.
10:38:21.515 [INFO] Reset finished (removed 8453 nodes, 29427 relations).
10:38:22.372 [INFO] Entering C:/jp/maven-parents/parent/target/failsafe-reports
10:38:22.378 [INFO] Leaving C:/jp/maven-parents/parent/target/failsafe-reports (1 entries, 4 ms)
However, in my Maven project, I don't see any jQAssistant output.
Starting mvn help:effective-pom -Parchitecture gives me the same output for the parent project and the Maven module:
<plugin>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.5</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>pmd</goal>
<goal>cpd</goal>
</goals>
<configuration>
...
</configuration>
</execution>
</executions>
<configuration>
...
</configuration>
</plugin>
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<id>scan</id>
<goals>
<goal>scan</goal>
</goals>
<configuration>
<useExecutionRootAsProjectRoot>true</useExecutionRootAsProjectRoot>
</configuration>
</execution>
</executions>
<configuration>
<useExecutionRootAsProjectRoot>true</useExecutionRootAsProjectRoot>
</configuration>
</plugin>
In my projects I have a parent POM with the following plugin management section:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<version>${jqassistant.version}</version>
<configuration>
<useExecutionRootAsProjectRoot>true</useExecutionRootAsProjectRoot>
</configuration>
<executions>
<execution>
<id>scan</id>
<goals>
<goal>scan</goal>
</goals>
</execution>
<execution>
<id>analyze</id>
<goals>
<goal>analyze</goal>
</goals>
<configuration>
<failOnSeverity>MAJOR</failOnSeverity>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
I also defined the following profile, which I use to run jQAsssistant:
<profile>
<id>verify-architecture</id>
<build>
<plugins>
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
Using mvn -P verify-archicture clean install I can scan and analyze my projects.
Here we are, some years later :-)
And coming back to my mistake!
The problem here was the Maven phase. The jQAssistant plugin Mojo scan has the Maven phase post-integration-test by default.
However, we never do mvn clean install in my company, we only do mvn clean package and install using Jenkins, Nexus etc. etc.
So, it was my fault to not force the plugin to the package phase.
That's how it works:
<profile>
<id>jqassistant</id>
<build>
<plugins>
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<executions>
<execution>
<id>scan-software</id>
<phase>package</phase>
<goals>
<goal>scan</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

How to maintain daily SNAPSHOT build using TeamCity in C# projects

I am taking over a project which consists of around 15 projects, whose continuous integration practice was done (the practice was ceased and I need to re-start it in a new environment) by Maven + Nexus OSS + TeamCity and are developed using C#.
What I got, except for those C# solutions themselves, is a POM for each of these project, and another parent POM (which doesn't contain any code) which every other project has parent of. These development POMs only have inter-dependency on SNAPSHOT versions hence the build order is crucial. But these POMs that I have do not need any VS plugin, which means (I guess) the compile procedure is not done by Maven but by TeamCity (VS runner). The Maven scripts I have are probably only in charge of e.g., downloading dependencies, validating and installing/deploying/releasing. Unfortunately I can't find any TeamCity configurations so I have no clue how this was done before.
EDIT:
I'll try to put some POM and script file that I have and see if someone can see some clue on the build procedure.
The files I got from SVN are mainly in three kinds categories:
1) The C# source code and project/solution files. Each solution has a 'Dependency' folder which contains all the dependencies, both on other projects on third-party dlls, so that this solution can be built in VS by the developer right after he checkout this solution.
2) The (development) POMs.
Firstly I have the POM of the parent project. This project doesn't contain any code but only the POM and some scripts (other projects have similar files too). The POM looks like this:
<modelVersion>4.0.0</modelVersion>
<groupId>MY.GROUP</groupId>
<artifactId>configuration</artifactId>
<version>1.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Configuration</name>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>purge-local-dependencies</id>
<phase>clean</phase>
<goals>
<goal>purge-local-repository</goal>
</goals>
<configuration>
<!-- Whether to purge only snapshot artifacts. -->
<snapshotsOnly>true</snapshotsOnly>
<actTransitively>false</actTransitively>
<reResolve>false</reResolve>
</configuration>
</execution>
<execution>
<id>unpack-dependencies</id>
<phase>validate</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${dependencies.directory}</outputDirectory>
<markersDirectory>${dependencies.markers.directory}</markersDirectory>
<useBaseVersion>true</useBaseVersion>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<excludeTransitive>false</excludeTransitive>
<useSubDirectoryPerArtifact>true</useSubDirectoryPerArtifact>
<stripVersion>true</stripVersion>
<stripClassifier>true</stripClassifier>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>assembly-single-zip</id>
<phase>prepare-package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>${project.build.finalName}</finalName>
<descriptors>
<descriptor>${assembly.file}</descriptor>
</descriptors>
<attach>false</attach>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.1</version>
<executions>
<execution>
<id>deploy-file-snapshot</id>
<phase>verify</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<file>${deploy.file}</file>
<repositoryId>${nexus.repository.id}</repositoryId>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<url>${nexus.repository.url}</url>
<pomFile>${nexus.deploy.pom}</pomFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<preparationGoals>clean</preparationGoals>
<tagBase>${release.tagBase}</tagBase>
<tagNameFormat>#{project.version}</tagNameFormat>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
...
Here we see that the plugins used in the build are dependency (to download dependencies), 'assembly' (to package), deploy (to deploy files to Nexus) and release--frankly I can't figure out how it is used. The scripts that I have (I'll describe later) don't use it explicitly and it doesn't seem to be executed in other standard build phases.
And in each of the solution the POM has parent of the configuration. And they look like this:
ProjA
<parent>
<groupId>MY.GROUP</groupId>
<artifactId>configuration</artifactId>
<version>1.0.1-SNAPSHOT</version>
</parent>
<groupId>MY.GROUP</groupId>
<artifactId>ProjA</artifactId>
<version>1.1.2-SNAPSHOT</version>
<packaging>pom</packaging>
<name>ProjA</name>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
</plugin>
</plugins>
</build>
...
In ProjB which depends on ProjA, the POM is like this:
<parent>
<groupId>MY.GROUP</groupId>
<artifactId>configuration</artifactId>
<version>1.0.1-SNAPSHOT</version>
</parent>
<groupId>MY.GROUP</groupId>
<artifactId>ProjB</artifactId>
<version>1.2.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>ProjB</name>
...
<dependencies>
<dependency>
<groupId>MY.GROUP</groupId>
<artifactId>ProjA</artifactId>
<version>1.1.2-SNAPSHOT</version>
<type>zip</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
</plugin>
</plugins>
</build>
...
3) Then some .bat scripts as well as deploy.pom and release.pom.
The deploy pom and release pom just simply replace the version numbers and declare the dependencies:
deploy.pom for ProjA:
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MY.GROUP</groupId>
<artifactId>ProjA</artifactId>
<version>1.1.2-SNAPSHOT</version>
<packaging>pom</packaging>
..<dependencies>...</dependencies>
By deploy I assume it means the the deployment of SNAPSHOT version as the version number indicates.
And the release.pom are basically the same but change the version to release version (in ProjA it is 1.1.1).
In each solution I also have some scripts which I believe are called by TeamCity. a) a file called download.bat, which basically calls mvn -U clean and then mvn -U validate. And b) a file called upload.bat which basically calls mvn prepare-package and then mvn verify. In both scripts we pass some mvn options like -DDeployPomFile, -DNexusUrl, -DRepositoryId. From the parent POM we can see some plugins are executed in those scripts too. And I guess the download.bat is called before TC is executing the VS build and upload.bat is called after the build (assume the target of the build is to publish the latest version).
Above is all I got. I suspect I still miss some TeamCity configuration because they are not stored in the SVN. But anyway, can somebody help figure out how to manage the daily build? Thank you very much!

Maven tests run twice when a profile identifier is in multiple projects. Why?

I have numerous projects in IntelliJ, each of which has a pom.xml, and each of the projects' poms inherit from the master pom.xml. One profile (called test1) is present in two of the poms (for project2 and project4). When I run maven from the command line, specifying one project and the profile name, it works (the tests in that project are executed once) Here is the commmand:
mvn test -pl project2 -am -P test1
When I specify both projects (both of which have the same profile present), the tests in project4 are executed twice. Here is the command:
mvn test -pl project2,project4 -am -P test1
I would like the tests only to be executed once. I am running maven 3.1.1.
As a further complication, when I specify just project4, the tests in project2 get executed once, and the tests in project4 don't get executed at all. Here is the command:
mvn test -pl project4 -am -P test1
Here is pom.xml for project2:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns stuff...>
<parent>
<artifactId>parent artifact id</artifactId>
<groupId>group id</groupId>
<version>version</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<name>project2</name>
<artifactId>project2</artifactId>
<packaging>jar</packaging>
<profiles>
<profile>
<id>test1</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>execute-tests-1</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<excludes>
<exclude>com/path/to/exclude/**/*.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
<!-- We don't want to run any tests without an active profile -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<!-- This exports the classes in the tests for use with our other modules' tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
[ dependencies ...]
</dependencies>
</project>
Here is the pom.xml for project4:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns stuff>
<parent>
<artifactId>[parent artifact id]</artifactId>
<groupId>[group id]</groupId>
<version>[version]</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<name>project4</name>
<artifactId>project4</artifactId>
<packaging>jar</packaging>
<dependencies>
[ dependencies ...]
</dependencies>
<profiles>
<profile>
<id>test1</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>execute-tests-2</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>com/path/to/tests/*.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
[ dependencies...]
</dependencies>
</profile>
</profiles>
</project>
I figured out the answer to my own question (by looking carefully at some of our other projects' Maven test setup). I had to do two things:
Include a <skip>false</skip> element in the <configuration> aggregate in the surefire plugin.
Include a generic surefire <plugins> aggregate outside of the <profiles> section. This one has <skip> set to true and prevents tests being run unless they are in a profile. Here is what the section looks like:
<build>
<plugins>
<!-- We don't want to run any tests without an active profile -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
The problem was that the tests were running the default-test lifecycle phase and then they were running again in the test phase. After I made the change they only ran in the test phase.

Resources