I have following segment in the parent pom.xml file
<groupId>my.group</groupId>
<artifactId>artifact</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>../A</module>
<module>../B</module>
</modules>
<profiles>
<profile>
<id>P1</id>
<modules>
<module>../B</module>
</modules>
</profile>
<profiles>
When i try to execute the compile goal of this pom file with the profile P1 (In IDEA 14 Maven Projects window) it will compile the both module A and B.
But if I remove the modules segment, It will compile only the module B. (as mention in the profile)
<modules>
<module>../A</module>
<module>../B</module>
</modules>
But i want to keep the modules tag as it is and use profile to compile only the module B. Is there any solution to overcome this issue.
You have to create a separate profile for building both module A and B. You can have this profile active by default. So that will not change the existing behavior.
<groupId>my.group</groupId>
<artifactId>artifact</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<profiles>
<profile>
<id>P1</id>
<modules>
<module>../B</module>
</modules>
</profile>
<profile>
<id>Everything</id>
<modules>
<module>../A</module>
<module>../B</module>
</modules>
</profile>
<profiles>
Related
In my pom, I have two profiles.
test1
test2
Now I want my war name to change based on the activated profile.
Expected Result
When test1 profile is activated, war name should be prefix-test1.war.
When test1 and test2 are activated, war name should be prefix-test1-test2.war.
When no profile is activated, war name should be prefix.war.
My POM file ....
<?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>
<parent>
<groupId>com.sbill</groupId>
<artifactId>sbill-wrapper</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<packaging>war</packaging>
<artifactId>executable</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<profiles>
<profile>
<id>test1</id>
<properties>
<rp.build.warname>test1</rp.build.warname>
</properties>
</profile>
<profile>
<id>test2</id>
<properties>
<rp.build.warname>test2</rp.build.warname>
</properties>
</profile>
</profiles>
<build>
<finalName>prefix-${rp.build.warname}</finalName>
</build>
</project>
Right now if I run command mvn clean install the war name is prefix-null.war
. If I run command mvn clean install -P test1,test2 the war name is prefix-test2.war.
The result is different to what expected.
Firstly, to avoid showing null when no profiles, we can provide a default value for the property rp.build.warname, as mentioned in Setting default values for custom Maven 2 properties.
For the case running mvn clean install -P test1,test2, the war name is prefix-test2.war as the value of rp.build.warname is overridden, you may read How are conflicting properties resolved if multiple profiles are activated for more details.
In Order to have multiple values, we can use two properties(rp.build.warname1, rp.build.warname2) instead.
The following pom.xml includes the above changes
<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>com.sbill</groupId>
<artifactId>sbill-wrapper</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<packaging>war</packaging>
<artifactId>executable</artifactId>
<!-- Provide default value here to avoid null in file name -->
<properties>
<rp.build.warname1/>
<rp.build.warname2/>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<profiles>
<profile>
<id>test1</id>
<properties>
<rp.build.warname1>-test1</rp.build.warname1>
</properties>
</profile>
<profile>
<id>test2</id>
<properties>
<rp.build.warname2>-test2</rp.build.warname2>
</properties>
</profile>
</profiles>
<build>
<finalName>prefix${rp.build.warname1}${rp.build.warname2}</finalName>
</build>
</project>
I am trying to debug a maven cucumber-serenity Java project in Eclipse Photon 2018/12.
Please tell me how I can set up maven debug profile and run so that I can debug through the code by setting breakpoints.
It depends on your needs. If you want to debug tests, just use this profile:
<project
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<packaging>...</packaging>
<repositories>
...
</repositories>
<distributionManagement>
...
</distributionManagement>
<profiles>
<profile>
<id>debug</id>
<properties>
<maven.surefire.debug>test</maven.surefire.debug>
</properties>
</profile>
</profiles>
<build>
...
</build>
<dependencies>
...
</dependencies>
</project>
But if this is not the case, then you could simply configure your Eclipse IDE doing this.
Hope it helps.
I have a multi module project with below hierarchy :
parent-build project pom.xml
...
<groupId>com.my.project</groupId>
<artifactId>parent-build</artifactId>
<packaging>pom</packaging>
<name>parent-build</name>
<version>${version.product}</version>
<properties>
<version.product>1.0</version.product>
</properties>
...
build-all project pom.xml
...
<parent>
<artifactId>parent-build</artifactId>
<groupId>com.my.project</groupId>
<version>${version.product}</version>
<relativePath>../parent-build/pom.xml</relativePath>
</parent>
<groupId>com.my.project</groupId>
<packaging>pom</packaging>
<modules>
<module>../child-1</module>
<module>../child-2</module>
</modules>
...
child-2 project pom.xml
...
<parent>
<artifactId>parent-build</artifactId>
<groupId>com.my.project</groupId>
<version>${version.product}</version>
<relativePath>../parent-build/pom.xml</relativePath>
</parent>
<groupId>com.my.project</groupId>
<artifactId>child-2</artifactId>
<packaging>jar</packaging>
<version>${version.product}</version>
...
<dependencies>
<dependency>
<groupId>com.my.project</groupId>
<artifactId>child-1</artifactId>
<version>${version.product}</version>
</dependency>
...
</dependencies>
...
child-1 project pom.xml
...
<parent>
<artifactId>parent-build</artifactId>
<groupId>com.my.project</groupId>
<version>${version.product}</version>
<relativePath>../parent-build/pom.xml</relativePath>
</parent>
<groupId>com.my.project</groupId>
<artifactId>child-1</artifactId>
<packaging>jar</packaging>
<version>${version.product}</version>
...
I want to build all jars with same version and this version should be specified at single place.
I declared a property in parent-build pom.xml
Now when I do mvn clean install on build-all project , it builds all projects in specified order of modules.
That is fine.
But in some cases , I want to build child-2 project only.
i.e ,lets say I do some changes in child-2 project and want to build only this project.
The problem with this scenario is , it cannot find the property value version.product
Edit:
Below is the error I am getting when building child-2 project
Could not transfer artifact com.my.project:parent-build:pom:${version.product} from/to central (http://repo1.maven.org/maven2): Illegal character in path at index 66: http://repo1.maven.org/maven2/com/my/project/parent-build/${version.product}/parent-build-${version.product}.pom
Please help.
Thanks in advance.
Firstly I would urge against this, but I know you may have a module that is not working properly yet etc. In the past I have used profiles in the parent pom to control the modules list:
<profiles>
<profile>
<id>all</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>1</module>
<module>2</module>
<module>3</module>
<module>4</module>
</modules>
</profile>
<profile>
<id>profile1</id>
<modules>
<module>1</module>
<module>2</module>
<module>3</module>
</modules>
</profile>
</profiles>
then for :
1) mvn clean install - you will get all modules
2) mvn clean install -Pprofile1 you will only get modules 1,2 & 3.
flatten-maven-plugin
This is what I want.
This plugin will replace your version specified in property, with actual property value in all effective pom.xml.
So later if you build any child separately, it will build successfully.
Cheers
I have a spring boot application where I want to package it according to the profile I am building with, for example when I issue profile x, I want maven to build as a jar; but when building with profile y, I want maven to build as a war.
I want something like:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0.0</version>
<package>${buildMethod}</package>
</project>
Where ${buildMethod} is the type of packaging.
This would be decided by executing a command i.e. mvn package -P buildProfile.
Maybe this would help:
<profiles>
<profile>
<id>war</id>
<properties>
<deploy.type>war</deploy.type>
</properties>
</profile>
<profile>
<id>jar</id>
<properties>
<deploy.type>jar</deploy.type>
</properties>
</profile>
</profiles>
And then just use this property placeholder ${deploy.type}.
You can easily add profiles, with a list of properties, to your pom file.
Build using:
mvn package - Builds a WAR by default (implicit)
mvn package -P deployWar - Builds a WAR
mvn package -P deployJar - Builds a JAR
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0.0</version>
<package>${deployment.type}</package>
<profiles>
<!-- This profile deploys the application as a WAR (default) -->
<profile>
<id>deployWar</id>
<properties>
<deployment.type>war</deployment.type>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<!-- This profile deploys the application as a JAR -->
<profile>
<id>deployJar</id>
<properties>
<deployment.type>jar</deployment.type>
</properties>
</profile>
</profiles>
</project>
We have a Maven 2 project with lots of modules in it. Example:
<modules>
<module>common</module>
<module>foo</module>
<module>data</module>
<module>bar</module>
... more ...
</module>
Let's say the "data" module is time consuming to build and we want to exclude it when the project is build by a CI server. Currently we use two pom.xml files to achieve this. One has all modules in it and the other one has all modules except the ones which can be left out for CI. But that's pretty annoying because sometimes we forget to put a new module into both files.
Is there a solution which doesn't need two separate module lists?
With Maven 3.2.1, you can now use -pl !<module_name>,!<module_name> to exclude certain modules from the reactor build.
See this feature request: https://issues.apache.org/jira/browse/MNG-5230
The easiest might be to use profiles like this:
<project>
...
<modules>
<module>common</module>
<module>foo</module>
<module>bar</module>
<modules>
...
<profiles>
<profile>
<id>expensive-modules-to-build</id>
<modules>
<module>data</module>
</modules>
</profile>
</profiles>
</project>
You should then check out ways you can activate profiles
The projects to build can also be specified on the mvn command line. This would remove the need for a separate pom, but instead you would have to change the CI configuration everytime there is a new module.
-pl,--projects <arg> Comma-delimited list of specified
reactor projects to build instead
of all projects. A project can be
specified by [groupId]:artifactId
or by its relative path.
Maybe a combination of this flag and --also-make-dependents or --also-make would reduce this maintenance burden again.
-am,--also-make If project list is specified, also
build projects required by the
list
-amd,--also-make-dependents If project list is specified, also
build projects that depend on
projects on the list
I assume you want the default build to always build everything, regardless of speed, so that new developers can get started quickly without having to understand lots about the POM. You can use profiles like this:
<modules>
<module>common</module>
<module>foo</module>
<module>bar</module>
</modules>
...
<profiles>
<profile>
<id>expensive-modules-to-build</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>data</module>
</modules>
</profile>
</profiles>
</project>
The problem with this is that if a developer specifies another profile on the command line, then the expensive-modules-to-build isn't included (unless the developer also specifies it). This makes it complicated to remember which profiles need to be included.
Here is a hacky way around that. Both profiles are always included, because the pom.xml file always exists. So to exclude the expensive modules, you can use -P!full-build on the command line.
<profiles>
<profile>
<id>full-build</id>
<activation>
<file>
<exists>pom.xml</exists>
</file>
</activation>
<modules>
<module>data</module>
</modules>
</profile>
<profile>
<id>short-build</id>
<activation>
<file>
<exists>pom.xml</exists>
</file>
</activation>
<modules>
<module>common</module>
<module>foo</module>
<module>bar</module>
</modules>
</profile>
</profiles>
Another idea: Reactor modules can be nested, so it should be possible to group your fast and slow-building modules into separate poms and then add another aggregator pom containing these two as modules. Your CI Server could then only reference the pom containing the fast building modules.
<artifactId>fast</artifactId>
<modules>
<module>fast-a</module>
<module>fast-b</module>
<module>fast-c</module>
</module>
<artifactId>all</artifactId>
<modules>
<module>fast</module>
<module>slow</module>
</module>
You could be to use maven profiles. In our build environment, we created a profile quick that disables many plugins and test execution.
This is done by
<profile>
<id>quick</id>
<properties>
<skipTests>true</skipTests>
<!-- others... -->
</properties>
<build>
<plugins>
<!-- configuration... -->
</plugins>
</build>
</profile>
And then we invoke maven the following way
mvn groupId:artifactId:goal -P quick
You could maybe disable compilation and other standard plugins in the pom of your module to speed it up.
Not exactly the answer these folks were asking for. My situation was I wanted to deploy only the parent pom. I'm using the spring-boot-thin-layout in a child module. This requires the parent module be deployed into artifactory. I added the following into my project. It enables skipping of install and/or deploy phase.
In my parent pom:
<properties>
<disable.install>true</disable.install>
<disable.deploy>true</disable.deploy>
<enable.deployAtEnd>true</enable.deployAtEnd>
</properties>
<profiles>
<profile>
<id>deploy-parent</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<disable.install>true</disable.install>
<disable.deploy>true</disable.deploy>
<deployAtEnd>${enable.deployAtEnd}</deployAtEnd>
</properties>
<build>
<finalName>${project.version}</finalName>
</build>
</profile>
</profiles>
And the in my child pom(s) or any module you don't want deployed with parent:
<properties>
<maven.install.skip>${disable.install}</maven.install.skip>
<maven.deploy.skip>${disable.deploy}</maven.deploy.skip>
<deployAtEnd>${enable.deployAtEnd}</deployAtEnd>
</properties>
So effectively when I run mvn deploy on the parent pom, it will compile all the modules, not run install on anything, and then at the end deploy any module not having <maven.deploy.skip>${disable.deploy}</maven.deploy.skip> in it's properties. So in my case only deploying the parent.